ChaoningZhang / MobileSAM

This is the official code for MobileSAM project that makes SAM lightweight for mobile applications and beyond!
Apache License 2.0
4.86k stars 505 forks source link

"bash ./experiments/mobilesamv2.sh" does not work on Mac M1 #148

Open tugsjargal1 opened 7 months ago

tugsjargal1 commented 7 months ago

Hi MobileSAM team,

First of all, thank you for this amazing library.

I am trying to run "bash ./experiments/mobilesamv2.sh" shell on my Mac Book M1 pro chip laptop. I have installed a lot of packages without any error. And I got error message when I run:

cd MobileSAMv2
bash ./experiments/mobilesamv2.sh
 bash ./experiments/mobilesamv2.sh
/Users/user/MobileSAM/MobileSAM-master/.venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/tinyvit/tiny_vit.py:656: UserWarning: Overwriting tiny_vit_5m_224 in registry with tinyvit.tiny_vit.tiny_vit_5m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/tinyvit/tiny_vit.py:656: UserWarning: Overwriting tiny_vit_11m_224 in registry with tinyvit.tiny_vit.tiny_vit_11m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/tinyvit/tiny_vit.py:656: UserWarning: Overwriting tiny_vit_21m_224 in registry with tinyvit.tiny_vit.tiny_vit_21m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/tinyvit/tiny_vit.py:656: UserWarning: Overwriting tiny_vit_21m_384 in registry with tinyvit.tiny_vit.tiny_vit_21m_384. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/tinyvit/tiny_vit.py:656: UserWarning: Overwriting tiny_vit_21m_512 in registry with tinyvit.tiny_vit.tiny_vit_21m_512. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
checkpoint_load_scucess
2.jpg

0: 1024x1024 82 objects, 1468.1ms
Speed: 5.3ms preprocess, 1468.1ms inference, 1.4ms postprocess per image at shape (1, 3, 1024, 1024)
Traceback (most recent call last):
  File "/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/Inference.py", line 122, in <module>
    main(args)
  File "/Users/user/MobileSAM/MobileSAM-master/MobileSAMv2/Inference.py", line 82, in main
    input_boxes = torch.from_numpy(input_boxes).cuda()
  File "/Users/user/MobileSAM/MobileSAM-master/.venv/lib/python3.9/site-packages/torch/cuda/__init__.py", line 284, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

How can I resolve this one ? I am using M1 Pro chip Mac book.

Thanks in advance! :)

DLTBryan commented 4 months ago

Hello, I am not in the team but from what I see, you need to have CUDA to use torch which the AMcbook M1 does not have.

It has the MEtal API to use the GPU part of the SOC chip. So maybe you should try it on a different device taht has a CUDA compatible GPU. =)

Pizzawookiee commented 4 months ago

Torch without CUDA is fine. However the code needs a slight alteration.

Go to Inference.py in the folder MobileSamV2. At line 82 it says "input_boxes = torch.from_numpy(input_boxes).cuda()", you would change it to "input_boxes = torch.from_numpy(input_boxes).cpu()".