@@ -166,12 +166,26 @@ def add_single_ground_truth_image_info(self, image_id, groundtruth_dict):
166
166
groundtruth_classes = groundtruth_dict [
167
167
standard_fields .InputDataFields .groundtruth_classes ]
168
168
groundtruth_classes -= self ._label_id_offset
169
+ # If the key is not present in the groundtruth_dict or the array is empty
170
+ # (unless there are no annotations for the groundtruth on this image)
171
+ # use values from the dictionary or insert None otherwise.
172
+ if (standard_fields .InputDataFields .groundtruth_difficult in
173
+ groundtruth_dict .keys () and
174
+ (groundtruth_dict [standard_fields .InputDataFields .groundtruth_difficult ]
175
+ .size or not groundtruth_classes .size )):
176
+ groundtruth_difficult = groundtruth_dict [
177
+ standard_fields .InputDataFields .groundtruth_difficult ]
178
+ else :
179
+ groundtruth_difficult = None
180
+ if not len (self ._image_ids ) % 1000 :
181
+ logging .warn (
182
+ 'image %s does not have groundtruth difficult flag specified' ,
183
+ image_id )
169
184
self ._evaluation .add_single_ground_truth_image_info (
170
185
image_id ,
171
186
groundtruth_dict [standard_fields .InputDataFields .groundtruth_boxes ],
172
187
groundtruth_classes ,
173
- groundtruth_dict .get (
174
- standard_fields .InputDataFields .groundtruth_difficult , None ))
188
+ groundtruth_is_difficult_list = groundtruth_difficult )
175
189
self ._image_ids .update ([image_id ])
176
190
177
191
def add_single_detected_image_info (self , image_id , detections_dict ):
@@ -337,14 +351,27 @@ def add_single_ground_truth_image_info(self, image_id, groundtruth_dict):
337
351
groundtruth_classes = groundtruth_dict [
338
352
standard_fields .InputDataFields .groundtruth_classes ]
339
353
groundtruth_classes -= self ._label_id_offset
340
-
354
+ # If the key is not present in the groundtruth_dict or the array is empty
355
+ # (unless there are no annotations for the groundtruth on this image)
356
+ # use values from the dictionary or insert None otherwise.
357
+ if (standard_fields .InputDataFields .groundtruth_group_of in
358
+ groundtruth_dict .keys () and
359
+ (groundtruth_dict [standard_fields .InputDataFields .groundtruth_group_of ]
360
+ .size or not groundtruth_classes .size )):
361
+ groundtruth_group_of = groundtruth_dict [
362
+ standard_fields .InputDataFields .groundtruth_group_of ]
363
+ else :
364
+ groundtruth_group_of = None
365
+ if not len (self ._image_ids ) % 1000 :
366
+ logging .warn (
367
+ 'image %s does not have groundtruth group_of flag specified' ,
368
+ image_id )
341
369
self ._evaluation .add_single_ground_truth_image_info (
342
370
image_id ,
343
371
groundtruth_dict [standard_fields .InputDataFields .groundtruth_boxes ],
344
372
groundtruth_classes ,
345
373
groundtruth_is_difficult_list = None ,
346
- groundtruth_is_group_of_list = groundtruth_dict .get (
347
- standard_fields .InputDataFields .groundtruth_group_of , None ))
374
+ groundtruth_is_group_of_list = groundtruth_group_of )
348
375
self ._image_ids .update ([image_id ])
349
376
350
377
0 commit comments