Operator Reference

create_dl_layer_grid_sampleT_create_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sample (Operator)

create_dl_layer_grid_sampleT_create_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sample — Create a grid sample layer.

Signature

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

void CreateDlLayerGridSample(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)

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

Description

The operator create_dl_layer_grid_samplecreate_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sample 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 DLLayerGridSampleDLLayerGridSampleDLLayerGridSampleDLLayerGridSampledllayer_grid_sample.

A grid sample layer warps the input DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input based on a sampling grid DLLayerGridDLLayerGridDLLayerGridDLLayerGriddllayer_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 . Thus, the values , must correspond to the top-left pixel, while , 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 1, defining the pixel centers as the grid reference points. The sampling grid DLLayerGridDLLayerGridDLLayerGridDLLayerGriddllayer_grid can be generated using create_dl_layer_affine_gridcreate_dl_layer_affine_gridCreateDlLayerAffineGridCreateDlLayerAffineGridcreate_dl_layer_affine_grid.

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 LayerNameLayerNameLayerNamelayerNamelayer_name sets an individual layer name. Note that if creating a model using create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelcreate_dl_model each layer of the created network must have a unique name.

The following generic parameters GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name and the corresponding values GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value are supported:

'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output":

Determines whether apply_dl_modelapply_dl_modelApplyDlModelApplyDlModelapply_dl_model will include the output of this layer in the dictionary DLResultBatchDLResultBatchDLResultBatchDLResultBatchdlresult_batch even without specifying this layer in OutputsOutputsOutputsoutputsoutputs ('true'"true""true""true""true") or not ('false'"false""false""false""false").

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

Default: 'false'"false""false""false""false"

Certain parameters of layers created using this operator create_dl_layer_grid_samplecreate_dl_layer_grid_sampleCreateDlLayerGridSampleCreateDlLayerGridSamplecreate_dl_layer_grid_sample can be set and retrieved using further operators. The following tables give an overview, which parameters can be set using set_dl_model_layer_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and which ones can be retrieved using get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param or get_dl_layer_paramget_dl_layer_paramGetDlLayerParamGetDlLayerParamget_dl_layer_param. Note, the operators set_dl_model_layer_paramset_dl_model_layer_paramSetDlModelLayerParamSetDlModelLayerParamset_dl_model_layer_param and get_dl_model_layer_paramget_dl_model_layer_paramGetDlModelLayerParamGetDlModelLayerParamget_dl_model_layer_param require a model created by create_dl_modelcreate_dl_modelCreateDlModelCreateDlModelcreate_dl_model.

Layer Parameters set get
'input_layer'"input_layer""input_layer""input_layer""input_layer" (DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input, DLLayerGridDLLayerGridDLLayerGridDLLayerGriddllayer_grid) x
'name'"name""name""name""name" (LayerNameLayerNameLayerNamelayerNamelayer_name) x x
'output_layer'"output_layer""output_layer""output_layer""output_layer" (DLLayerGridSampleDLLayerGridSampleDLLayerGridSampleDLLayerGridSampledllayer_grid_sample) x
'shape'"shape""shape""shape""shape" x
'type'"type""type""type""type" x
Generic Layer Parameters set get
'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output" x x
'num_trainable_params'"num_trainable_params""num_trainable_params""num_trainable_params""num_trainable_params" x

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

DLLayerInputDLLayerInputDLLayerInputDLLayerInputdllayer_input (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Input layer for image or feature map.

DLLayerGridDLLayerGridDLLayerGridDLLayerGriddllayer_grid (input_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Input layer defining the sampling grid.

LayerNameLayerNameLayerNamelayerNamelayer_name (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Name of the output layer.

GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (input_control)  attribute.name(-array) HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Generic input parameter names.

Default: []

List of values: 'is_inference_output'"is_inference_output""is_inference_output""is_inference_output""is_inference_output"

GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (input_control)  attribute.value(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Generic input parameter values.

Default: []

Suggested values: 'true'"true""true""true""true", 'false'"false""false""false""false"

DLLayerGridSampleDLLayerGridSampleDLLayerGridSampleDLLayerGridSampledllayer_grid_sample (output_control)  dl_layer HDlLayer, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (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')

Possible Predecessors

create_dl_layer_affine_gridcreate_dl_layer_affine_gridCreateDlLayerAffineGridCreateDlLayerAffineGridcreate_dl_layer_affine_grid

Module

Deep Learning Professional