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