@@ -93,12 +93,6 @@ def __init__(self, config_path, image_info=None):
93
93
(osp .splitext (osp .basename (p .strip ()))[0 ], p .strip ())
94
94
for p in f
95
95
)
96
-
97
- for item_id , image_path in subset .items .items ():
98
- image_path = self ._make_local_path (image_path )
99
- if not osp .isfile (image_path ) and item_id not in image_info :
100
- raise Exception ("Can't find image '%s'" % item_id )
101
-
102
96
subsets [subset_name ] = subset
103
97
104
98
self ._subsets = subsets
@@ -122,10 +116,9 @@ def _get(self, item_id, subset_name):
122
116
image_path = self ._make_local_path (item )
123
117
image_size = self ._image_info .get (item_id )
124
118
image = Image (path = image_path , size = image_size )
125
- h , w = image .size
126
119
127
120
anno_path = osp .splitext (image_path )[0 ] + '.txt'
128
- annotations = self ._parse_annotations (anno_path , w , h )
121
+ annotations = self ._parse_annotations (anno_path , image )
129
122
130
123
item = DatasetItem (id = item_id , subset = subset_name ,
131
124
image = image , annotations = annotations )
@@ -134,21 +127,30 @@ def _get(self, item_id, subset_name):
134
127
return item
135
128
136
129
@staticmethod
137
- def _parse_annotations (anno_path , image_width , image_height ):
130
+ def _parse_annotations (anno_path , image ):
131
+ lines = []
138
132
with open (anno_path , 'r' ) as f :
139
- annotations = []
140
133
for line in f :
141
- label_id , xc , yc , w , h = line .strip ().split ()
142
- label_id = int (label_id )
143
- w = float (w )
144
- h = float (h )
145
- x = float (xc ) - w * 0.5
146
- y = float (yc ) - h * 0.5
147
- annotations .append (Bbox (
148
- round (x * image_width , 1 ), round (y * image_height , 1 ),
149
- round (w * image_width , 1 ), round (h * image_height , 1 ),
150
- label = label_id
151
- ))
134
+ line = line .strip ()
135
+ if line :
136
+ lines .append (line )
137
+
138
+ annotations = []
139
+ if lines :
140
+ image_height , image_width = image .size # use image info late
141
+ for line in lines :
142
+ label_id , xc , yc , w , h = line .split ()
143
+ label_id = int (label_id )
144
+ w = float (w )
145
+ h = float (h )
146
+ x = float (xc ) - w * 0.5
147
+ y = float (yc ) - h * 0.5
148
+ annotations .append (Bbox (
149
+ round (x * image_width , 1 ), round (y * image_height , 1 ),
150
+ round (w * image_width , 1 ), round (h * image_height , 1 ),
151
+ label = label_id
152
+ ))
153
+
152
154
return annotations
153
155
154
156
@staticmethod
0 commit comments