使用 ONNXRuntime 加载 ONNX 模型时出错

Error in loading ONNX model with ONNXRuntime

我正在将自定义的 Pytorch 模型转换为 ONNX。然而,当用ONNXRuntime加载它时,我遇到了如下错误:

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: ...onnxruntime/core/providers/cpu/tensor/transpose.h:46 onnxruntime::TransposeBase::TransposeBase(const onnxruntime::OpKernelInfo &) v >= 0 && static_cast<uint64_t>(v) <= std::numeric_limits<size_t>::max() was false.

我已经与 onnx.checker.check_model() 核对过,完全没问题。 我也尝试在 forward() 函数中将 transpose() 替换为 permute() 但错误仍然存​​在。

有人熟悉这个错误吗?

环境:

Python 3.7
Pytorch 1.9.0
CUDA 10.2 
ONNX 1.10.1
ONNXRuntime 1.8.1 
OS Ubuntu 18.04

节点 Transpose_52perm 属性是 [-1, 0, 1] 尽管 ONNX 运行时要求它们都应该是正数:onnxruntime/core/providers/cpu/tensor/transpose.h#L46