Grounded-Segment-Anything icon indicating copy to clipboard operation
Grounded-Segment-Anything copied to clipboard

Error Encountered While Executing Grounding-Dino-Sam Notebook with Custom Data - Class Label Mismatch Leads to TypeError

Open puranjay123 opened this issue 2 years ago • 3 comments

Hi, @rentainhe

I am trying to run grounding-dino-sam notebook when I tried with custom data ,it is giving error(stated below):

What I think and found: I found out that When the labels I have written and the labels detected by the model even mismatch by a little bit the code throws an error stated below. In a normal scenario there should be multiple labels and if there is a mismatch in Class labels and labels getting out from the model it should simply ignore the mismatched labels. When I try with default class the output is getting just fine CLASSES = ['car', 'dog', 'person', 'nose', 'chair', 'shoe', 'ear'] when I used my CLASSES labels it is throwing error stated below: CLASSES = ['dog' , 'paper' , 'cup' , 'Snack' , 'Candy' , 'Bag', 'Wrapper'] here is the link of my collab notebook here in which I encountered the error.

here is the list of the original collab notebook: here

here is the link for images that I used: here

TypeError   

      Traceback (most recent call last)
[<ipython-input-114-225db28cada8>](https://localhost:8080/#) in <cell line: 17>()
     15 # annotate image with detections
     16 box_annotator = sv.BoxAnnotator()
---> 17 labels = [
     18     f"{CLASSES[class_id]} {confidence:0.2f}"
     19     for _, _, confidence, class_id, _

[<ipython-input-114-225db28cada8>](https://localhost:8080/#) in <listcomp>(.0)
     16 box_annotator = sv.BoxAnnotator()
     17 labels = [
---> 18     f"{CLASSES[class_id]} {confidence:0.2f}"
     19     for _, _, confidence, class_id, _
     20     in detections]

TypeError: list indices must be integers or slices, not NoneType`
```

puranjay123 avatar Sep 07 '23 12:09 puranjay123

I also had a similar error as you. I don't know if my experience will be helpful, but I'm writing this in hopes of your luck. My case is as follows: CLASSES =["van","car"]

Grounddino generated a "van car" phrase that I did not specify, and an error occurred because it was not in CLASSES =["van","car"].

My solution is to change 'van car' to 'van'.

The following code was inserted at line 201 of the groundingdino/util/inference.py file.

        phrases_copy = phrases.copy()
        for index_phrase,phrase in enumerate(phrases_copy):
            if phrase.find(' ') != -1:
                phrases[index_phrase] = phrase[:phrase.find(' ')]

3942368 avatar Oct 21 '23 21:10 3942368

@3942368 why this occur?

yxchng avatar Nov 26 '23 13:11 yxchng

@yxchng When gronding-dino thinks there are different labels in the same image area, it creates a new label.

In my case, 'car' and 'van'were created in the exact same area of ​​the image, and gronding-dino created a new label called 'van car' that I did not specify.

So an error occurred.

In my case, the' van' and 'car' labels caused the problem. The superior probably had 'snacks', 'candy' that caused the problem.

Anyway, the new label created by gronding-dino is created as a combination of the labels I created, so my idea is to change the label created by gronding-dino to the label I created

3942368 avatar Nov 27 '23 02:11 3942368