Darkeras: Execute YOLOv3/YOLOv4 Object Detection on Keras with Darknet Pre-trained Weights

Everything in the universe is connected.

LA Tran
Towards Data Science

--

Convolutional neural network-based object detection has become a dominant topic in computer vision as it has attracted numerous researchers in the field. Various state-of-the-art methods can be categorized into two main genres: one-stage object detector (e.g. SSD, YOLOv1-v5, EfficientDet, RetinaNet) and two-stage object detector (e.g. R-CNN, Fast R-CNN, Faster R-CNN, Cascade R-CNN). While two-stage object detectors aim to improve the detection accuracy, one-stage object detection methods have been developed in an attempt to balance the trade-off between the accuracy and the inference speed, hence, they are getting more attraction due to the applicability to the real-world problems which require the mentioned trade-off balance.

Figure from Paper: Object Detection in 20 Years: A Survey

Among dozens of elite methods, YOLO (You Only Look Once) by Joseph Redmon has been considered one of the most powerful and classical methods in the field. Although Joseph announced that he stopped going on his project which began an important milestone of object detection due to some individual reasons, he gave the leading privilege of YOLO project to Alexey Bochkovskiy, and Alexey introduced YOLOv4 in 2020. You can have a look at this project via the official website or the github repo darknet.

Image from Darknet Website

Above is just a piece of information that you might care about (might be not). Now we go back to the reason that brought you here to read this post, the title: “Darkeras: Execute YOLOv3/YOLOv4 Object Detection on Keras with Darknet Pre-trained Weights”. You guys may know how to use Darknet, some other guys may be professionals in Tensorflow-Keras. In my experience of using both frameworks, Darknet was created for object detection, thus, it should be optimized and produce more favorable results than that of Tensorflow-Keras in this task. It is like a guy who knows one thing deeply and another guy who knows things extensively. In this scenario, Darknet is the first guy who knows deeply about YOLO. However, Darknet was not designed for users to customize too much! For example, you can change the network architecture, hyperparameters, but you can not or it is too hard to do some high-level learning methods like knowledge distillation, hint-based learning, or feature map analysis, but Tensorflow-Keras can. To take advantage of the beautiful values from both of these guys, I end up writing this post and provide you guys a tool for converting Darknet trained weights and executing object detection on Tensorflow-Keras. You can have look at my project here (darkeras).

The description of the project is presented as follows:

Dependencies

  • OpenCV
  • Tensorflow 2.3.0
  • Keras 2.4.0

Supported Models

  • YOLOv3
  • YOLOv4

How to Use

  • Put pre-trained weights downloaded from the official Darknet website or your trained weights into “weights” folder (If you use your model trained on your customed dataset, please change NUM_CLASS and ANCHORS in the notebooks)
  • Run YOLOv3: darkeras-yolov3.ipynb
  • Run YOLOv4: darkeras-yolov4.ipynb

Detection Results

  • Input
Image from Github
  • YOLOv3
Image from Github
  • YOLOv4
Image from Github

Have fun!

The project has been updated frequently.

Conclusions

In this post, I have introduced Darkeras, a tool written in Python for converting weight files trained on Darknet software to Keras framework. This project aims to support high-level learning methods such as knowledge distillation, hint-based learning, or feature map analysis in the Tensorflow-Keras framework using weights trained on Darknet software.

Readers are welcome to visit my github repo of this project and Facebook fanpage which is for sharing things regarding Machine Learning: Diving Into Machine Learning.

Thanks for spending time!

--

--

PhD in Machine Learning and Computer Vision | Once the WHY is clear, the HOW goes easy.