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

Make requirements installation optional #3094

Closed
tadejsv opened this issue May 10, 2021 · 13 comments · Fixed by #3298 or #3495
Closed

Make requirements installation optional #3094

tadejsv opened this issue May 10, 2021 · 13 comments · Fixed by #3298 or #3495
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@tadejsv
Copy link

tadejsv commented May 10, 2021

🚀 Feature

I am using yolov5 via torch.hub. When I load a model, the library attempts to install all the requirements. This is a problem for me, as the installed packages interfere with my system packages. Specifically, I have opencv installed via conda, but yolo5 does not see it, and assumes it is missing, so it starts installing opencv-python. This then messes up some of opencv functionality. And in general, some packages that it tries to install are not strictly necessary - you only need PIL if you use it to load images, which I do not.

Would it be possible to make this installation optional, and just issue a warning if some packages are not found? This would make my life much easier :)

@tadejsv tadejsv added the enhancement New feature or request label May 10, 2021
@github-actions
Copy link
Contributor

github-actions bot commented May 10, 2021

👋 Hello @tadejsv, 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

@tadejsv hi thanks for the feedback! Yes we are aware of this issue and are looking for a fix, see #3073 for a duplicate issue. Pillow is a requirement for Hub models as it is used throughout our autoshape wrapper.

Could you run the commands in #3073 (comment) and report back your results? Thank you!

@glenn-jocher glenn-jocher added the duplicate This issue or pull request already exists label May 10, 2021
@tadejsv
Copy link
Author

tadejsv commented May 10, 2021

Hi @glenn-jocher - I ran the commands from the issue mentioned, both show no package found, even though import cv2 works normally.

But I don't think that is a duplicate issue. My issue is not that in this particular case the right package is not picked up, it is that I would prefer that yolo5 would not install any packages on its own, when loading it from torch hub. I am aware that Pillow is used for loading images - but only if you pass a filename (and not a numpy array), which is what I am not doing.

@glenn-jocher
Copy link
Member

@tadejsv Pillow is a hard requirement. You can not run YOLOv5 PyTorch Hub models without it, regardless of your input method. If you're missing it and it is being auto-installed then everything is working as intended.

If your opencv installation is not found, then there is a bug and things are not working as intended.

I'm confused though, none of the 3 methods in #3073 (comment) detected your opencv-python installation?

@tadejsv
Copy link
Author

tadejsv commented May 10, 2021

No, because it is not installed with pip. I am aware that things are "working as intended", that's why I opened this as a feature request and not a bug report :)

@tadejsv
Copy link
Author

tadejsv commented May 10, 2021

To clarify, the package I have installed is py-opencv, and not opencv-python. But it's also not detected by any of the 3 methods, though you can see it with conda list

@glenn-jocher
Copy link
Member

glenn-jocher commented May 10, 2021

@tadejsv you may not want to rely on 3rd party opencv packages, as their reliability is unknown, and also because they will cause conflicts with the requirements.txt dependencies.

One workaround if you would like to experiment with alternate packages is to simply fork this repo into your own directory, make any modifications you want to your forked hubconf.py, and then load YOLOv5 Hub models from your fork:

import torch

# Model
model = torch.hub.load('your_github_account/yolov5', 'yolov5s')

You can comment the check_requirements() function here, or add opencv-python to the exclude list:

check_requirements(Path(__file__).parent / 'requirements.txt', exclude=('tensorboard', 'pycocotools', 'thop'))

@tadejsv
Copy link
Author

tadejsv commented May 10, 2021

@glenn-jocher I've had no issue with reliability so far. I am using the conda installation of opencv as it is compiled with some OpenCV modules which the pip installation does not have. I also prefer using conda as it makes sure all other system dependencies are installed.

I am aware I could fork the repo, I was just hoping for a more "elegant" solution that does not involve maintaining my own fork. Anyways, I see that changes to requirements installation here aren't something you are willing to consider, so I'll be closing this issue.

@tadejsv tadejsv closed this as completed May 10, 2021
@glenn-jocher
Copy link
Member

@tadejsv thanks for the feedback, we'll keep it in mind for future updates.

@glenn-jocher
Copy link
Member

glenn-jocher commented May 23, 2021

@tadejsv good news 😃! Your original issue may now be fixed ✅ in PR #3298. This PR increases robustness to failures in check_requirements() function during attempted package installs. To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

@glenn-jocher glenn-jocher linked a pull request May 23, 2021 that will close this issue
@tadejsv
Copy link
Author

tadejsv commented May 23, 2021

@glenn-jocher This does not solve my issue, as my issue was not with failures during installation, but rather with unwanted packages being installed

@glenn-jocher
Copy link
Member

@tadejsv got it, thanks for the feedback!

@glenn-jocher glenn-jocher linked a pull request Jun 7, 2021 that will close this issue
@glenn-jocher
Copy link
Member

@tadejsv good news 😃! Your original issue may now be fixed ✅ in PR #3495. This PR adds opencv-python to the hubconf.py check_requirements() exclude list, allowing for 3rd party or contrib versions of OpenCV to be used. To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
2 participants