Exploratory Data Analysis
How our data looks like?
Annotations format (YOLO Format): [class, x_center, y_center, obj_width, obj_height]
Distributions
They make sense for number plate images
- x values are well distributed, which means the cameraman did a good job :D
- y values are well distributed as well, but, most of the objects are on top of our images.
- both height and width make sense, because our object is licence plate and they all have almost similiar sizes.
X vs Y & Height vs Width
- As mentioned above, there is a lack in our dataset in buttom-half part of xy plane.
- As we can see, the center of our x axis is dense, it's beacuse humans put the object in the center of the camera.
Tensorflow Implementation for YOLOv4
It's recommended to train your custom detector on darknet, rather than this implemntation, and then convert your weights and use this implemntation.
!git clone https://github.com/hunglc007/tensorflow-yolov4-tflite
Environment Setup
Conda Environment
# Create
# tf < 2.5 | python = 3.7
# tf > 2.5 | python > 3.9
!conda create --name envname python=3.7
# Activate
!activate envname
Requirements
# in tf > 2.5 both cpu and gpu use the same package
# GPU
!pip install -r requirements-gpu.txt
# CPU
!pip install -r requirements.txt
Check
!conda list # installed packages in current env
!python --version
Set the environment as jupyter kernel
!pip install ipykernel
!python -m ipykernel install --user --name=envname
Then choose yolov4tf from kernels in your notebook
Tensorflow
Convert weights
!python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4
COCO Dataset
!python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --image ./data/kite.jpg
Custom Dataset
- Create a custom.names file in data/classes and type your class (based on your weights and training)
- Call the custom.names in config.py (change coco.names to custom.names)
- Change the paths in detect.py
!python detect.py --weights ./checkpoints/custom --size 416 --model yolov4 --image ./data/custom.jpg
3. Tflite
Recommended for mobile and edge devices.
Convert
# Save tf model for tflite converting
!python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite
# YOLOv4
!python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite
Demo
!python detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite
Metrics
- Precision: 91 %
- Average Precision: 89.80 %
- Recall: 86 %
- F1-score: 88 %
- Average IoU: 74.06 %
- [email protected]: 89.80 %
- Confusion Matrix:
- TP = 439
- FP = 45
- FN = 73
- unique_truth_count (TP+FN) = 512
- detections_count = 805