ultralytics / JSON2YOLO

Convert JSON annotations into YOLO format.

Home Page:https://docs.ultralytics.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError: 'iscrowd'

Mary14-design opened this issue · comments

I am trying to convert instances_train2017.json from https://cocodataset.org/#home and it returns the following error

Traceback (most recent call last): File "/tmp/workspace/codes/JSON2YOLO/general_json2yolo.py", line 393, in <module> convert_coco_json( File "/tmp/workspace/codes/JSON2YOLO/general_json2yolo.py", line 286, in convert_coco_json box = np.array(ann["bbox"], dtype=np.float64) KeyError: 'bbox'

Any idea on how to solve this error?

@Mary14-design hello! 😊 It seems like there's an issue with accessing the bbox attribute in your annotations. This could happen if the JSON structure doesn't match what the script expects.

First, double-check the JSON file to ensure that it follows the COCO format, where each annotation should include a bbox field. The error might also occur if certain annotations are missing this field due to variability in the dataset.

If the structure is correct and the issue persists, you might want to add a check before accessing the bbox field to skip annotations without it:

if 'bbox' in ann:
    box = np.array(ann['bbox'], dtype=np.float64)
    # Proceed with your processing
else:
    print("Skipping annotation without bbox.")

This way, you can avoid the KeyError and handle annotations missing the bbox more gracefully.

For more detailed guidance on working with datasets and annotations, you might find the Ultralytics Docs helpful: https://docs.ultralytics.com

Let us know if you need further assistance!