1. 问题
训练时采用的pytorch框架,采用动态尺寸的输入。所以最好的目标就是像用pytorch一样,采用动态尺寸的输入,得到动态尺寸的输出
- pspnet解码部分的上采样,在python下能得到任意尺寸的输出,但导出到onnx时是不能的。因为
interpolate
函数的size要输入为int,而 torch.onnx.export 又不支持 int 的输入类型
解决方案: 设置interpolate的 scale_factor参数,这样不能多尺度测试
## onnx 输入多大,返回多大,不能用多尺度测试
x = nn.functional.interpolate(
x, scale_factor=8.0, mode='bilinear')
x = nn.functional.softmax(x, dim=1)
问题2: onnxruntime和pytorch interpolate结果不一样
pytorch的interpolate,转onnx后,再用onnxruntime进行验证的时候,pytorch的输出和onnxruntime的结果有差异
发生异常: AssertionError
Not equal to tolerance rtol=0.1, atol=1e-10
Mismatched elements: 1429278 / 1945600 (73.5%)
Max absolute difference: 0.67711896
Max relative difference: 14.636919
x: array([[[[8.655339e-01, 8.655339e-01, 8.655339e-01, ..., 7.575323e-01,
7.575323e-01, 7.575323e-01],
[8.655339e-01, 8.655339e-01, 8.655339e-01, ..., 7.575323e-01,...
y: array([[[[8.655338e-01, 8.727098e-01, 8.793454e-01, ..., 7.575321e-01,
7.575321e-01, 7.575321e-01],
[8.592935e-01, 8.666480e-01, 8.734899e-01, ..., 7.461441e-01,...
File "/home/data/CM/8_instance_segmentation/semantic-segmentation-pytorch/to_onnx.py", line 107, in local_test
np.testing.assert_allclose(to_numpy(torch_out), ort_outs[0], rtol=1e-01, atol=1e-010)
File "/home/data/CM/8_instance_segmentation/semantic-segmentation-pytorch/to_onnx.py", line 119, in <module>
local_test()
解决方案: 无