anaconda3/lib/python3.9/site-packages/mmcv/ops/point_sample.py:76: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
y1 = torch.where(y1 > padded_h - 1, torch.tensor(padded_h - 1).to(device), y1)
之前的博文里讲了用open-mmcv中的mmcv.ops.point_sample.bilinear_grid_sample解决onnx不支持torch.nn.functional.grid_sample的问题
但是近期在onnxruntime推理过程中又遇到了mmcv中grid_sample不支持动态输入的问题,转onnx模型时有上述警告,一开始没有当回事,在静态输入时也完全没有问题,直到动态推理时遇到了axis不匹配的问题。
最终找到了解决方案:
使用onnxsim将onnx模型简化,对复杂模块封装,这意外的解决了我的问题
- 安装onnxsim
pip install onnxsim
- 简化你原本的onnx模型
onnxsim inp.onnx out.onnx
- 加载新的onnx模型进行动态推理
顺利解决问题
原onnx模型:
问题主要在红框圈出来的部分 造成了最下方的concat维度不匹配
经过onnxsim优化后的模型
可以看出 输出的结果成功的变为动态维度了