facebookresearch / sam2

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
12.44k stars 1.15k forks source link

SAM model failing in detecting masks when 2 rectangles are provided #262

Open Shantilal-zanwar opened 2 months ago

Shantilal-zanwar commented 2 months ago

I am trying to detect handrails using SAM model but it is failing constantly. It work fine when one handrail need to be detected Figure_1-Failed

Shantilal-zanwar commented 2 months ago

Figure_2Failed

AlexMcClay commented 2 months ago

did you check the shape of the masks output? generally its something like (n, 1, height, width) where n is the number of boxes. Also I've found that the model is very weird about the coordinates of the boxes. the box cords basically have to be from top left to bottom right, if its in any other position or order it doesn't like it.

Look at this section in their example notebook for images, they explain how to do multiple boxes there

https://github.com/facebookresearch/segment-anything-2/blob/main/notebooks/image_predictor_example.ipynb

They explain it in the "Batched prompt inputs" section