问题:VGG16训练出的模型效果很好,但是是PTH格式的,想转换为ONNX通用模型,但会报错。报错内容:torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of operator adaptive_avg_pool2d, output size that are not factor of input size. Please feel free to request support or submit a pull request on PyTorch GitHub: Issues · pytorch/pytorch [Caused by the value '70 defined in (%70 : Long(2, strides=[1], device=cpu) = onnx::Constant[value= 7 7 [ CPULongType{2} ]]()
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Constant'.]
Inputs:Empty
Outputs:#0: 70 defined in (%70 : Long(2, strides=[1], device=cpu) = onnx::Constant[value= 7 7 [ CPULongType{2} ]]()
) (type 'Tensor')
解答:只需要把输入维度固定为VGG16的输入图像的尺寸224*224就可以了。因为权重文件的参数数量是提前预设好的,如果随意改变,adaptive_avg_pool2d的输出就不是7*7*512了。
这个问题已经困扰我一周了,今天好不容易解决,记录一下。全网没找到相关答案,在这里找到答案并解决的小伙伴请留个赞。Thanks♪(・ω・)ノ