CASIA-IVA-Lab / FastSAM

Fast Segment Anything
GNU Affero General Public License v3.0
7.51k stars 709 forks source link

No module named ultralytics #235

Closed AlmendrosCarmona closed 4 months ago

AlmendrosCarmona commented 4 months ago

Hi!

I am cloning the repository, changing directory to it and installing requirements but when I run a simple code to test fastsam I found the follwoing error:

ModuleNotFoundError: No module named 'ultralytics'

The code I am trying to run is:

# test.py
from FastSAM.fastsam import FastSAM, FastSAMPrompt

import os

# Cargamos el modelo fast sam
model = FastSAM("FastSAM.pt")
DEVICE = 'cpu'

everything_results = model("test.jpg", device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)
prompt_process = FastSAMPrompt("test.jpg", everything_results, device=DEVICE)
ann = prompt_process.everything_prompt()
output_filename = f'output.jpg'
output_path = os.path.join('.', output_filename)
prompt_process.plot(annotations=ann, output=output_path)

And my folder structure is as simple as:

Someones can help me ? Thanks in advance..

UPDATE: I know that I have to use the folder ultralytics rather than de module of ultralytics. When I wasn't using venv my error was ultralytics.yolo not found but this error was solved by applying a venv and installing only the packages in requirements.txt of the FastSAM repository.

AlmendrosCarmona commented 4 months ago

SOLUTION:

This happens because the system does not know where to find the folder ultralytics. There are three main solutions (as far as I know):

  1. Run custom code inside the FASTSam folder.
  2. Run the following code before importing FastSAM
    import sys
    fastsam_path = './FastSAM'
    if fastsam_path not in sys.path:
     sys.path.insert(0, fastsam_path)
  3. Run `pip install -e 'FastSAM' to turn the folder into a package.

I highly recommend to use the ultralytics implementation or a virtual envorionment to prevent this problems.

Thanks.