Installing YOLOv4 with Anaconda
This project uses the YOLOv4/Anaconda Setup by The AI Guy. This is part one of this series:
- Installing YOLOv4 using Anaconda
- License Plate Recognition with YOLOv4, OpenCV and Tesseract
- Crop License Plate from the Original Image
Yolo4 Object Detection Setup
Dependencies
Anaconda
Install Conda:
wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh
chmod +x Anaconda3-2021.11-Linux-x86_64.sh
bash Anaconda3-2021.11-Linux-x86_64.sh
Add conda
to your PATH variables (~/.bashrc, ~/.zshrc, etc) - don' t forget to source
it afterwards:
export PATH="/home/myuser/anaconda3/bin:$PATH"
Verify:
conda --version
conda 4.10.3
Initialize your shell with:
conda init <SHELL_NAME>
Currently supported shells are:
bash
fish
tcsh
xonsh
zsh
powershell
Git
conda install -c anaconda git
Source Repository
And clone the source code from Github:
git clone https://github.com/mpolinowski/yolov4-custom-functions.git
Pre-trained Weights
YOLOv4 comes pre-trained and able to detect 80 classes. For easy demo purposes we will use the pre-trained weights. Download pre-trained yolov4.weights
file:
Copy and paste yolov4.weights
from your downloads folder into the 'data' folder of the repository.
Virtual Environment
Enter the repository and either run the CPU or GPU setup - the latter requires an NVIDIA graphic card with CUDA support:
CPU
conda env create -f conda-cpu.yml
conda activate yolov4-cpu
GPU
conda env create -f conda-gpu.yml
conda activate yolov4-gpu
Convert weights to TensorFlow Format
To implement YOLOv4 using TensorFlow, first we convert the .weights into the corresponding TensorFlow model files and then run the model.
Convert darknet weights to tensorflow:
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4
Run YOLOv4
Run YOLOv4 Tensorflow Model on an Image
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/Old_Town.jpg
Run YOLOv4 from a Video File
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video ./data/video/cars.mp4 --output ./detections/results.avi
Run YOLOv4 on a Webcam Stream
Connect your webcam and run YOLOv4:
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video 0 --output ./detections/results.avi
Run YOLOv4 on a INSTAR IP Camera Stream
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video http://192.168.0.80:80/mjpegstream.cgi?-chn=11&-usr=admin&-pwd=instar