forked from ysh329/darknet2caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
darknet2inferx.py
37 lines (32 loc) · 1.43 KB
/
darknet2inferx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from darknet2caffe import *
from caffe2inferx import *
if __name__ == "__main__":
import sys
if len(sys.argv) != 3:
print('Usage: python {} DARKNET_CFG DARKNET_WEIGHTS'.format(sys.argv[0]))
exit(-1)
############################################################
# Step1. convert to Caffe's *.prototxt, *.caffemodel files #
# from Darknet #
############################################################
cfg_file = sys.argv[1]
weights_file = sys.argv[2]
name = cfg_file.replace(".cfg", "")
prototxt_file = ".".join([name, "prototxt"])
caffemodel_file = ".".join([name, "caffemodel"])
darknet2caffe(cfg_file, weights_file, prototxt_file, caffemodel_file)
format_data_layer(prototxt_file)
correct_pooling_layer(cfg_file, prototxt_file)
#########################################################
# Step2. convert to InferXLite's *.c, *.h, *.dat files #
# from Caffe #
#########################################################
# net_compiler
net = Net(prototxt_file)
print("[INFO] Successful conversion from {}.prototxt to {}.c and {}.h" \
.format(name, name, name))
# caffe_compiler
print("[INFO] Start to convert weight file ......")
main(caffemodel_file)
print("[INFO] Successful conversion from {}.caffemodel to {}.dat" \
.format(name, name))