Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name collision with YOLO #116

Open
dzenanz opened this issue Jun 17, 2024 · 1 comment
Open

Name collision with YOLO #116

dzenanz opened this issue Jun 17, 2024 · 1 comment

Comments

@dzenanz
Copy link
Contributor

dzenanz commented Jun 17, 2024

I am trying to use a YOLOv5 trained model to provide box prompts to MedSA. However, when I try to load them both in the same script, I run into name collisions. Try 1:

from utils import cfg
args = cfg.parse_args()
detector = torch.hub.load(yolo_path, 'custom',
                          path=r'M:\Dev\...\best.pt',
                          source='local')

produces:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "M:\Dev\CXR\.venv\lib\site-packages\torch\hub.py", line 93, in _add_to_sys_path
    yield
  File "M:\Dev\CXR\.venv\lib\site-packages\torch\hub.py", line 597, in _load_local
    model = entry(*args, **kwargs)
  File "M:\Dev\CXR\yolov5\hubconf.py", line 88, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "M:\Dev\CXR\yolov5\hubconf.py", line 34, in _create
    from models.common import AutoShape, DetectMultiBackend
ImportError: cannot import name 'AutoShape' from 'models.common' (M:\Dev\CXR\Medical-SAM-Adapter\models\common\__init__.py)

Trying to apply advice from this discussion:

yolo_path = r"M:\Dev\CXR\yolov5"
sys.path.insert(0, yolo_path)
detector = torch.hub.load(yolo_path, 'custom',
                          path=r'M:\Dev\...\best.pt',
                          source='local')
sys.path.remove(yolo_path)
sys.path.append(r'M:\Dev\CXR')
sys.path.append(r'M:\Dev\CXR\Medical_SAM_Adapter')

from Medical_SAM_Adapter.utils import cfg

produces:

YOLOv5  v7.0-312-g1bcd17ee Python-3.9.13 torch-2.3.0+cu121 CUDA:0 (NVIDIA GeForce RTX 3090, 24576MiB)

Fusing layers... 
YOLOv5s summary: 157 layers, 7012822 parameters, 0 gradients, 15.8 GFLOPs
Adding AutoShape... 
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "M:\Dev\CXR\Medical_SAM_Adapter\utils.py", line 60, in <module>
    from models.discriminator import Discriminator
ModuleNotFoundError: No module named 'models.discriminator'

Both YOLOv5 and MedSA have module named models. How to avoid this name collision?

@25benjaminli
Copy link

@dzenanz you can try to manually change the code/filenames as a last resort, shouldn't be difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants