Skip to content

create_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sampleT_create_dl_layer_grid_sampleπŸ”—

Short descriptionπŸ”—

create_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sampleT_create_dl_layer_grid_sample β€” Create a grid sample layer.

SignatureπŸ”—

create_dl_layer_grid_sample( dl_layer DLLayerInput, dl_layer DLLayerGrid, string LayerName, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerGridSample )void CreateDlLayerGridSample( const HTuple& DLLayerInput, const HTuple& DLLayerGrid, const HTuple& LayerName, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerGridSample )static void HOperatorSet.CreateDlLayerGridSample( HTuple DLLayerInput, HTuple DLLayerGrid, HTuple layerName, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerGridSample )def create_dl_layer_grid_sample( dllayer_input: HHandle, dllayer_grid: HHandle, layer_name: str, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandle

Herror T_create_dl_layer_grid_sample( const Htuple DLLayerInput, const Htuple DLLayerGrid, const Htuple LayerName, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerGridSample )

HDlLayer HDlLayer::CreateDlLayerGridSample( const HDlLayer& DLLayerGrid, const HString& LayerName, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerGridSample( const HDlLayer& DLLayerGrid, const HString& LayerName, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerGridSample( const HDlLayer& DLLayerGrid, const char* LayerName, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerGridSample( const HDlLayer& DLLayerGrid, const wchar_t* LayerName, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerGridSample( HDlLayer DLLayerGrid, string layerName, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerGridSample( HDlLayer DLLayerGrid, string layerName, string genParamName, string genParamValue )

DescriptionπŸ”—

The operator create_dl_layer_grid_sampleCreateDlLayerGridSample creates a grid sample layer, which applies a spatial transformation to an input image or feature map. The handle of the created grid sample layer is returned in DLLayerGridSampleDLLayerGridSampledllayer_grid_sample.

A grid sample layer warps the input DLLayerInputDLLayerInputdllayer_input based on a sampling grid DLLayerGridDLLayerGriddllayer_grid. This grid needs to specify spatially normalized input pixel locations which are then used to interpolate the output values. Pixel locations inside the input image or feature map must have values in the range of \([-1, 1]\). Thus, the values \(x=-1\), \(y=-1\) must correspond to the top-left pixel, while \(x=1\), \(y=1\) describe the bottom-right pixel. Thereby, the extrema refer to the center points of the corner pixels. The grid sample layer internally sets β€˜align_corners’ to 11, defining the pixel centers as the grid reference points. The sampling grid DLLayerGridDLLayerGriddllayer_grid can be generated using create_dl_layer_affine_gridCreateDlLayerAffineGrid.

The grid sample layer uses bilinear interpolation to compute output values, ensuring smooth transitions between pixel values. For sampling grid locations outside of the input image or feature map the corresponding values are set to 0. The output of the grid sample layer has the same spatial dimensions as the input grid.

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 generic parameters GenParamNamegenParamNamegen_param_name and the corresponding values GenParamValuegenParamValuegen_param_value are supported:

  • '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_grid_sampleCreateDlLayerGridSample 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, DLLayerGridDLLayerGriddllayer_grid) x
'name'"name" (LayerNamelayerNamelayer_name) x x
'output_layer'"output_layer" (DLLayerGridSampleDLLayerGridSampledllayer_grid_sample) 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)

Input layer for image or feature map.

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

Input layer defining the sampling grid.

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

Name of the output layer.

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: 'is_inference_output'"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'"true", "false"

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

Grid sample layer.

ExampleπŸ”—

(HDevelop)

read_image (Image, 'printer_chip/printer_chip_01')
convert_image_type (Image, Image, 'real')
get_image_size (Image, Width, Height)
* Create input layer for the image to be transformed.
create_dl_layer_input ('image', [Width,Height,1], [], [], DLLayerInputImage)
*
* Create an affine grid layer and define the size of its output grid with (Width/2, Height/2), which later
* determines the output image size.
create_dl_layer_input ('transformation', [3,2,1], [], [], DLLayerInputTransformation)
create_dl_layer_affine_grid (DLLayerInputTransformation, 'affine_grid', Width/2, Height/2, [], [], DLLayerAffineGrid)
*
* Create an affine transformation which represents a translation
* to the right by half the image width.
* As the affine grid layer uses normalized pixel positions in
* the range of [-1,1] the translation value must be normalized
* as well. Hence, translating by half the image width to the right
* corresponds to a translation value of -1 in x-direction.
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, -1, 0, HomMat2DTranslate)
*
* Create grid sample layer with the affine grid as input
create_dl_layer_grid_sample (DLLayerInputImage, DLLayerAffineGrid, 'output', [], [], DLLayerGridSample)
*
* Create and apply dl model
create_dl_model (DLLayerGridSample, DLModelHandle)
DLSample := dict{image: Image, transformation: HomMat2DTranslate}
apply_dl_model (DLModelHandle, DLSample, [], DLResultBatch)
get_dict_object (ImageTranslated, DLResultBatch, 'output')

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

create_dl_layer_affine_gridCreateDlLayerAffineGrid

ModuleπŸ”—

Deep Learning Professional