allow convert_to_coco_dict for custom dataset without annotations
Summary:
Fix . Allowing inference when annotations are not available for custom datasets.
Pull Request resolved:
@@ -318,7 +318,7 @@ def convert_to_coco_dict(dataset_name):
}
coco_images.append(coco_image)
- anns_per_image = image_dict["annotations"]
+ anns_per_image = image_dict.get("annotations", [])
for annotation in anns_per_image:
# create a new dict with only COCO fields
coco_annotation = {}
@@ -392,13 +392,9 @@ def convert_to_coco_dict(dataset_name):
"date_created": str(datetime.datetime.now()),
"description": "Automatically generated COCO json file for Detectron2.",
}
- coco_dict = {
- "info": info,
- "images": coco_images,
- "annotations": coco_annotations,
- "categories": categories,
- "licenses": None,
- }
+ coco_dict = {"info": info, "images": coco_images, "categories": categories, "licenses": None}
+ if len(coco_annotations) > 0:
+ coco_dict["annotations"] = coco_annotations
return coco_dict
