TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

Problem in slice layer with dynamic shape input

Open yux94 opened this issue 6 years ago • 7 comments

hi , we were trying to build a network with a dynamic input, and the network have some slice layers. Then we got a failure: slice size must be positive.
Do you have any suggestions for this problem?Thx~

yux94 avatar May 13 '20 04:05 yux94

Hi @yux94 ,

Please share:

  1. full error traceback
  2. the code that reproduces the error
  3. all environment info requested in issue template

rmccorm4 avatar May 14 '20 15:05 rmccorm4

@rmccorm4 Thank you for your reply. In my case, the slice layer throws an error if shape with dim -1:

slicelayer = network. add_slice(input, start, shape, stride)

the input dims : (-1,768,1,1) while the network has a dynamic input(1,3,32,-1) and 3 dense block before this. What we want is to split&concat, and get the output with (-1*h, 768/h,1,1) first, h=8 then we set

slicenum=input. get_output(0).shape[1]/8 for i in range(8): ……start_index = slice_num*i ……slicelayer = network. add_slice(input, (0,start_index,0,0), (input. get_output(0).shape[0],slice_num,1,1) ,(1,1,0,0))

The error traceback is: [Slice] slice size must be positive, size =[-1,96,1,1]

###environment tensorRT version 7.0.0.11 CUDA version 9.0. 176 CUDNN version 7.5.0 GPU Type Tesla M60

yux94 avatar May 15 '20 01:05 yux94

@rmccorm4 Thank you for your reply. In my case, the slice layer throws an error if shape with dim -1:

slicelayer = network. add_slice(input, start, shape, stride)

the input dims : (-1,768,1,1) while the network has a dynamic input(1,3,32,-1) and 3 dense block before this. What we want is to split&concat, and get the output with (-1*h, 768/h,1,1) first, h=8 then we set

slicenum=input. get_output(0).shape[1]/8 for i in range(8): ……start_index = slice_num*i ……slicelayer = network. add_slice(input, (0,start_index,0,0), (input. get_output(0).shape[0],slice_num,1,1) ,(1,1,0,0))

The error traceback is: [Slice] slice size must be positive, size =[-1,96,1,1]

###environment tensorRT version 7.0.0.11 CUDA version 9.0. 176 CUDNN version 7.5.0 GPU Type Tesla M60

I have the same error, have you solved this problem?

jiuzhuanzhuan avatar Sep 29 '20 03:09 jiuzhuanzhuan

meet same error with a dynamic input model, how to solve it?

wnzhyee avatar Nov 18 '20 12:11 wnzhyee

Hello @yux94 @jiuzhuanzhuan @wnzhyee Have you tried 7.2? If you still see the failure in 7.2, could you share your model or code? thanks!

ttyio avatar Nov 27 '20 11:11 ttyio

I will close this since no response for more than 3 weeks, please reopen if you still have question, thanks!

ttyio avatar Jan 12 '21 14:01 ttyio

i think you have to extract the shapes at runtime with a shape layer, and use the setInput method in slice layers as describe in the 7.3 section of this doc : https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#work_dynamic_shapes

Charles-Mensah avatar Aug 19 '21 09:08 Charles-Mensah