Processing a dynamic input tensor containing different size images (batch size = 2, each batch contains images of a different size)

Hey everyone,

I’ve managed to get my TensorRT code working using a dynamic input tensor shape (Pytorch to ONNX conversion was used). The input tensor shape is (-1, 3, -1, -1) which means that the batch size, height and width are of a variable size. I create optimizations profiles that contain the MIN, OPT and MAX dimensions for dynamic input tensors. I set the optimization profile and the binding dimensions before calling enqueueV2.

So, everything works fine but my question is, is it possible to process an input tensor whose batch size is, for example, 2 but each batch contains an image of a different size. The image sizes would be within the OPT-MAX dimensions of the currently selected optimization profile. The input tensor would look something like this:

      C   H   W

Batch 0: 3, 1000, 2000
Batch 1: 3, 1200, 2200

Can this input tensor be processed using only one enqueueV2 call ?

Thank you!

Request you to share the ONNX model and the script if not shared already so that we can assist you better.
Alongside you can try few things:

  1. validating your model with the below snippet

import sys
import onnx
filename = yourONNXmodel
model = onnx.load(filename)
2) Try running your model with trtexec command.

In case you are still facing issue, request you to share the trtexec “”–verbose"" log for further debugging


I am not sure if I didn’t describe my question well or you didn’t understand it but I didn’t have any issue to report. I didn’t have any problems converting my model from ONNX to TRT or getting my TRT model to work. I actually had a question that I couldn’t find an answer to in any online TensorRT documentation.

Given the description in my initial post (dynamic input tensor shape…), is it possible to process an input tensor of a batch size of 2, for example, where each batch contains an image of a different size ?

Batch 0: 3, 1000, 2000
Batch 1: 3, 1200, 2200

I believe that once you set the binding dimensions/size before calling enqueueV2 that is the only size that can be processed by enqueueV2 until you change the binding size again. So, is it possible to process an input tensor whose batch size is greater than one and each batch contains a different size image/tensor using only one enqueueV2 call ?

I tried to ask the same question in two different ways hoping that you will understand what it is that I am asking about.



This is not supported. We have to do padding the image of the same batch to the same size.

Thank you.

Thank you so much for your reply, spolisetty.

I assumed that was the case but wanted to make sure.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.