Improve YOLOv4 real time object detection on Jetson Nano
YOLOv4 was released at the end of April. It soon gained popularity among the machine learning community. You can check it out with following link.
- YOLO v4 essay:https://arxiv.org/abs/2004.10934
- YOLO v4 code:https://github.com/AlexeyAB/darknet
Compared with YOLOv3, YOLOv4’s AP has increased by 10%, while its FPS has increased by 12%. But can Jetson Nano handle YOLOv4? If you have tried YOLOv3 (darknet version) on Jetson Nano to perform real-time object detection, especially using the darknet version, you know what I’m saying. Usually, Jetson can only run the detection at around 1 FPS.
But with YOLOv4, Jetson Nano can run detection at more than 2 FPS.
Although YOLOv4 runs 167 layers of neural network, which is about 50% more than YOLOv3, 2 FPS is still too low. Now let’s try to accelerate it with PyTorch.
Run the following command
1 2 3 4 5 | git clone https://github.com/ultralytics/yolov3 && cd yolov3 #down load yolov4 pre-trained weights wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights #convert darknet cfg/weights to pytorch model python3 -c "from models import *; convert('cfg/yolov4.cfg', 'yolov4.weights')" |
When success, you can run the YOLOv4 PyTorch model by using the following command
1 | python3 detect.py --cfg cfg/yolov4.cfg --weights weights/yolov4.pt --source 0 |
Although the accuracy has been improved, FPS is still not satisfying. But fortunately, YOLOv5 is now available. For more information about YOLOv5, please check my next blog.
I run “python3 -c “from models import *; convert(‘cfg/yolov4.cfg’, ‘yolov4.weights’)””, It show error “RuntimeError: shape ‘[512, 256, 3, 3]’ is invalid for input of size 282158”
10 fps = 0.1s)))?
Around 0.122 seconds per frame