一. 背景介绍
当我们的测试代码有很多依赖,或者训练测试代码在一起时,如何快速地导出onnx?
二. 实现
利用测试代码中原始的数据处理,在模型测试的时候直接导出onnx,并对比torch和onnx的推理结果。
tips:设置一个export_onnx参数,直接导出onnx。
实现代码如下,一个例子:
with torch.no_grad():
export_onnx = True
if export_onnx:
input_img = img_mix.to(device)
save_path =