Cloud give some samples on addSlice Layer to support dynamic bathsize?

Description

Previous topic mentioned this problem, and “To use dynamic slice, we need to set start/size/stride with ISliceLayer::setInput(). Hope this link will help you.” was a response to the question.
Cloud give some samples on addSlice Layer to support the 0th dimension is -1 ?
My code is as follows.

  IBuilder *builder = createInferBuilder(gLogger);
    IBuilderConfig *config = builder->createBuilderConfig();
    INetworkDefinition *network = builder->createNetworkV2(1U<<static_cast<int>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH));


    ITensor *data = network->addInput(INPUT_BLOB_NAME, DataType::kFLOAT, Dims4{-1,3, INPUT_H, INPUT_W});

   auto sliceLayer= network->addSlice(*data,Dims4{0, 0, (INPUT_H / 2), 0}, Dims4{-1, 3, (INPUT_H / 2), INPUT_W},
                      Dims4{1, 1, 1, 1});
    network->markOutput(*sliceLayer->getOutput(0));
    std::cout << "Building engine, please wait for a while..." << std::endl;
    IHostMemory *hostMemory = builder->buildSerializedNetwork(*network, *config);
    std::cout << "Build engine successfully!" << std::endl;

And the log as follows.

[03/08/2022-11:40:41] [E] [TRT] 9: [graphShapeAnalyzer.cpp::addVolumeCheck::610] Error Code 9: Internal Error ((Unnamed Layer* 0) [Slice]_output: dimension 0 never exceeds -1)
[03/08/2022-11:40:41] [E] [TRT] 3: (Unnamed Layer* 0) [Slice]: slice size cannot have negative dimension, size = [-1,3,112,224]
[03/08/2022-11:40:41] [E] [TRT] 4: [network.cpp::validate::2963] Error Code 4: Internal Error (Layer (Unnamed Layer* 0) [Slice] failed validation)
[03/08/2022-11:40:41] [E] [TRT] 2: [builder.cpp::buildSerializedNetwork::619] Error Code 2: Internal Error (Assertion engine != nullptr failed. )

Environment

TensorRT Version: 8
GPU Type: 3090
Nvidia Driver Version: 495.29.05
CUDA Version: 11.5
Operating System + Version: Ubuntu20.04

Hi,
Please refer to the below link for Sample guide.

Refer to the installation steps from the link if in case you are missing on anything

However suggested approach is to use TRT NGC containers to avoid any system dependency related issues.

In order to run python sample, make sure TRT python packages are installed while using NGC container.
/opt/tensorrt/python/python_setup.sh

In case, if you are trying to run custom model, please share your model and script with us, so that we can assist you better.
Thanks!

Thanks for your reply, but your reply is so board that i can not find any samples about the ISliceLayer to show how to support input dimension like[-1,3,224,224], cloud give me detailed sample ? Thanks.

Hi,

Currently couldn’t find a sample.
To use dynamic slice, we need to set start/size/stride with ISliceLayer::setInput().
Hope this link will help you.

https://docs.nvidia.com/deeplearning/tensorrt/api/c_api/classnvinfer1_1_1_i_slice_layer.html
https://docs.nvidia.com/deeplearning/tensorrt/api/python_api/infer/Graph/Layers.html#islicelayer

Thank you.

Thanks for these link, which will be of great help to me !

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