ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.99k stars 16.16k forks source link

Running on Jetpack #1944

Closed sammilei closed 3 years ago

sammilei commented 3 years ago

Hi, I saw people back in Sep 2020 able to use python3.6 and torch 1.6 to run YOLOv5 on Jetpack(Linux18.04). I have issues in installing torch 1.7 to Jetpack with python3.8. I wonder if I can use two other ways:

  1. use an older version of YOLOv5 with python3.6+torch1.7, which I have successfully installed but failed the YOLOv5 requirements installation.
  2. try another combination - torch1.8 and python3.8 as someone claimed a success.

Does anyone know if it is possible to get an older version of YOLOv5 or prove that torch1.8 works? Thanks!

glenn-jocher commented 3 years ago

@sammilei you can access any release of YOLOv5 very easily:

git clone https://github.com/ultralytics/yolov5
cd yolov5
git checkout v3.0
tensorturtle commented 3 years ago

@sammilei On my Jetson Xavier NX, I am successfully running YOLOv5 with python 3.6.9 + torch 1.7, by manually installing the required packages. Doing so required manual building of OpenCV, PyTorch, and the rest of the pip packages.

Before you follow anything I did below, you must get a fresh reinstall of JetPack 4.4.1 which has Python 3.6.9. I tried using virtual environments for python versions but that was fruitless.

First, to build OpenCV, this guide worked. JetPack ships with a version of OpenCV, but it is not CUDA-enabled and is an older version, so it's better to rebuild. https://qengineering.eu/install-opencv-4.5-on-jetson-nano.html

Next, for PyTorch I followed NVIDIA's guide https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-7-0-now-available/72048

Finally, for all the other requirements (Cython, matplotlib, Pillow, PyYAML, scipy, tensorboard, tqdm, seaborn, pandas), I simply got them with 'pip3 install ...'. For almost all of them, pre-built binaries were not available, so it took a very long time. Each one took something like 30 minutes.

I did not have success in getting anything to work with python 3.8, or any other version.

My Jetson Xavier NX info systeminfo-xavier

sammilei commented 3 years ago

@triangularsalt Thanks a lot for your comment! I did try Jetpack 4.4.1(Python 3.6) + Pytorch 1.7 installed manually then I failed to install YOLOv5. So then I went with trials with Python 3.8. Probably I didn't build the OpenCV beforehand. I will try your approach with a fresh Jetpack 4.4.1. I will give updates later.

sammilei commented 3 years ago

Thanks to @neuroquantifier's instruction, I was able to install OpenCV and torch and most of the dependencies. I am able to import torch with the built-in python3.6:

Python 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. ->>> import torch ->>> print(torch.version) 1.7.0

jtop

An issue occurs during the installation of torchvision as

running egg_info
creating pip-egg-info/torch.egg-info
writing pip-egg-info/torch.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/torch.egg-info/dependency_links.txt
writing requirements to pip-egg-info/torch.egg-info/requires.txt
writing top-level names to pip-egg-info/torch.egg-info/top_level.txt
writing manifest file 'pip-egg-info/torch.egg-info/SOURCES.txt'
error: package directory 'torch/cuda' does not exist
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-6eg7m99c/torch/

Running python3 detect.py --source inference/images/bus.jpg --weights yolov5s.pt --img 640 requires torchvision.

How did you install torchvision? @neuroquantifier? Thanks in advance!

sammilei commented 3 years ago

@neuroquantifier nvm. I installed torchvision through the same link for torch installation for Jetpack. The YOLOv5 works! I appreciate your help!

ttocs167 commented 3 years ago

@neuroquantifier how did you install thop? This is the final thing I cant manage to install and I am getting errors when running detect.py without it. If I do pip3 install thop I get an error

Could not find a version that satisfies the requirement torch>=1.0.0

I can't seem to install thop from source either as I get an error saying 'torch/cuda' directory doesn't exist.

Ownmarc commented 3 years ago

@ttocs167 thop is optional requirement.. remove it from requirements.txt and you’ll be good.

ttocs167 commented 3 years ago

