Slices an input tensor into an output tensor based on the offset and strides.
More...
Slices an input tensor into an output tensor based on the offset and strides.
The slice layer has two variants, static and dynamic. Static slice specifies the start, size, and stride dimensions at layer create time via Dims and can use the get/set accessor functions of the ISliceLayer. Dynamic slice specifies the start and size dimensions at layer create time via ITensors and uses ILayer::setTensor to set the optional stride parameter after layer construction. An application can determine if the ISliceLayer is dynamic or static based on if there are 3 or 4 inputs(Dynamic) or 1 input(Static). When working on a shape tensor, a dynamic slace layer must have start, size, and stride specified at build time.
The slice layer selects for each dimension a start location from within the input tensor, and given the specified stride, copies strided elements to the output tensor. Start, Size, and Stride shape tensors must be DataType::kINT32.
For example using slice on a data tensor: input = {{0, 1}, {2, 3}, {4, 5}} start = {1, 0} size = {1, 2} stride = {1, 2} output = {1, 5}
- Warning
- Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
void nvinfer1::ISliceLayer::setInput |
( |
int |
index, |
|
|
ITensor & |
tensor |
|
) |
| |
|
pure virtual |
replace an input of this layer with a specific tensor.
- Parameters
-
index | the index of the input to modify. |
tensor | the new input tensor |
Sets the input tensor for the given index. The index must be 0 for a static slice layer. A static slice layer is converted to a dynamic slice layer by calling setInput with an index > 0. A dynamic slice layer cannot be converted back to a static slice layer.
For a dynamic slice layer, the values 0-3 are valid. If an index > 0 is specified, all values between index 0 and that index must be dynamic tensors. The values larger than index can use static dimensions. For example, if an index of two is specified, the stride tensor can be set via setStride, but the start tensor must be specified via setInput as both size and start are converted to dynamic tensors. The indices in the dynamic case are as follows:
Index | Description 0 | Data or Shape tensor to be sliced. 1 | The start tensor to begin slicing, N-dimensional for Data, and 1-D for Shape. 2 | The size tensor of the resulting slice, N-dimensional for Data, and 1-D for Shape. 3 | The stride of the slicing operation, N-dimensional for Data, and 1-D for Shape.
If this function is called with a value greater than 0, then the function getNbInputs() changes from returning 1 to index + 1. When converting from static to dynamic slice layer, all unset tensors, between 1 and index + 1, are initialized to nullptr. It is an error to attempt to build a network that has any nullptr inputs.
Implements nvinfer1::ILayer.