Darknet To TensorFlow and Other Conversions

Prashant Dandriyal
3 min readApr 17, 2020

--

You will find different methods to convert YOLO models collected here. The article explains how to go about converting your Darknet or rather YOLO models to other framework-formats like TensorFlow or TensorFlowLite (with and without quantisation).

I will be using Google Collaboratory to demonstrate the process.

Note : Different methods use different version of TensorFlow, do Restart your runtime each time!

Warning

Darknet to TensorFlow

The TensorFlow format generated at the output is the frozen graph (.pb) format. Remember, the .cfg files should always be downloaded (or cloned) in RAW format. That is, the link to the cfg file for v3-tiny is https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3-tiny.cfg and NOT https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-tiny.cfg.

Method 1: Using Darkflow (.weights -> .pb)

  • Only supports YOLO v2, v2-tiny and some image classification model (tested on Darknet-53)
  • Each time you select a model for conversion, do remember to copy the contents of the file : labels.txt present in the cloned DarkFlow folder. For v2-tiny and v3-tiny, the labels are based on the COCO dataset and can be found here: https://github.com/pjreddie/darknet/blob/master/data/coco.names. Initially and finally the txt file looks as shown:
Before
After

Method 2: Using Mystic’s method (.weights -> .pb)

  • Based on the method proposed by Mystic.
  • Tested on YOLO v3 and v3-tiny
  • The file saves the output frozen graph with the same name : “frozen_darknet_yolov3_model.pb.” So, make sure to save/rename the result before running the below command.

Method 3: Using DW2TF (.weights -> .pb)

  • Supports YOLO v2, v2-tiny, v3 and v3-tiny.
  • The method outputs as shown:
Output

DarkNet to ONNX to TensorFlow

There also exist other conversions; once you have obtained the frozen graph (.pb), you can further convert it to TensorFlowLite and quantized versions.

TensorFlow to TFLite (.pb -> tflite)

P.S. The article is regularly updated.

If I could help you, you can also send me some crypto like Solana, Ethereum, Doge or coins on BSC. 🤠

SOL wallet: Geyvsojk1KAegziagYAJ5HWaDuAFYKZAS2KpqZeag9DM

BSC wallet: 0x47acC4B652166AE55fb462e4cD7DD26eFa97Da04

ETH wallet: 0x47acC4B652166AE55fb462e4cD7DD26eFa97Da04

Doge wallet: DFT6Pydzw7RAYG1ww4RRfctBKqyiXbbBwk

--

--