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

Function test_coco_empty_annotations_poly

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

Source from the content-addressed store, hash-verified

368
369
370def test_coco_empty_annotations_poly():
371 file_root = os.path.join(test_data_root, "db", "coco_dummy", "images")
372 train_annotations = os.path.join(test_data_root, "db", "coco_dummy", "instances.json")
373
374 @pipeline_def(batch_size=1, device_id=0, num_threads=4)
375 def coco_pipe():
376 _, _, _, poly, vert, ids = fn.readers.coco(
377 file_root=file_root,
378 annotations_file=train_annotations,
379 image_ids=True,
380 polygon_masks=True,
381 )
382 return poly, vert, ids
383
384 pipe = coco_pipe()
385 number_of_samples = pipe.epoch_size()
386 for k in number_of_samples:
387 # there is only one reader
388 number_of_samples = number_of_samples[k]
389 break
390
391 annotations = None
392 with open(train_annotations) as file:
393 annotations = json.load(file)
394
395 anno_mapping = {}
396 for elm in annotations["annotations"]:
397 image_id = elm["image_id"]
398 anno_mapping[image_id] = anno_mapping.get(image_id, False) or "segmentation" in elm
399
400 for _ in range(number_of_samples):
401 poly, vert, image_ids = pipe.run()
402 image_ids = int(image_ids.as_array().item())
403 poly = np.array(poly.as_tensor()).size
404 vert = np.array(vert.as_tensor()).size
405 assert (poly != 0 and image_ids in anno_mapping and anno_mapping[image_ids]) or (
406 vert == 0 and not (image_ids in anno_mapping and anno_mapping[image_ids])
407 )
408
409
410def test_coco_pix_mask_ratio():

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected