@@ -22,7 +22,7 @@ class COCOTEXT(AbstractDataset):
22
22
COCO-Text dataset from `"COCO-Text: Dataset and Benchmark for Text Detection and Recognition in Natural Images"
23
23
<https://arxiv.org/pdf/1601.07140v2>`_ |
24
24
`"homepage" <https://bgshih.github.io/cocotext/>`_.
25
-
25
+
26
26
>>> # NOTE: You need to download the dataset first.
27
27
>>> from doctr.datasets import COCOTEXT
28
28
>>> train_set = COCOTEXT(train=True, img_folder="/path/to/coco_text/train2014/",
@@ -31,7 +31,7 @@ class COCOTEXT(AbstractDataset):
31
31
>>> test_set = COCOTEXT(train=False, img_folder="/path/to/coco_text/train2014/",
32
32
>>> label_path = "/path/to/coco_text/cocotext.v2.json")
33
33
>>> img, target = test_set[0]
34
-
34
+
35
35
Args:
36
36
img_folder: folder with all the images of the dataset
37
37
label_path: path to the annotations file of the dataset
@@ -55,7 +55,7 @@ def __init__(
55
55
super ().__init__ (
56
56
img_folder , pre_transforms = convert_target_to_relative if not recognition_task else None , ** kwargs
57
57
)
58
- # Task check
58
+ # Task check
59
59
if recognition_task and detection_task :
60
60
raise ValueError (
61
61
" 'recognition' and 'detection task' cannot be set to True simultaneously. "
@@ -73,14 +73,16 @@ def __init__(
73
73
74
74
with open (label_path , "r" ) as file :
75
75
data = json .load (file )
76
-
76
+
77
77
# Filter images based on the set
78
78
img_items = [img for img in data ["imgs" ].items () if (img [1 ]["set" ] == "train" ) == train ]
79
+ box : list [float ] | np .ndarray
79
80
80
81
for img_id , img_info in tqdm (img_items , desc = "Preparing and Loading COCOTEXT" , total = len (img_items )):
81
82
img_path = os .path .join (img_folder , img_info ["file_name" ])
82
83
83
- if not os .path .exists (img_path ):
84
+ # File existence check
85
+ if not os .path .exists (img_path ): # pragma: no cover
84
86
raise FileNotFoundError (f"Unable to locate { img_path } " )
85
87
86
88
# Get annotations for the current image (only legible text)
@@ -90,11 +92,12 @@ def __init__(
90
92
if ann ["image_id" ] == int (img_id ) and ann ["legibility" ] == "legible"
91
93
]
92
94
93
- if not annotations : # Some images have no annotations with readable text
95
+ # Some images have no annotations with readable text
96
+ if not annotations : # pragma: no cover
94
97
continue
95
98
96
99
_targets = []
97
-
100
+
98
101
for annotation in annotations :
99
102
x , y , w , h = annotation ["bbox" ]
100
103
if use_polygons :
@@ -133,4 +136,4 @@ def __init__(
133
136
self .root = tmp_root
134
137
135
138
def extra_repr (self ) -> str :
136
- return f"train={ self .train } "
139
+ return f"train={ self .train } "
0 commit comments