UX-Decoder / Semantic-SAM

[ECCV 2024] Official implementation of the paper "Semantic-SAM: Segment and Recognize Anything at Any Granularity"
2.27k stars 107 forks source link

ModuleNotFoundError: No module named 'MultiScaleDeformableAttention' - Google Colab #72

Open SharmaNatasha opened 11 months ago

SharmaNatasha commented 11 months ago

I am trying to run Semantic SAM on google colab and seeing below issue even after compiling CUDA operators cd ./models/ops sh ./make.sh


ModuleNotFoundError Traceback (most recent call last) /content/Semantic-SAM/semantic_sam/body/encoder/ops/functions/ms_deform_attn_func.py in 21 try: ---> 22 import MultiScaleDeformableAttention as MSDA 23 except ModuleNotFoundError as e:

ModuleNotFoundError: No module named 'MultiScaleDeformableAttention'

During handling of the above exception, another exception occurred:

ModuleNotFoundError Traceback (most recent call last) 13 frames /content/Semantic-SAM/semantic_sam/body/encoder/ops/functions/ms_deform_attn_func.py in 27 "\tsh make.sh\n" 28 ) ---> 29 raise ModuleNotFoundError(info_string) 30 31

ModuleNotFoundError:

Please compile MultiScaleDeformableAttention CUDA op with the following commands: cd mask2former/modeling/pixel_decoder/ops sh make.sh

zlin-monarch commented 11 months ago
cd Semantic-SAM 
git clone https://github.com/facebookresearch/Mask2Former.git
cd Mask2Former/mask2former/modeling/pixel_decoder/ops
sh make.sh

it should work~

SharmaNatasha commented 11 months ago

Thank you @zlin-monarch I have tried this earlier and tried again after you suggested.. but when import semantic sam from semantic_sam import prepare_image, plot_multi_results, build_semantic_sam, SemanticSAMPredictor I get no module found for it.

Here is the code i am running

!pip install torch torchvision !git clone https://github.com/UX-Decoder/Semantic-SAM !pip install -r requirements.txt

!pip install 'git+https://github.com/MaureenZOU/detectron2-xyz.git' %cd "/content/Semantic-SAM" !git clone https://github.com/facebookresearch/Mask2Former %cd "Mask2Former/mask2former/modeling/pixel_decoder/ops" !sh make.sh

from semantic_sam import prepare_image, plot_multi_results, build_semantic_sam, SemanticSAMPredictor original_image, input_image = prepare_image(image_pth='/content/Semantic-SAM/examples/4.png')

zlin-monarch commented 11 months ago

Hi, may I check what is ur workpath when running import semantic sam?

U can use pwd to check it. It should be on Semantic-SAM directory, or else u can come back to Semantic-SAM by cd ~/Semantic-SAM after doing the installation

SharmaNatasha commented 11 months ago

Please find below attached screenshot. after installing mask2former when I change the directory to semantic sam, i get no error for multiscaledeformable

Screenshot 2023-10-16 at 3 05 19 PM
zlin-monarch commented 11 months ago

Okay. I tried on colab and met the same errorimage It is due to that the library path related to cuda might have been hard-coded during compilation, and has been written into the 'so' file, which seems to be the root of the problem or need sudo permission.

This problem can be prevented when we run it on the server and configure CUDA manually. Related link: csdn: ModuleNotFoundError: No module named ‘Multiscaledeformableattention‘

anja-sheppard commented 6 months ago
cd Semantic-SAM 
git clone https://github.com/facebookresearch/Mask2Former.git
cd Mask2Former/mask2former/modeling/pixel_decoder/ops
sh make.sh

it should work~

For anyone else with this issue (not in colab) this comment worked for me.