Skip to content

create_dl_layer_sliceCreateDlLayerSliceCreateDlLayerSlicecreate_dl_layer_sliceT_create_dl_layer_sliceπŸ”—

Short descriptionπŸ”—

create_dl_layer_sliceCreateDlLayerSliceCreateDlLayerSlicecreate_dl_layer_sliceT_create_dl_layer_slice β€” Create a slice layer.

SignatureπŸ”—

create_dl_layer_slice( dl_layer DLLayerInput, string LayerName, number Axes, number StartIndices, number EndIndices, number Steps, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerSlice )void CreateDlLayerSlice( const HTuple& DLLayerInput, const HTuple& LayerName, const HTuple& Axes, const HTuple& StartIndices, const HTuple& EndIndices, const HTuple& Steps, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerSlice )static void HOperatorSet.CreateDlLayerSlice( HTuple DLLayerInput, HTuple layerName, HTuple axes, HTuple startIndices, HTuple endIndices, HTuple steps, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerSlice )def create_dl_layer_slice( dllayer_input: HHandle, layer_name: str, axes: MaybeSequence[Union[int, str]], start_indices: MaybeSequence[int], end_indices: MaybeSequence[int], steps: MaybeSequence[int], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandle

Herror T_create_dl_layer_slice( const Htuple DLLayerInput, const Htuple LayerName, const Htuple Axes, const Htuple StartIndices, const Htuple EndIndices, const Htuple Steps, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerSlice )

HDlLayer HDlLayer::CreateDlLayerSlice( const HString& LayerName, const HTuple& Axes, const HTuple& StartIndices, const HTuple& EndIndices, const HTuple& Steps, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerSlice( const HString& LayerName, Hlong Axes, Hlong StartIndices, Hlong EndIndices, Hlong Steps, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerSlice( const char* LayerName, Hlong Axes, Hlong StartIndices, Hlong EndIndices, Hlong Steps, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerSlice( const wchar_t* LayerName, Hlong Axes, Hlong StartIndices, Hlong EndIndices, Hlong Steps, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerSlice( string layerName, HTuple axes, HTuple startIndices, HTuple endIndices, HTuple steps, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerSlice( string layerName, int axes, int startIndices, int endIndices, int steps, string genParamName, string genParamValue )

DescriptionπŸ”—

The operator create_dl_layer_sliceCreateDlLayerSlice creates a slice layer that extracts a single slice of a tensor along specified axes, based on the provided start and end indices as well as the step size for the slicing operations. The handle of the slice layer is returned in DLLayerSliceDLLayerSlicedllayer_slice.

The parameter DLLayerInputDLLayerInputdllayer_input determines the feeding input layer and expects the layer handle as value.

The parameter LayerNamelayerNamelayer_name sets an individual layer name. Note that if creating a model using create_dl_modelCreateDlModel each layer of the created network must have a unique name.

The following parameters are used for the slice operation:

  • 'starts'"starts" Determines the starting indices of the slice operation along the axes specified in 'axes'"axes". This parameter is set using StartIndicesstartIndicesstart_indices.

  • 'ends'"ends" Determines the ending indices of the slice operation along the axes specified in 'axes'"axes". This parameter is set using EndIndicesendIndicesend_indices.

  • 'steps'"steps" Determines the step size for the slicing operation along the axes specified in 'axes'"axes". The parameter 'steps'"steps" must either be an empty tuple or have the same length as 'axes'"axes". If it is empty, the 'steps'"steps" are set to 11 for all 'axes'"axes". This parameter is set using Stepsstepssteps.

  • 'axes'"axes" Specifies the axes along which the slicing operation is performed. The axes are defined in the format WHC, representing Width, Height, and Channel and can also be specified as strings. Slicing in the Batch dimension is not supported. This parameter is set using Axesaxesaxes.

The slice layer allows slicing a tensor along specified axes, providing flexible adjustment options. To ensure correct operations 'starts'"starts" and 'ends'"ends" must have the same length as the parameter 'axes'"axes". Negative values in 'starts'"starts" and 'ends'"ends" are adjusted by adding the size of the corresponding array dimension, effectively allowing negative indexing for one iteration. After that, negative values are clamped to prevent further out-of-bounds slicing.

Negative values in 'axes'"axes" are adjusted by adding the total number of dimensions of the tensor to the respective axis. Negative value means counting dimensions from the back. The accepted range is [\(-r\), \(r-1\)] where \(r\) = rank. For slicing to the end of a dimension with unknown size, it is recommended to pass in H_INT_MAX when slicing forward and H_INT_MIN when slicing backward.

Handling of axes and indices

  • Adjusting axes Negative values in the 'axes'"axes" parameter are made non-negative by adding the rank of the input tensor \(r\) to each negative axis:

    \[\begin{eqnarray*} \textrm{axes}[i] \gets \textrm{axes}[i] + r \quad \textrm{if } \textrm{axes}[i] < 0 \end{eqnarray*}\]
  • Adjusting β€˜starts’ and β€˜ends’

    • Negative Index Adjustment Negative values in 'starts'"starts" and 'ends'"ends" are adjusted by adding the respective tensor dimension size:

      'starts'"starts"[\(i\)] is adjusted by adding the tensor dimension size.

      \[\begin{eqnarray*} \textrm{starts}[i] \gets \textrm{starts}[i] + \textrm{dims}[\textrm{axes}[i]] \quad \textrm{if } \textrm{starts}[i] < 0 \end{eqnarray*}\]

      'ends'"ends"[\(i\)] is adjusted by adding the respective tensor dimension size.

      \[\begin{eqnarray*} \textrm{ends}[i] \gets \textrm{ends}[i] + \textrm{dims}[\textrm{axes}[i]] \quad \textrm{if } \textrm{ends}[i] < 0 \end{eqnarray*}\]
    • Clamping β€˜starts’ Values Adjusted 'starts'"starts" values are clamped to the range:

      \[\begin{eqnarray*} \textrm{starts}[i] \in [0, \textrm{dims}[\textrm{axes}[i]]] \end{eqnarray*}\]
    • Clamping β€˜ends’ Values Adjusted 'ends'"ends" values are clamped based on the step direction:

      • Positive Stepping: 'ends'"ends" is clamped to the range [0, dims].

        \[\begin{eqnarray*} \textrm{if } \textrm{steps}[i] > 0: \, \textrm{ends}[i] \in [0, \textrm{dims}[\textrm{axes}[i]]] \end{eqnarray*}\]
      • Negative Stepping: 'ends'"ends" is clamped to the range [-1, dims - 1].

        \[\begin{eqnarray*} \textrm{if } \textrm{steps}[i] < 0: \, \textrm{ends}[i] \in [-1, \textrm{dims}[\textrm{axes}[i]] - 1] \end{eqnarray*}\]

The following generic parameters GenParamNamegenParamNamegen_param_name and the corresponding values GenParamValuegenParamValuegen_param_value are supported:

  • 'axes_format'"axes_format": Compatibility parameter that determines whether the specified Axesaxesaxes are given in WHCN format (default) or in NCHW format. The parameter changes how the specified axes are interpreted. For example, with axis 11 and 'axes_format'"axes_format" 'nchw'"nchw", slicing is performed along depth. If 'axes_format'"axes_format" is set to 'whcn'"whcn" or left unspecified, slicing is performed along height. Instead of indices, strings can also be used to specify the axes.

    List of values: 'nchw'"nchw", 'whcn'"whcn"

    Default: 'whcn'"whcn"

  • 'is_inference_output'"is_inference_output": Determines whether apply_dl_modelApplyDlModel will include the output of this layer in the dictionary DLResultBatchDLResultBatchdlresult_batch even without specifying this layer in Outputsoutputsoutputs ('true'"true") or not ('false'"false").

    List of values: 'true'"true", 'false'"false"

    Default: 'false'"false"

Certain parameters of layers created using this operator create_dl_layer_sliceCreateDlLayerSlice can be set and retrieved using further operators. The following tables give an overview, which parameters can be set using set_dl_model_layer_paramSetDlModelLayerParam and which ones can be retrieved using get_dl_model_layer_paramGetDlModelLayerParam or get_dl_layer_paramGetDlLayerParam. Note, the operators set_dl_model_layer_paramSetDlModelLayerParam and get_dl_model_layer_paramGetDlModelLayerParam require a model created by create_dl_modelCreateDlModel.

Layer Parameters set get
'input_layer'"input_layer" (DLLayerInputDLLayerInputdllayer_input) x
'name'"name" (LayerNamelayerNamelayer_name) x x
'axes'"axes" x
'starts'"starts" x
'ends'"ends" x
'steps'"steps" x
'output_layer'"output_layer" (DLLayerSliceDLLayerSlicedllayer_slice) x
'shape'"shape" x
'type'"type" x
Generic Layer Parameters set get
'is_inference_output'"is_inference_output" x x
'num_trainable_params'"num_trainable_params" x

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersπŸ”—

DLLayerInputDLLayerInputdllayer_input (input_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Feeding layer.

Default: 'DLLayerInput'"DLLayerInput"

LayerNamelayerNamelayer_name (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of the output layer.

Axesaxesaxes (input_control) number(-array) β†’ (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Axes used for slicing.

Default: 00
Suggested values: 0, 'width', 1, 'height', 2, 'depth'0, "width", 1, "height", 2, "depth"

StartIndicesstartIndicesstart_indices (input_control) number(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Starting indices of corresponding axes (inclusive).

Default: 00

EndIndicesendIndicesend_indices (input_control) number(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Ending indices of corresponding axes (exclusive).

Default: 11

Stepsstepssteps (input_control) number(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Slicing steps.

Default: [][]

GenParamNamegenParamNamegen_param_name (input_control) attribute.name(-array) β†’ (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Generic input parameter names.

Default: [][]
List of values: 'axes_format', 'is_inference_output'"axes_format", "is_inference_output"

GenParamValuegenParamValuegen_param_value (input_control) attribute.value(-array) β†’ (string / integer / real)HTuple (HString / Hlong / double)HTuple (string / int / long / double)MaybeSequence[Union[int, float, str]]Htuple (char* / Hlong / double)

Generic input parameter values.

Default: [][]
Suggested values: 'true', 'false', 'nchw', 'whcn'"true", "false", "nchw", "whcn"

DLLayerSliceDLLayerSlicedllayer_slice (output_control) dl_layer β†’ (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Output layer.

ModuleπŸ”—

Deep Learning Professional