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

Update DocLayNet-small.py

Browse files
Files changed (1) hide show
  1. DocLayNet-small.py +13 -14
DocLayNet-small.py CHANGED
@@ -129,7 +129,6 @@ class DocLayNet(datasets.GeneratorSmalldBuilder):
129
  "coco_height": datasets.Value("int32"), # with in pixels in PNG and COCO format
130
  "collection": datasets.Value("string"), # sub-collection name
131
  "doc_category": datasets.Value("string"), # category type of the document
132
-
133
  }
134
  )
135
 
@@ -196,7 +195,7 @@ class DocLayNet(datasets.GeneratorSmalldBuilder):
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:
@@ -213,18 +212,6 @@ class DocLayNet(datasets.GeneratorSmalldBuilder):
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"]
@@ -233,4 +220,16 @@ class DocLayNet(datasets.GeneratorSmalldBuilder):
233
  bboxes_block.append(bbox_block_example)
234
  bboxes_line.append(bbox_line_example)
235
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  yield guid, {"id": str(guid), "texts": texts, "bboxes_block": bboxes_block, "bboxes_line": bboxes_line, "categories": categories, "image": image, "pdf": pdf_encoded_string, "page_hash": page_hash, "original_filename": original_filename, "page_no": page_no, "num_pages": num_pages, "original_width": original_width, "original_height": original_height, "coco_width": coco_width, "coco_height": coco_height, "collection": collection, "doc_category": doc_category}
 
129
  "coco_height": datasets.Value("int32"), # with in pixels in PNG and COCO format
130
  "collection": datasets.Value("string"), # sub-collection name
131
  "doc_category": datasets.Value("string"), # category type of the document
 
132
  }
133
  )
134
 
 
195
  bboxes_block = []
196
  bboxes_line = []
197
  categories = []
198
+
199
  # get json
200
  file_path = os.path.join(ann_dir, file)
201
  with open(file_path, "r", encoding="utf8") as f:
 
212
  with open(pdf_path, "rb") as pdf_file:
213
  pdf_bytes = pdf_file.read()
214
  pdf_encoded_string = base64.b64encode(pdf_bytes)
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  for item in data["form"]:
217
  text_example, category_example, bbox_block_example, bbox_line_example = item["text"], item["category"], item["box"], item["box_line"]
 
220
  bboxes_block.append(bbox_block_example)
221
  bboxes_line.append(bbox_line_example)
222
 
223
+ # get all metadadata
224
+ page_hash = data["metadata"]["page_hash"]
225
+ original_filename = data["metadata"]["original_filename"]
226
+ page_no = data["metadata"]["page_no"]
227
+ num_pages = data["metadata"]["num_pages"]
228
+ original_width = data["metadata"]["original_width"]
229
+ original_height = data["metadata"]["original_height"]
230
+ coco_width = data["metadata"]["coco_width"]
231
+ coco_height = data["metadata"]["coco_height"]
232
+ collection = data["metadata"]["collection"]
233
+ doc_category = data["metadata"]["doc_category"]
234
+
235
  yield guid, {"id": str(guid), "texts": texts, "bboxes_block": bboxes_block, "bboxes_line": bboxes_line, "categories": categories, "image": image, "pdf": pdf_encoded_string, "page_hash": page_hash, "original_filename": original_filename, "page_no": page_no, "num_pages": num_pages, "original_width": original_width, "original_height": original_height, "coco_width": coco_width, "coco_height": coco_height, "collection": collection, "doc_category": doc_category}