Tutorial: Yolov3 in Keras
Reference
Github: https://github.com/qqwweee/keras-yolo3
Setup
Create Virtual Environment (Conda)
Lets create a virtual environment for YOLOv3.
The requirements are
python=3.7.10
cudatoolkit=10.0
cudnn-7.6.5-cuda10.0_0
tensorflow-gpu=1.15.0
keras=2.3.1
pillow=8.2.0
matplotlib=3.3.4
opencv=3.4.2
If you have problems when installing opencv packages, use the following commands pip install opencv-python
Install the following:
Clone Git
After the installation, activate the virtual environment. We will clone the reference repository to download Yolov3 codes.
Method 1: From conda prompt (in virtual env)
git https://github.com/qqwweee/keras-yolo3.git
Method 2:
Download zip file from the github and unzip.
Download the trained weight file
After the download, place the weight model file in the same directory of Yolov3.
YOLOv3 weights https://pjreddie.com/media/files/yolov3.weights
You can also download it from the conda Prompt as
wget
https://pjreddie.com/media/files/yolov3.weights
``
YOLOv3-tiny weights
https://pjreddie.com/media/files/yolov3-tiny.weights
Open V.S Code
>> code .
You can also run the below codes in the Conda Promt
In VS code, select the virtual environment: F1--> Python Interpreter --> Select Environ.
Convert Darknet YOLOv3 to Keras model
In the terminal of VS code or in Conda Prompt, type:
Run Yolov3 Detection
Copy the test video file in the same directory (Yolov3 directory)
If the video file name is 'test_Video.avi'
Run Yolov3-Tiny Detection
After downloading yolov3-tiny.weights, Convert it to Keras model and save it as 'yolo-tiny.h5'
Run Yolo-tiny with the Test video
Usage
Use --help to see usage of yolo_video.py:
How to train a dataset
Prepare the dataset
For this tutorial, we will use KITTI dataset
Image file: Download Kitti Dataset
Label file: Download Kitti Dataset Label
Object Detection annotation Convert to Yolo Darknet Format: Click here
Class file:
Copy the 'kitti_classes.txt' in the folder of `\model_data` folder
Modify train.py
Open 'train.py' file in VS Code\
Go to LIne 16 : def main():. Change the ''annotation' and 'classes-path' to your setting.
Go to LIne 32: Change the name of the pre-trained weight file.
We will use COCO trained weight file as we used above(yolo.h5). Create a copy and name it as
yolo_weights.h5
Run Train
Start training by running the following in the terminal
Evaluate
Use your trained weights or checkpoint weights with command line option --model model_file
when using yolo_video.py Remember to modify the class path or anchor path.
TroubleShooting
Problem 1
Error message of
_, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
Solution
Modify model.py
(line 394)
_, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
should be changed to
_, ignore_mask = tf.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
Last updated