onnx-tensorrt: Gather in Upsample problem
Hi! Cant export model from onnx to tensorrt.
`----------------------------------------------------------------
Input filename: model.onnx
ONNX IR version: 0.0.4
Opset version: 9
Producer name: pytorch
Producer version: 1.1
Domain:
Model version: 0
Doc string:
WARNING: ONNX model has a newer ir_version (0.0.4) than this parser was built against (0.0.3).
Parsing model
WARNING: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
Successfully casted down to INT32.
While parsing node number 69 [Gather -> “208”]:
ERROR: /home/alex/tools/onnx-tensorrt/onnx2trt_utils.hpp:335 In function convert_axis:
[8] Assertion failed: axis >= 0 && axis < nbDims
%206 : Long() = onnx::Constantvalue={2}, scope: ResNet18_OneConvDecoder/DecoderBlock[center]/Sequential[block]/Upsample[0]
%207 : Tensor = onnx::Shape(%205), scope: ResNet18_OneConvDecoder/DecoderBlock[center]/Sequential[block]/Upsample[0]
%208 : Long() = onnx::Gather[axis=0](%207, %206), scope: ResNet18_OneConvDecoder/DecoderBlock[center]/Sequential[block]/Upsample[0]
%209 : Tensor = onnx::Constantvalue={2}
%210 : Tensor = onnx::Mul(%208, %209)`
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (2 by maintainers)
I also had this issue with a model coming from PyTorch. Here’s an explanation of what I did to work around the problem:
This PyTorch model, when exported to ONNX, fails when importing in TensorRT because of the Gather operation:
However, this model works:
with just a warning during export to onnx that the trace might not generalize to other inputs.
A single PyTorch upsampling by a factor of 2 gets traced like this:
A PyTorch interpolate function will also work if you supply not the upsampling factor, but the already-known future size of your tensor. Below an upsampler for (batch_size x channels x H x W) tensors:
Which gets traced to ONNX like this:
thus avoiding the Gather and which functions in TensorRT.
@jinfagang try