label-studio-ml-backend icon indicating copy to clipboard operation
label-studio-ml-backend copied to clipboard

SAM Model Predict Bug

Open PtttCode opened this issue 1 year ago • 2 comments

I had followed https://github.com/heartexlabs/label-studio-ml-backend/tree/master/label_studio_ml/examples/segment_anything_model to deploy SAM model

But there are some bugs of SAM predictions:

The coordinates of the mask will be offset from the target I expected, but in fact the shape of the mask is correct

Examples:

  1. Here is a 2048*1024 image performance(Offset): 图片

  2. Here is a 640*426 image performance(Correct): 图片

  3. Here is a 640*480 image performance(Offset): 图片

There are absolutely bugs on the process after prediction, and I think the key of question is the image padding

Here are the original images: 88a3f9da-berlin_000005_000019_leftImg8bit d6d991d3-000000055150 d01284fc-000000167486

PtttCode avatar Jun 01 '23 10:06 PtttCode

Probably related to this issue with the ONNX model: https://github.com/anuragxel/salt/issues/2

Seems like masks are off for input images not matching the aspect ratio (2:3) set with

"orig_im_size": torch.tensor([1500, 2250], dtype=torch.float),

in onnxconverter.py

Your example image, with a size of 640x426, happens to have the correct aspect ratio.

jflessau avatar Jun 07 '23 09:06 jflessau

Hi, this issue was addressed in the pull request mentioned. @jflessau thank you so much for pointing me in the right direction. This new pull request (if using the AdvancedSAM backend instead) should have no issues with masks offsetting from images -> this is an ONNX issue described in the README of this pull request.

shondle avatar Jul 26 '23 05:07 shondle