Steps to use YOLOv5¶
Python Packages Dependencies¶
- Install following python paackages
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
torch>=1.7.0
torchdivision>=0.8.1
tqdm>=4.41.0
tensorboard>=2.4.1
pandas>=1.1.4
seaborn>=0.11.0
Environment Setup for YOLOv5¶
- Clone YOLOv5 repository
git clone https://github.com/ultralytics/yolov5
- Go to the yolov5 directory
cd yolov5
- Install python libraries using
pip install -r requirements.txt
Run YOLOv5 Model¶
- Download pretrained yolov5 weights from the link and save it in the sae directory ‘yolov5’
- For real time detection execute the commands
python3 detect.py –weights yolov5s.pt –source 0
- To run the model on the downloded video or images download the video or the image and put it in the yolov5 folder and then use the command as
For Image : python3 detect.py –weights yolov5s.pt –source imgname.jpg
For Video : python3 detect.py –weights yolov5s.pt –source videofilename.mp4
Issue faced¶
The installation command “pip install -r requirements.txt” works well with the jetpack 4.6 but in jetpack 4.4 the command fails while installing Opencv as can be seen in the screenshot below:
Solution¶
The issue can be resolved upgarding the version of pip, as the pip version installed with jetpack 4.4 is 9.0.1 and it needs higher version of pip. pip version can be upgarded using command as:
pip3 install –upgrade pip
Note¶
yolov5s.pt is PyTorch format of Yolov5. Other supported formats like TorchScript, TensorRT can also be used with the same command just replacing the correspoding weightfiles format
python3 detect.py –weights weightfiles.xx –source 0