| 1 | # Darknet To NCNN Conversion Tools |
| 2 | |
| 3 | This is a standalone darknet2ncnn converter without additional dependency. |
| 4 | |
| 5 | Support yolov4, yolov4-tiny, yolov3, yolov3-tiny and enet-coco.cfg (EfficientNetB0-Yolov3). |
| 6 | |
| 7 | Another conversion tool based on darknet can be found at: [darknet2ncnn](https://github.com/xiangweizeng/darknet2ncnn) |
| 8 | |
| 9 | ## Usage |
| 10 | |
| 11 | ``` |
| 12 | Usage: darknet2ncnn [darknetcfg] [darknetweights] [ncnnparam] [ncnnbin] [merge_output] |
| 13 | [darknetcfg] .cfg file of input darknet model. |
| 14 | [darknetweights] .weights file of input darknet model. |
| 15 | [cnnparam] .param file of output ncnn model. |
| 16 | [ncnnbin] .bin file of output ncnn model. |
| 17 | [merge_output] merge all output yolo layers into one, enabled by default. |
| 18 | ``` |
| 19 | |
| 20 | ## Example |
| 21 | |
| 22 | ### 1. Convert yolov4-tiny cfg and weights |
| 23 | |
| 24 | Download pre-trained [yolov4-tiny.cfg](https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4-tiny.cfg) and [yolov4-tiny.weights](https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights) or with your own trained weight. |
| 25 | |
| 26 | Convert cfg and weights: |
| 27 | ``` |
| 28 | ./darknet2ncnn yolov4-tiny.cfg yolov4-tiny.weights yolov4-tiny.param yolov4-tiny.bin 1 |
| 29 | ``` |
| 30 | |
| 31 | If succeeded, the output would be: |
| 32 | ``` |
| 33 | Loading cfg... |
| 34 | WARNING: The ignore_thresh=0.700000 of yolo0 is too high. An alternative value 0.25 is written instead. |
| 35 | WARNING: The ignore_thresh=0.700000 of yolo1 is too high. An alternative value 0.25 is written instead. |
| 36 | Loading weights... |
| 37 | Converting model... |
| 38 | 83 layers, 91 blobs generated. |
| 39 | NOTE: The input of darknet uses: mean_vals=0 and norm_vals=1/255.f. |
| 40 | NOTE: Remember to use ncnnoptimize for better performance. |
| 41 | ``` |
| 42 | |
| 43 | ### 2. Optimize graphic |
| 44 | |
| 45 | ``` |
| 46 | ./ncnnoptimize yolov4-tiny.param yolov4-tiny.bin yolov4-tiny-opt.param yolov4-tiny-opt.bin 0 |
| 47 | ``` |
| 48 | |
| 49 | ### 3. Test |
| 50 | |
| 51 | build examples/yolov4.cpp and test with: |
| 52 | |
| 53 | ``` |
| 54 | ./yolov4 dog.jpg |
| 55 | ``` |
| 56 | |
| 57 | The result will be: |
| 58 | |
| 59 |  |
| 60 | |
| 61 | |
| 62 | ## How to run with benchncnn |
| 63 | |
| 64 | Set 2=0.3 for Yolov3DetectionOutput layer. |
| 65 | |