pierreguillou commited on
Commit
49993d7
1 Parent(s): b89e0d2

Update DocLayNet-small.py

Browse files
Files changed (1) hide show
  1. DocLayNet-small.py +16 -13
DocLayNet-small.py CHANGED
@@ -190,38 +190,41 @@ class DocLayNet(datasets.GeneratorSmalldBuilder):
190
  ann_dir = os.path.join(filepath, "annotations")
191
  img_dir = os.path.join(filepath, "images")
192
  pdf_dir = os.path.join(filepath, "pdfs")
 
193
  for guid, file in enumerate(sorted(os.listdir(ann_dir))):
194
  texts = []
195
  bboxes_block = []
196
  bboxes_line = []
197
  categories = []
 
198
  # get json
199
  file_path = os.path.join(ann_dir, file)
200
  with open(file_path, "r", encoding="utf8") as f:
201
  data = json.load(f)
 
202
  # get image
203
  image_path = os.path.join(img_dir, file)
204
  image_path = image_path.replace("json", "png")
205
  image, size = load_image(image_path)
 
206
  # get pdf
207
  pdf_path = os.path.join(pdf_dir, file)
208
  pdf_path = pdf_path.replace("json", "pdf")
209
  with open(pdf_path, "rb") as pdf_file:
210
  pdf_bytes = pdf_file.read()
211
  pdf_encoded_string = base64.b64encode(pdf_bytes)
212
- # get all data
213
-
214
- for item in data["metadata"]:
215
- page_hash = item["page_hash"]
216
- original_filename = item["original_filename"]
217
- page_no = item["page_no"]
218
- num_pages = item["num_pages"]
219
- original_width = item["original_width"]
220
- original_height = item["original_height"]
221
- coco_width = item["coco_width"]
222
- coco_height = item["coco_height"]
223
- collection = item["collection"]
224
- doc_category = item["doc_category"]
225
 
226
  for item in data["form"]:
227
  text_example, category_example, bbox_block_example, bbox_line_example = item["text"], item["category"], item["box"], item["box_line"]
 
190
  ann_dir = os.path.join(filepath, "annotations")
191
  img_dir = os.path.join(filepath, "images")
192
  pdf_dir = os.path.join(filepath, "pdfs")
193
+
194
  for guid, file in enumerate(sorted(os.listdir(ann_dir))):
195
  texts = []
196
  bboxes_block = []
197
  bboxes_line = []
198
  categories = []
199
+
200
  # get json
201
  file_path = os.path.join(ann_dir, file)
202
  with open(file_path, "r", encoding="utf8") as f:
203
  data = json.load(f)
204
+
205
  # get image
206
  image_path = os.path.join(img_dir, file)
207
  image_path = image_path.replace("json", "png")
208
  image, size = load_image(image_path)
209
+
210
  # get pdf
211
  pdf_path = os.path.join(pdf_dir, file)
212
  pdf_path = pdf_path.replace("json", "pdf")
213
  with open(pdf_path, "rb") as pdf_file:
214
  pdf_bytes = pdf_file.read()
215
  pdf_encoded_string = base64.b64encode(pdf_bytes)
216
+
217
+ # get all metadadata
218
+ page_hash = data["metadata"]["page_hash"]
219
+ original_filename = data["metadata"]["original_filename"]
220
+ page_no = data["metadata"]["page_no"]
221
+ num_pages = data["metadata"]["num_pages"]
222
+ original_width = data["metadata"]["original_width"]
223
+ original_height = data["metadata"]["original_height"]
224
+ coco_width = data["metadata"]["coco_width"]
225
+ coco_height = data["metadata"]["coco_height"]
226
+ collection = data["metadata"]["collection"]
227
+ doc_category = data["metadata"]["doc_category"]
 
228
 
229
  for item in data["form"]:
230
  text_example, category_example, bbox_block_example, bbox_line_example = item["text"], item["category"], item["box"], item["box_line"]