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

Module collision when loading more than one model with Torch Hub #5083

Closed
carloalbertobono opened this issue Oct 7, 2021 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@carloalbertobono
Copy link

Hi, I think I have a similar issue to #2414 (I commented there but later realized that the issue was closed)

It prevents from loading more than one model using torch.hub
If I'm not mistaken by reading the thread, loading the model with torch.hub shadows some module names, that then become unusable within torch.

I'm using torch '1.9.1+cu102' on a Ubuntu 20.04 machine and to reproduce I do:

import torch
model = torch.hub.load('facebookresearch/detr', 'detr_resnet50', pretrained=True)
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

that ends up in

~/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py in _create(name, pretrained, channels, classes, autoshape, verbose, device)
     28     from pathlib import Path
     29 
---> 30     from models.yolo import Model
     31     from models.experimental import attempt_load
     32     from utils.general import check_requirements, set_logging

ModuleNotFoundError: No module named 'models.yolo'

reversing the load order obviously ends up with:

~/.cache/torch/hub/facebookresearch_detr_master/hubconf.py in <module>
      2 import torch
      3 
----> 4 from models.backbone import Backbone, Joiner
      5 from models.detr import DETR, PostProcess
      6 from models.position_encoding import PositionEmbeddingSine

ModuleNotFoundError: No module named 'models.backbone'

Is there some workaround which I'm not seeing?

Thank you very much, also for the awesome project itself
cb

@carloalbertobono carloalbertobono added the bug Something isn't working label Oct 7, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

👋 Hello @carloalbertobono, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at [email protected].

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@carloalbertobono thanks for the bug report. I am able to reproduce the issue using your code in colab. I'm not sure there's a simple fix, but also this might be slightly outside of our scope. You should definitely raise on pytorch and/or hub repos also, and link to this issue. Thanks!

https://github.com/pytorch/pytorch
https://github.com/pytorch/hub

@carloalbertobono
Copy link
Author

thank you @glenn-jocher, I'll do it!

@NicolasHug
Copy link

@glenn-jocher this is definitely an issue on the torchhub side (which I'm looking into), so feel free to close this one

@glenn-jocher
Copy link
Member

@NicolasHug thanks for looking into this! I'd imagine loading multiple hub models from different sources will become more common as the feature gains adoption, so probably worth the effort to find a fix.

Will close here and follow pytorch/hub#243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants