mazurowski-lab / SlicerSegmentWithSAM

3D Slicer extension for Segment Anything Model (SAM) developed by Meta
Apache License 2.0
28 stars 6 forks source link

Cannot find PyTorch extension #18

Open jcohenadad opened 2 months ago

jcohenadad commented 2 months ago

Hi,

I keep getting the following message after I installed the SlicerSegmentWithSAM extension:

image

Even when I click on "OK" and wait for several minutes, nothing happens. I restarted Slicer, this did not help either. And it seems that the Pytorch module is in fact installed:

image

Possibly a duplicate of #17

noneedanick commented 1 month ago

I just encountered the same problem and solved it !

It is stated in the readme that in the manual installation option you have to install packages using following codes in the 3D slicer's python terminal: slicer.util.pip_install("torch torchvision torchaudio") and slicer.util.pip_install("opencv-python")

After I checked outputs in the python terminal I found that when you install SAM from extension manager and try to open it, the extension tries to check its dependencies and for the torch package it gives you following error: ERROR: Could not find a version that satisfies the requirement torch>=1.7 (from versions: 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 2.2.2) ERROR: No matching distribution found for torch>=1.7

I think authors should revise the dependencies of the package.

Shortly just execute slicer.util.pip_install("torch torchvision torchaudio") and slicer.util.pip_install("opencv-python") in the slicer python terminal, wait for libraries to be installed, restart the extension and its done !

jcohenadad commented 1 month ago

Thank you @noneedanick 🙏 ! It did fix the issue. I'll keep the issue open so the developers can consider improving the installation workflow.

kirbyju commented 1 month ago

I'm on a Macbook Pro M2 and thought maybe this might be related to my issue. Sadly the suggestion from @noneedanick didn't resolve the problem.

Collecting https://github.com/facebookresearch/segment-anything/archive/6fdee8f2727f4506cfbbe553e23b895e27956588.zip
  Using cached https://github.com/facebookresearch/segment-anything/archive/6fdee8f2727f4506cfbbe553e23b895e27956588.zip
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Traceback (most recent call last):
  File "/Applications/Slicer-5.6.2.app/Contents/Extensions-32448/SegmentWithSAM/lib/Slicer-5.6/qt-scripted-modules/SegmentWithSAM.py", line 135, in __init__
    from segment_anything import sam_model_registry, SamPredictor
  File "/Applications/Slicer-5.6.2.app/Contents/lib/Python/lib/python3.9/site-packages/segment_anything/__init__.py", line 15, in <module>
    from .automatic_mask_generator import SamAutomaticMaskGenerator
  File "/Applications/Slicer-5.6.2.app/Contents/lib/Python/lib/python3.9/site-packages/segment_anything/automatic_mask_generator.py", line 9, in <module>
    from torchvision.ops.boxes import batched_nms, box_area  # type: ignore
ModuleNotFoundError: No module named 'torchvision.ops'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Slicer-5.6.2.app/Contents/Extensions-32448/SegmentWithSAM/lib/Slicer-5.6/qt-scripted-modules/SegmentWithSAM.py", line 137, in __init__
    raise RuntimeError("There is a problem about the installation of 'segment-anything' package. Please try again to install!")
RuntimeError: There is a problem about the installation of 'segment-anything' package. Please try again to install!
[Qt] qSlicerPythonCppAPI::instantiateClass  - [ "SegmentWithSAMWidget" ] - Failed to instantiate scripted pythonqt class "SegmentWithSAMWidget" 0x7fc5171305a0