MCPcopy Create free account
hub / github.com/NVIDIA/DALI / test_coco_empty_annotations_pix

Function test_coco_empty_annotations_pix

dali/test/python/reader/test_coco.py:331–367  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

329
330
331def test_coco_empty_annotations_pix():
332 file_root = os.path.join(test_data_root, "db", "coco_dummy", "images")
333 train_annotations = os.path.join(test_data_root, "db", "coco_dummy", "instances.json")
334
335 @pipeline_def(batch_size=1, device_id=0, num_threads=4)
336 def coco_pipe():
337 _, _, _, masks, ids = fn.readers.coco(
338 file_root=file_root,
339 annotations_file=train_annotations,
340 image_ids=True,
341 pixelwise_masks=True,
342 )
343 return masks, ids
344
345 pipe = coco_pipe()
346 number_of_samples = pipe.epoch_size()
347 for k in number_of_samples:
348 # there is only one reader
349 number_of_samples = number_of_samples[k]
350 break
351
352 annotations = None
353 with open(train_annotations) as file:
354 annotations = json.load(file)
355
356 anno_mapping = {}
357 for elm in annotations["annotations"]:
358 image_id = elm["image_id"]
359 anno_mapping[image_id] = anno_mapping.get(image_id, False) or "segmentation" in elm
360
361 for _ in range(number_of_samples):
362 mask, image_ids = pipe.run()
363 image_ids = int(image_ids.as_array().item())
364 max_mask = np.max(np.array(mask.as_tensor()))
365 assert (max_mask != 0 and image_ids in anno_mapping and anno_mapping[image_ids]) or (
366 max_mask == 0 and not (image_ids in anno_mapping and anno_mapping[image_ids])
367 )
368
369
370def test_coco_empty_annotations_poly():

Callers

nothing calls this directly

Calls 7

coco_pipeFunction · 0.85
itemMethod · 0.80
epoch_sizeMethod · 0.45
loadMethod · 0.45
getMethod · 0.45
runMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected