-
Notifications
You must be signed in to change notification settings - Fork 86
/
pth2onnx.py
executable file
·80 lines (44 loc) · 1.96 KB
/
pth2onnx.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
@Fire
https://github.com/fire717
"""
import os
import random
import pandas as pd
import torch
from lib import init, Data, MoveNet, Task
from config import cfg
def main(cfg):
init(cfg)
model = MoveNet(num_classes=cfg["num_classes"],
width_mult=cfg["width_mult"],
mode='train')
run_task = Task(cfg, model)
run_task.modelLoad('output/test/e100_valacc0.98349.pth')
run_task.model.eval()
run_task.model.to("cuda")
#data type nchw
dummy_input1 = torch.randn(1, 3, 192, 192).to("cuda")
input_names = [ "input1"] #自己命名
output_names = [ "output1","output2","output3","output4" ]
# torch.onnx.export(model, (dummy_input1, dummy_input2, dummy_input3), "C3AE.onnx", verbose=True, input_names=input_names, output_names=output_names)
torch.onnx.export(run_task.model, dummy_input1, "output/pose.onnx",
verbose=True, input_names=input_names, output_names=output_names,
do_constant_folding=True,opset_version=11)
# model = MoveNet(num_classes=cfg["num_classes"],
# width_mult=cfg["width_mult"],
# mode='test')
# run_task = Task(cfg, model)
# run_task.modelLoad('output/test/e104_valacc0.95586.pth')
# run_task.model.eval()
# run_task.model.to("cuda")
# #data type nchw
# dummy_input1 = torch.randn(1, 3, 192, 192).to("cuda")
# input_names = [ "input1"] #自己命名
# output_names = [ "output1" ]
# # torch.onnx.export(model, (dummy_input1, dummy_input2, dummy_input3), "C3AE.onnx", verbose=True, input_names=input_names, output_names=output_names)
# torch.onnx.export(run_task.model, dummy_input1, "output/pose.onnx",
# verbose=True, input_names=input_names, output_names=output_names,
# do_constant_folding=True,opset_version=11)
if __name__ == '__main__':
main(cfg)