Convert torch-->onnx-->tensorrt get sub-tensor

Please provide an explanation of the error messages I encountered when converting two different ways of indexing a PyTorch tensor (using advanced indexing and using a custom indexing function) into ONNX and then TensorRT.
Specifically, when I tried to convert the indexing operation box=box[keep] or box = torch.index_select(box, 0, keep) , it resulted:

[ 0]Input → DataType.FLOAT (1, 3, 721, 960) (1, 3, 721, 960) input
[ 1]Output-> DataType.FLOAT (-1, 4) (-1, 4) box
[02/20/2023-22:32:34] [TRT] [E] 1: [graphContext.h::~MyelinGraphContext::35] Error Code 1: Myelin (Error 709 destroying stream ‘0x581bf030’.)
[02/20/2023-22:32:34] [TRT] [E] 1: [graphContext.h::~MyelinGraphContext::35] Error Code 1: Myelin (Error 709 destroying stream ‘0x6aab77f0’.)

On the other hand, when I tried to convert the custom indexing function box=get_sub(box,keep) that I used to index the tensor, it resulted :

[ 0]Input → DataType.FLOAT (1, 3, 721, 960) (1, 3, 721, 960) input
[ 1]Output-> DataType.FLOAT (23, 4) (23, 4) box
[02/20/2023-22:39:15] [TRT] [E] 7: [shapeMachine.cpp::executeContinuation::738] Error Code 7: Internal Error (/rpn/Gather_76: cannot do non-empty gather from an empty axis Condition ‘<’ violated: 0 >= 0. Instruction: CHECK_LESS 0 0.)

Can you please explain the cause of these errors and suggest how to resolve them?

box=torch.tensor([[3.9757e+02, 1.7175e+02, 4.5984e+02, 2.3181e+02],
[3.9709e+02, 1.7280e+02, 4.5805e+02, 2.3358e+02],
[3.9703e+02, 1.7704e+02, 4.5986e+02, 2.3405e+02],
[4.1861e+02, 8.1773e+01, 4.7217e+02, 1.4221e+02],
[4.1412e+02, 8.1290e+01, 4.7007e+02, 1.4078e+02],
[3.9646e+02, 1.7763e+02, 4.5724e+02, 2.3455e+02],
[4.2251e+02, 5.1695e+01, 4.6851e+02, 1.9899e+02],
[6.6601e+02, 4.3646e+02, 7.2502e+02, 5.3734e+02],
[4.2302e+02, 5.5282e+01, 4.6890e+02, 2.1063e+02],
[6.5495e+02, 4.5190e+02, 7.2045e+02, 5.4027e+02],
[4.1713e+02, 5.2906e+01, 4.6313e+02, 1.9826e+02],
[3.1367e+02, 4.5675e+02, 4.4594e+02, 5.6500e+02]])

keep=torch.tensor([ 5, 9, 0, 6, 1])

box= box[keep]

box = torch.index_select(box, 0, keep)

def get_sub(orgin_tensor, index_list):
    new =torch.full((len(index_list),4),fill_value=0.0)
    for i in range(len(index_list)):
         new[i]=orgin_tensor[index_list[i]]
    return new
box=get_sub(box,keep)

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

Hi,

Could you share a reproducible source with us so we can give it a try?
It will be good if both PyTorch and ONNX models can be shared as well.

Thanks.