Key Error when loading data in Model Maker

Can anyone help me make sense of the following error:

/usr/local/lib/python3.8/dist-packages/tensorflow_examples/lite/model_maker/third_party/efficientdet/dataset/create_pascal_tfrecord.py in dict_to_tf_example(data, images_dir, label_map_dict, unique_id, ignore_difficult_instances, ann_json_dict)
    175       area.append((xmax[-1] - xmin[-1]) * (ymax[-1] - ymin[-1]))
    176       classes_text.append(obj['name'].encode('utf8'))
--> 177       classes.append(label_map_dict[obj['name']])
    178       if obj['truncated'] == 'Unspecified':
    179         truncated.append(0)

KeyError: '-'

In the past when this error has occurred it is to do with my mapping of classes in the dataloader. I’ve inspected my data pretty hard and haven’t been able to find any inconsitancies.

Does this mean there is a stray ‘-’ floating around in the ‘name’ field of one of my xml files?

I’m loading data with Pascal VOC.

Any thoughts tips things I can look for? Dataset is around 70k so hunting through it is quite difficult.

Answering my own question here but will leave it for anyone who comes across these types of errors.

I used Sublime Text and searched across all files and then inspected results and found this in a few of my xml files:

<name>-</name>

This is no good and doesn’t map to my classes, also probably needs to be found and figured out as well to see what it was supposed to be classed as.

Good luck for the next people coming along and having a similar error.

1 Like