Datasets:
Tasks:
Image Classification
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
100K<n<1M
ArXiv:
License:
Update rvl_cdip_easyocr.py
Browse files- rvl_cdip_easyocr.py +14 -10
rvl_cdip_easyocr.py
CHANGED
@@ -19,7 +19,7 @@ import os
|
|
19 |
import numpy as np
|
20 |
from tqdm import tqdm
|
21 |
import datasets
|
22 |
-
|
23 |
|
24 |
_CITATION = """\
|
25 |
@inproceedings{harley2015icdar,
|
@@ -178,7 +178,7 @@ class RvlCdipEasyOcr(datasets.GeneratorBasedBuilder):
|
|
178 |
)
|
179 |
for ex in tqdm(data, desc="Loading OCR data"):
|
180 |
w, h = ex["images"][0]["image_width"], ex["images"][0]["image_height"]
|
181 |
-
filename = ex["images"][0]["file_name"]
|
182 |
words = ex["word-level annotations"][0]["ocred_text"]
|
183 |
box_info = ex["word-level annotations"][0]["ocred_boxes"]
|
184 |
boxes = [parse_easyOCR_box(box) for box in box_info]
|
@@ -190,6 +190,9 @@ class RvlCdipEasyOcr(datasets.GeneratorBasedBuilder):
|
|
190 |
def _path_to_OCR(image_to_OCR, file_path):
|
191 |
# obtain text and boxes given file_path
|
192 |
words, boxes = None, None
|
|
|
|
|
|
|
193 |
if file_path in image_to_OCR:
|
194 |
words, boxes = image_to_OCR[file_path]
|
195 |
return words, boxes
|
@@ -209,11 +212,12 @@ class RvlCdipEasyOcr(datasets.GeneratorBasedBuilder):
|
|
209 |
class_id = image_to_class_id[file_path]
|
210 |
label = _CLASSES[class_id]
|
211 |
words, boxes = self._path_to_OCR(image_to_OCR, file_path)
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
19 |
import numpy as np
|
20 |
from tqdm import tqdm
|
21 |
import datasets
|
22 |
+
from pathlib import Path
|
23 |
|
24 |
_CITATION = """\
|
25 |
@inproceedings{harley2015icdar,
|
|
|
178 |
)
|
179 |
for ex in tqdm(data, desc="Loading OCR data"):
|
180 |
w, h = ex["images"][0]["image_width"], ex["images"][0]["image_height"]
|
181 |
+
filename = Path(ex["images"][0]["file_name"]).stem
|
182 |
words = ex["word-level annotations"][0]["ocred_text"]
|
183 |
box_info = ex["word-level annotations"][0]["ocred_boxes"]
|
184 |
boxes = [parse_easyOCR_box(box) for box in box_info]
|
|
|
190 |
def _path_to_OCR(image_to_OCR, file_path):
|
191 |
# obtain text and boxes given file_path
|
192 |
words, boxes = None, None
|
193 |
+
#imagesv/v/u/b/vub13c00/523466896+-6898.tif
|
194 |
+
#523466896+-6898.jpg
|
195 |
+
file_path = Path(file_path).stem
|
196 |
if file_path in image_to_OCR:
|
197 |
words, boxes = image_to_OCR[file_path]
|
198 |
return words, boxes
|
|
|
212 |
class_id = image_to_class_id[file_path]
|
213 |
label = _CLASSES[class_id]
|
214 |
words, boxes = self._path_to_OCR(image_to_OCR, file_path)
|
215 |
+
if words is not None: #skipping all items for which we do not have OCR
|
216 |
+
a = dict(
|
217 |
+
id=file_path,
|
218 |
+
image={"path": file_path, "bytes": file_obj.read()},
|
219 |
+
label=label,
|
220 |
+
words=words,
|
221 |
+
boxes=boxes,
|
222 |
+
)
|
223 |
+
yield file_path, a
|