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

Are pretrained models intended to be downlaoded into /home by torch.hub? #3889

Closed
johnohagan opened this issue Jul 5, 2021 · 6 comments · Fixed by #3904
Closed

Are pretrained models intended to be downlaoded into /home by torch.hub? #3889

johnohagan opened this issue Jul 5, 2021 · 6 comments · Fixed by #3904
Labels
question Further information is requested Stale

Comments

@johnohagan
Copy link
Contributor

Hi

I'm a python user using pretrained object detection for an art project, so not a developer!

I was using cv2.dnn with yolov3 but recently switched to torch.hub with yolov5. I love how easy it is to use, eg model = torch.hub.load(...), model.conf = 0.5, results = model(image).xyxyn, etc, exactly how software should be!

Something I've noticed when calling torch.hub.load from the ultralytics repo for the first time is that the model zipfiles are downloaded into my home directory. Is this intentional? This is not a big deal obviously, but other torch.hub repos seem to put these in a directory in ~.cache/torch/hub along with the other required files, which seems neater to me.

I added this line to my hubconf.py that fixes this, but obviously it disappears if I call anything with force_reload:

name = ''.join((str(Path(file).parent), '/', name))

Should I submit this as a bug report / feature request?

Thanks

@johnohagan johnohagan added the question Further information is requested label Jul 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2021

👋 Hello @johnohagan, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ 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), testing (test.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

glenn-jocher commented Jul 5, 2021

@johnohagan hmm that's an interesting idea. I'm not sure if people actually want to see these model.pt files or if they want them hidden away.

But sure please submit a PR, thanks!

See our Contributing Guide if you have questions on how to submit a PR.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 5, 2021

@johnohagan I think the path code you want is something like this, but you should also be aware that passing a path will download the model to that path also, which is a feature we need to retain:

model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/download/model.pt')

so you probably want to check that name does not include any directories before assigning it to the cache directory with something like:

name = Path(__file__).parent / name

EDIT: Above comments mainly apply to torch.hub.load('ultralytics/yolov5', 'custom', ...)

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 5, 2021

@johnohagan FYI hubconf.py updated slightly in #3894 with unrelated changes today.

johnohagan added a commit to johnohagan/yolov5 that referenced this issue Jul 6, 2021
Re issue ultralytics#3889, added code to download model.pt files into ~/.cache/torch/hub/ultralytics_yolov5_master/ instead of  ~.
@johnohagan
Copy link
Contributor Author

Thanks, I submitted that pull request. I should have made it clear that the line I added was to the _create function and modifies the "name" argument passed to that function.

Since then I had a quick look at the where the pytorch/vision repo puts .pt(h) files, and it's ~/.cache/torch/hub/checkpoints. If that was considered better the line would be
name = ''.join((str(Path(__file__).parent.parent), '/checkpoints/', name))

I've also just learbed from your comment that I don't need the ''.join for Path objects so I'll fix that either way.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2021

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants