Skip to content

Commit dd8f7ee

Browse files
committed
add file
1 parent ea5d8ca commit dd8f7ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

yolov3/gen_wts.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import struct
2+
import sys
3+
from models import *
4+
from utils.utils import *
5+
6+
model = Darknet('cfg/yolov3.cfg', (608, 608))
7+
weights = sys.argv[1]
8+
dev = '0'
9+
if weights.endswith('.pt'): # pytorch format
10+
model.load_state_dict(torch.load(weights, map_location=device)['model'])
11+
else: # darknet format
12+
load_darknet_weights(model, weights)
13+
model = model.eval()
14+
15+
f = open('yolov3.wts', 'w')
16+
f.write('{}\n'.format(len(model.state_dict().keys())))
17+
for k, v in model.state_dict().items():
18+
vr = v.reshape(-1).cpu().numpy()
19+
f.write('{} {} '.format(k, len(vr)))
20+
for vv in vr:
21+
f.write(' ')
22+
f.write(struct.pack('>f',float(vv)).hex())
23+
f.write('\n')
24+

0 commit comments

Comments
 (0)