OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.48k stars 2.18k forks source link

Error when training custom detection: bounding box values should be in the range 0 - 1 #815

Closed toolhater closed 1 year ago

toolhater commented 1 year ago

I'm trying to use the something similar to the example that was given for training a model for custom image detection. I annotate the files in Label Studio and export in yolo format. If I just have one class I dont have a problem. However when I add more than one class, even after update the object_names_array, I get the error in the subject line.

Before we get too far into the weeds I should mention that some of the images I have have more than one class inside them. So if I open the annotation for an image I might see something like this:

1 0.5884861407249463 0.6983273596176822 0.823027718550106 0.4074074074074073 0 0.5127931769722814 0.5173237753882914 0.9744136460554371 0.9653524492234169

The first number is the I think represents a mapping to the classes. Indeed, there is a notes.json file that has this info:

{ "categories": [ { "id": 0, "name": "dogs" }, { "id": 1, "name": "cats" }, { "id": 2, "name": "birds" } ], "info": { "year": 2023, "version": "1.0", "contributor": "Label Studio" } }

Should I be trying to export this in another format or does imageAI only expect one class per annotation file? Also ran a loop and read all the annotations and didn't find one value in the box, not the class, that had a value less than 0 or greater than 1.

Any help would be appreciated.

toolhater commented 1 year ago

I've found the error. After taking out some of the code and running it against the list of items I was trying to load, I found two items that had values =1. In those cases, when I looked at the labeling, the line was exactly on the end of the image, Once I closed the rectangle a tad the problem was fixed.

Looping through the folder where my annotations were I used this code:

l = np.loadtxt(f'{directory}{file_name}').reshape(-1, 5)

#     try:
#         assert (l[:, 1:] <= 1).all(), f"bounding box values should be in the range 0 - 1 {file_name}"
#     except AssertionError as ex:
#         print(file_name)
#         print(l)