@Ownmarc Ah, thank you so much! I also had to remove the OpenCV requirement and change the torchvision requirement to get past this check, everything is running now. Thanks so much for the help.

glenn-jocher commented 3 years ago

@Ownmarc @ttocs167 I've opened a PR #2041 for excluding packages from the requirements check. It's unclear to me which packages to add to the default list however.

Another option is to comment the check in detect.py altogether, under the assumption detect.py is more commonly used in deployed environments like jetpack.

Ownmarc commented 3 years ago

@glenn-jocher Jetpack/Jetsons are a bit tricky, I would assume people playing with it to be able to play with the code and the requirement file.

I would simply make the requirement check a little more flexible so it can adapt to where its called in the code (detect vs train vs test). Having a lightweight deployment environment is key (nothing more then what's required to do the detections and serving the model) when we want to deploy in prod, the train/test environment can be a little more messy because we often change things there. Pycocotools and thop should be considered like the tensorboard and W&B requirements.. nice to have but not hard requirements

glenn-jocher commented 3 years ago

@Ownmarc PR #2571 now excludes pycocotools and thop from detect.py check_requirements() per your recommendation, and also based on user feedback from https://github.com/ultralytics/yolov5/discussions/2556.

0marA commented 1 year ago

I'm trying to install YOLOV5 on Python 3.6 for use on a Jetson Nano. I can't use a different Python version because I need PyTorch with support for CUDA 10.2 which only works with Python 3.6 because of Jetpack 4. I followed @tensorturtle instructions in regards to installing OpenCV with CUDA and a version of PyTorch with CUDA, but I can not get a version of Ultralytics to install for Python 3.6. I've followed the Ultralytics installation guide to clone the repo and pip install the requirements.txt file. It will all finish successfully. I've even tried checking out version 3.0 and repeating the installation, but I keep getting the error: ModuleNotFoundError: No module named 'ultralytics'. Any help would be much appreciated.

glenn-jocher commented 1 year ago

@0marA hi there!

The ModuleNotFoundError: No module named 'ultralytics' error message usually implies a package installation issue. You might want to check if the ultralytics package was installed successfully after running pip install -U -r requirements.txt.

If the package is still not found, please try running pip install -U . in the YOLOv5 directory, which should install the local package.

Please let us know if this helps resolve the issue or if you need further assistance.

0marA commented 1 year ago

Thank you for your response! I git checked out v3.0 and ran those commands with pip3 (python 3.6) and it will go through all the requirements and say that they are satisfied, but when I try to open a python3.6 shell and import ultralytics it will say the module is not found. However, if I pip install with python3.8 (python3.8 -m pip install -U -r requirements.txt) everything works...but unfortunately I can't use python3.8 with the version of torch that uses CUDA on my nano :(. So I need to have Ultralytics run on Python 3.6. I know it isn't officially supported but a workaround would be awesome. Cheers

glenn-jocher commented 1 year ago

@0marA hi there!

It's great to hear that the pip install -U -r requirements.txt command works with Python 3.8, but I understand that you need to use Python 3.6 with the version of torch that uses CUDA on your Nano.

As you mentioned, YOLOv5 is not officially supported on Python 3.6, but there may be a workaround that you can try. One possible solution is to try building the ultralytics package from source using Python 3.6 and the corresponding version of torch that you need. This process is described in the YOLOv5 README under the "Local install" section.

Alternatively, you could try creating a Python 3.6 virtual environment and installing all of the requirements there. This should ensure that all of the packages are installed with the correct version of Python.

I hope these suggestions are helpful! Let us know if you have any further questions or concerns.

0marA commented 1 year ago

Unfortunately running in a virtual environment didn't seem to change anything :(. I'd like to try building the package, but I can't seem to find where that is in the README. Would you mind pointing it out to me? Thank you. EDIT: Nevermind, I think I found the instructions in the ultralytics repo

glenn-jocher commented 1 year ago

@0marA I'm sorry to hear that creating a virtual environment did not work. Regarding building the ultralytics package from source, the instructions are provided in the YOLOv5 README under the "Local install" section. If you encounter any issues during the build process, please don't hesitate to ask for assistance. We're here to help!