-
Notifications
You must be signed in to change notification settings - Fork 1
/
export_onnx.py
27 lines (26 loc) · 887 Bytes
/
export_onnx.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
import torch
import onnxruntime
import nnet
import utils
args = utils.get_args()
# args.device=torch.device("cpu")
model = nnet.get_models(args)
ckpt_path = "./ckpt/SVTR_711_Son/SVTR_0711_0.9.ckpt"
# ckpt_path = "./ckpt/SVTR_kalapa_2710/checkpoints/SVTR.ckpt"
checkpoint = torch.load(ckpt_path, map_location=args.device)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
model = model.to(args.device).half()
dummy_input = torch.rand([1,3,48,720]).to(args.device).half()
torch.onnx.export(
model,
dummy_input,
'halfbestmodel.onnx',
input_names = ['image'],
output_names = ['logit'],
# dynamic_axes = {'batch_images': {0: 'batch'},
# 'batch_logits': {0: 'batch'}},
opset_version=15,
verbose=True,
# operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK
)