IDEA-Research / Grounded-Segment-Anything

Grounded SAM: Marrying Grounding DINO with Segment Anything & Stable Diffusion & Recognize Anything - Automatically Detect , Segment and Generate Anything
https://arxiv.org/abs/2401.14159
Apache License 2.0
14.85k stars 1.37k forks source link

Error: grounded_sam_simple_demo #404

Open rkuo2000 opened 10 months ago

rkuo2000 commented 10 months ago

python grounded_sam_simple_demo.py

File "/kaggle/working/Grounded-Segment-Anything/grounded_sam_simple_demo.py", line 51, in labels = [ File "/kaggle/working/Grounded-Segment-Anything/grounded_sam_simple_demo.py", line 52, in f"{CLASSES[class_id]} {confidence:0.2f}" TypeError: list indices must be integers or slices, not NoneType

yxchng commented 10 months ago

i am also facing this problem, how to solve it?

rentainhe commented 10 months ago

You can check the output of your code to see if there are some objects to be detected or not

yxchng commented 10 months ago

@rentainhe

I only modify the following two lines in grounded_sam_simple_demo.py

SOURCE_IMAGE_PATH = "./assets/demo2.jpg"
CLASSES = ["The running dog"]

and print the detection results as such:

# print detections
for d in detections:
    print(d)

which gives me

(array([ 801.4983, 516.0155, 1788.2068, 991.4297], dtype=float32), None, 0.89449936, None, None)

Why is it giving None?

This problem has been mentioned here as well https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/371, https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/244,

What should I do to resolve this problem?

rentainhe commented 10 months ago

You can hack in the code and check the output name to see if it is matched with the running dog, this may be due to that grounding dino will only output the text whose confidence is larger than the text threshold, then the visualization tool will match the name with the input label to generate the final visualization file. I think there're something wrong with the name matching part here: https://github.com/IDEA-Research/Grounded-Segment-Anything/blob/c643397a5f641eb3f6450e8fd42c91ec7833031e/GroundingDINO/groundingdino/util/inference.py#L249

rentainhe commented 10 months ago

I've fixed some corner cases in this part, I may still miss some cases

yxchng commented 10 months ago

@rentainhe which commit has the fix?