pierreguillou commited on
Commit
521f829
1 Parent(s): d3d2ec3

Update DocLayNet-base.py

Browse files
Files changed (1) hide show
  1. DocLayNet-base.py +10 -10
DocLayNet-base.py CHANGED
@@ -25,7 +25,7 @@ DocLayNet dataset:
25
 
26
  import json
27
  import os
28
- import base64
29
  from PIL import Image
30
  import datasets
31
 
@@ -121,7 +121,7 @@ class DocLayNet(datasets.GeneratorBasedBuilder):
121
  )
122
  ),
123
  "image": datasets.features.Image(),
124
- "pdf": datasets.Value("string"),
125
  "page_hash": datasets.Value("string"), # unique identifier, equal to filename
126
  "original_filename": datasets.Value("string"), # original document filename
127
  "page_no": datasets.Value("int32"), # page number in original document
@@ -193,7 +193,7 @@ class DocLayNet(datasets.GeneratorBasedBuilder):
193
  logger.info("⏳ Generating examples from = %s", filepath)
194
  ann_dir = os.path.join(filepath, "annotations")
195
  img_dir = os.path.join(filepath, "images")
196
- pdf_dir = os.path.join(filepath, "pdfs")
197
 
198
  for guid, file in enumerate(sorted(os.listdir(ann_dir))):
199
  texts = []
@@ -211,12 +211,12 @@ class DocLayNet(datasets.GeneratorBasedBuilder):
211
  image_path = image_path.replace("json", "png")
212
  image, size = load_image(image_path)
213
 
214
- # get pdf
215
- pdf_path = os.path.join(pdf_dir, file)
216
- pdf_path = pdf_path.replace("json", "pdf")
217
- with open(pdf_path, "rb") as pdf_file:
218
- pdf_bytes = pdf_file.read()
219
- pdf_encoded_string = base64.b64encode(pdf_bytes)
220
 
221
  for item in data["form"]:
222
  text_example, category_example, bbox_block_example, bbox_line_example = item["text"], item["category"], item["box"], item["box_line"]
@@ -237,4 +237,4 @@ class DocLayNet(datasets.GeneratorBasedBuilder):
237
  collection = data["metadata"]["collection"]
238
  doc_category = data["metadata"]["doc_category"]
239
 
240
- 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}
25
 
26
  import json
27
  import os
28
+ # import base64
29
  from PIL import Image
30
  import datasets
31
 
121
  )
122
  ),
123
  "image": datasets.features.Image(),
124
+ # "pdf": datasets.Value("string"),
125
  "page_hash": datasets.Value("string"), # unique identifier, equal to filename
126
  "original_filename": datasets.Value("string"), # original document filename
127
  "page_no": datasets.Value("int32"), # page number in original document
193
  logger.info("⏳ Generating examples from = %s", filepath)
194
  ann_dir = os.path.join(filepath, "annotations")
195
  img_dir = os.path.join(filepath, "images")
196
+ # pdf_dir = os.path.join(filepath, "pdfs")
197
 
198
  for guid, file in enumerate(sorted(os.listdir(ann_dir))):
199
  texts = []
211
  image_path = image_path.replace("json", "png")
212
  image, size = load_image(image_path)
213
 
214
+ # # get pdf
215
+ # pdf_path = os.path.join(pdf_dir, file)
216
+ # pdf_path = pdf_path.replace("json", "pdf")
217
+ # with open(pdf_path, "rb") as pdf_file:
218
+ # pdf_bytes = pdf_file.read()
219
+ # pdf_encoded_string = base64.b64encode(pdf_bytes)
220
 
221
  for item in data["form"]:
222
  text_example, category_example, bbox_block_example, bbox_line_example = item["text"], item["category"], item["box"], item["box_line"]
237
  collection = data["metadata"]["collection"]
238
  doc_category = data["metadata"]["doc_category"]
239
 
240
+ yield guid, {"id": str(guid), "texts": texts, "bboxes_block": bboxes_block, "bboxes_line": bboxes_line, "categories": categories, "image": image, "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}