AGOberprieler / GinJinn2

https://ginjinn2.readthedocs.io
Apache License 2.0
15 stars 2 forks source link

ginjinn predict IndexError: list index out of range #4

Open mareikedaubert opened 1 year ago

mareikedaubert commented 1 year ago

Hello, I am receiving an error with ginjinn predict in one of the datasets I am running it one. The error occurs at what is equivalent to the last step of the calculation from the example application "Leucanthemum leaf segmentation" from the docs. I have predicted from a bounding box model and cropped my images to the detected bounding boxes. Then I am predicting from a segmentation model. The prediction step runs to completion, but the refinement and output generation aborts after processing 2% of the data. Accordingly, I have ~1.300 input images, but only 32 images in my output folder. The error did not occur with another dataset I was working on at the same time and I used the same script on. The exact error message is:

  File "/user/me/.conda/envs/ginjinn2/lib/python3.7/site-packages/detectron2/utils/visualizer.py", line 241, in _create_text_labels
    labels = [class_names[i] for i in classes]
  File "/user/me/.conda/envs/ginjinn2/lib/python3.7/site-packages/detectron2/utils/visualizer.py", line 241, in <listcomp>
    labels = [class_names[i] for i in classes]
IndexError: list index out of range

What could cause this error to occur?

mareikedaubert commented 1 year ago

Hello, I just wanted to add that the error still occurs sporadically for me. The calculation always aborts in the refinement and output generation step after processing a part of the images. It also seems to be independent of the model as I have since implemented both mask_rcnn_X_101_32x8d_FPN_3x.yaml and mask_rcnn_R_101_FPN_3x.yaml.

ulilautenschlager commented 1 year ago

Hi Mareike, thanks for reporting this problem. Does ginjinn predict complete if you omit the -v/--visualize option?

mareikedaubert commented 1 year ago

Hello, skipping -v avoids the problem. The visualization output is not very essential for me, so I do not mind not having it. I have also tried allocating more RAM to the calculation, but that did not fix it.

ulilautenschlager commented 1 year ago

It seems in rare cases (e.g. after only short training) categories are predicted which should not exist. (You can verify this in your prediction directory with cat annotations.json | grep category_id | sort | uniq -c.) We need to fix this in the code, for the moment appending the following to your ginjinn_config.yaml (before training) should serve as a workaround:

detectron:
    MODEL:
        ROI_HEADS:
            NUM_CLASSES: <n>

Here, \ should be replaced by the number of categories, e.g. 1 if you only have a single leaf class.

mareikedaubert commented 1 year ago

Hello, Thank you, the workaround worked for me. Would you say it is a sign on insufficient training if this error occurs?

ulilautenschlager commented 1 year ago

It can be, but not necessarily. On the other hand, a large number of images/objects also makes the error more likely, so I would instead focus on the model performance (AP scores etc.) to decide on the number of training iterations.