-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenwts.py
37 lines (34 loc) · 993 Bytes
/
genwts.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
import torch
from torch import nn
import torchvision
import os
import struct
#from torchsummary import summary
# mod
def main():
print('cuda device count: ', torch.cuda.device_count())
device = 'cuda:1'
net = torch.load('retinaface.pth')
net = net.to(device)
net.eval()
print('model: ', net)
#print('state dict: ', net.state_dict().keys())
tmp = torch.ones(1, 3, 640, 640).to(device)
print('input: ', tmp)
out = net(tmp)
print('output:', out)
if os.path.exists('retinafacePlate.wts'):
return
f = open("retinaface.wts", 'w')
f.write("{}\n".format(len(net.state_dict().keys())))
for k,v in net.state_dict().items():
print('key: ', k)
print('value: ', v.shape)
vr = v.reshape(-1).cpu().numpy()
f.write("{} {}".format(k, len(vr)))
for vv in vr:
f.write(" ")
f.write(struct.pack(">f", float(vv)).hex())
f.write("\n")
if __name__ == '__main__':
main()