ONNX to TensorRT Upsampling node "The scales input must be an initializer" error

Description

Converting a PyTorch model to ONNX then to TensorRT fails with the following error:
[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:725: ERROR: builtin_op_importers.cpp:4426 In function importUpsample:
[8] Assertion failed: (scales_input.is_weights()) && “The scales input must be an initializer.”

There is indeed an upsample node in the model, with the following forward function:

M = nnf.upsample(M, size=(skip_x.size(2), skip_x.size(3)), mode='bilinear', align_corners=False)

I found a possibly related thread from last year, which states that using a “resize layer with scale factor of output tensor from concat layer” is not supported by TensorRT. (Title: Assertion failed: scales.is_weights() && “Resize scales must be an initializer!”) Since this upsample layer depends on the size of the input which may vary, can you confirm that this feature is indeed not supported on the current version?

If that’s the case, what does “initializer” here mean?

Environment

TensorRT Version: 8.0.1.6
GPU Type: NVIDIA GTX 1080 Ti
Nvidia Driver Version: Host machine has 470.57.02
CUDA Version: 11.4.1
CUDNN Version: 8.2.2.26
Operating System + Version: Ubuntu 20.04
Python Version (if applicable): 3.8
TensorFlow Version (if applicable): N/A
PyTorch Version (if applicable): 1.10.0a0+3fd9dcf
Baremetal or Container (if container which image + tag): nvcr.io/nvidia/pytorch:21.08-py3

Relevant Files

PyTorch file:
https://get.station307.com/aB1SKIAfq4e/model-ResNet18DenseRef-10-ADEAffSynth12.th

ONNX file:
https://get.station307.com/YEDKjgbJle8/model-ResNet18DenseRef-10-ADEAffSynth12_ONNX.onnx

Steps To Reproduce

  1. Download the model (TH file).
  2. Load and export the model to ONNX using the steps described in the quick start guide from Nvidia
  3. Convert the resulting ONNX file to TensorRT using:
    trtexec --onnx=model-ResNet18DenseRef-10-ADEAffSynth12_ONNX.onnx --saveEngine=my_engine.trt --explicitBatch
  4. The resulting terminal output’s error section reads:

[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:720: While parsing node number 61 [Upsample → “268”]:
[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:721: — Begin node —
[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:722: input: “250”
input: “267”
output: “268”
name: “Upsample_61”
op_type: “Upsample”
attribute {
name: “mode”
s: “linear”
type: STRING
}

[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:723: — End node —
[09/02/2021-10:17:37] [E] [TRT] ModelImporter.cpp:725: ERROR: builtin_op_importers.cpp:4426 In function importUpsample:
[8] Assertion failed: (scales_input.is_weights()) && “The scales input must be an initializer.”
[09/02/2021-10:17:37] [E] Failed to parse onnx file
[09/02/2021-10:17:37] [I] Finish parsing network model
[09/02/2021-10:17:37] [E] Parsing model failed
[09/02/2021-10:17:37] [E] Engine creation failed
[09/02/2021-10:17:37] [E] Engine set up failed

1 Like

Hi @s.bien,
Please refer to below link in case it’s helpful:

Thanks

Confirmed to work. Solution:

skip_x_h, skip_x_w = int(skip_x.size(2)), int(skip_x.size(3))

Where the int() parameter is essential; without it, the compilation still fails.

1 Like