Skip to content

create_dl_layer_affine_gridCreateDlLayerAffineGridCreateDlLayerAffineGridcreate_dl_layer_affine_gridT_create_dl_layer_affine_grid🔗

Short description🔗

create_dl_layer_affine_gridCreateDlLayerAffineGridCreateDlLayerAffineGridcreate_dl_layer_affine_gridT_create_dl_layer_affine_grid — Create an affine grid layer.

Signature🔗

create_dl_layer_affine_grid( dl_layer DLLayerInput, string LayerName, number Width, number Height, attribute.name GenParamName, attribute.value GenParamValue, out dl_layer DLLayerAffineGrid )void CreateDlLayerAffineGrid( const HTuple& DLLayerInput, const HTuple& LayerName, const HTuple& Width, const HTuple& Height, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DLLayerAffineGrid )static void HOperatorSet.CreateDlLayerAffineGrid( HTuple DLLayerInput, HTuple layerName, HTuple width, HTuple height, HTuple genParamName, HTuple genParamValue, out HTuple DLLayerAffineGrid )def create_dl_layer_affine_grid( dllayer_input: HHandle, layer_name: str, width: int, height: int, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandle

Herror T_create_dl_layer_affine_grid( const Htuple DLLayerInput, const Htuple LayerName, const Htuple Width, const Htuple Height, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DLLayerAffineGrid )

HDlLayer HDlLayer::CreateDlLayerAffineGrid( const HString& LayerName, Hlong Width, Hlong Height, const HTuple& GenParamName, const HTuple& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAffineGrid( const HString& LayerName, Hlong Width, Hlong Height, const HString& GenParamName, const HString& GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAffineGrid( const char* LayerName, Hlong Width, Hlong Height, const char* GenParamName, const char* GenParamValue ) const

HDlLayer HDlLayer::CreateDlLayerAffineGrid( const wchar_t* LayerName, Hlong Width, Hlong Height, const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

HDlLayer HDlLayer.CreateDlLayerAffineGrid( string layerName, int width, int height, HTuple genParamName, HTuple genParamValue )

HDlLayer HDlLayer.CreateDlLayerAffineGrid( string layerName, int width, int height, string genParamName, string genParamValue )

Description🔗

The operator create_dl_layer_affine_gridCreateDlLayerAffineGrid creates an affine grid layer which returns a 2D sampling grid parameterized by an affine transformation matrix. The handle of the affine grid layer is returned in DLLayerAffineGridDLLayerAffineGriddllayer_affine_grid. Usually, sampling grids are fed into grid sample layers to apply affine transformations to images or feature maps, see create_dl_layer_grid_sampleCreateDlLayerGridSample.

The parameter DLLayerInputDLLayerInputdllayer_input determines the feeding input layer and expects the layer handle as value. The input consists of a batch of 2D affine transformation matrices (Height = 2, Width = 3). They are passed in the format WHC, representing Width, Height, and Channel, where Channel must always be 1. See affine_trans_image_sizeAffineTransImageSize for more information about affine transformations.

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 parameters Widthwidthwidth and Heightheightheight define the output size. Given a batch of N affine transformation input matrices, the affine grid layer returns a batch of sampling grids of dimension (Heightheightheight, Widthwidthwidth, 2) in the format CHW representing Channel, Height, and Width.

For an affine transformation matrix \(\mvMatrix{a & b & c \\ d & e & f}\) a point \((x,y)\) in an image of size (Widthwidthwidth, Heightheightheight) is mapped to \((x',y')\) by

\[\begin{eqnarray*} \mvHomVectorTwoD{x'}{y'} = \mvHomMatrixTwoDElements{a & b & c \\ d & e & f} \cdot \mvHomVectorTwoD{x}{y} \end{eqnarray*}\]

where \(x\) refers to the column coordinate and \(y\) to the row coordinate. Hence, for the affine input matrix of a batch (\(b\)), the output tensor values \((b, y, x, 0)\) and \((b, y, x, 1)\) corresponds to the column and row values \(x'\) and \(y'\) of the point \((x,y)\) after transformation.

The sampling grid locations \((x,y)\) are normalized by the spatial dimensions Widthwidthwidth and Heightheightheight to get values in the range of \([-1, 1]\). Thus, the values \(x=-1\), \(y=-1\) 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 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_affine_gridCreateDlLayerAffineGrid 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
'grid_size'"grid_size" (Widthwidthwidth, Heightheightheight) x
'output_layer'"output_layer" (DLLayerAffineGridDLLayerAffineGriddllayer_affine_grid) 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 a batch of affine transformation matrices of shape [3,2,1].

LayerNamelayerNamelayer_name (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of the output layer.

Widthwidthwidth (input_control) number → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Width of the returned grid.

Default: 256256

Heightheightheight (input_control) number → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Height of the returned grid.

Default: 256256

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"

DLLayerAffineGridDLLayerAffineGriddllayer_affine_grid (output_control) dl_layer → (handle)HTuple (HHandle)HDlLayer, HTuple (IntPtr)HHandleHtuple (handle)

Affine grid layer.

Example🔗

(HDevelop)

* Create affine grid layer for images of size (3,5).
create_dl_layer_input ('input', [3,2,1], [], [], DLLayerInput)
create_dl_layer_affine_grid (DLLayerInput, 'affine_grid', 5, 3, ['is_inference_output'], ['true'], DLLayerAffineGrid)
*
* Create an affine transformation which represents a translation
* to the right by one pixel.
* As the affine grid layer uses normalized pixel positions in
* the range of [-1,1] the translation value must be normalized
* as well. For Width = 5 the normalized column values are
* [-1, -0.5, 0.0, 0.5, 1.0]. Hence, translating by one pixel
* to the right corresponds to a translation value of 0.5 in
* x-direction.
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, 0.5, 0, HomMat2DTranslate)
*
* For better visualization add permutation layer to get an
* output image of size (3,5) where the first channel describes
* the transformed (normalized) column coordinates and the second
* channel describes the transformed (normalized) row coordinates.
create_dl_layer_permutation (DLLayerAffineGrid, 'permute', ['height','depth','width','batch'], [], [], DLLayerPermutation)
*
* Create and apply dl model
create_dl_model (DLLayerPermutation, DLModelHandle)
DLSample := dict{input: HomMat2DTranslate}
apply_dl_model (DLModelHandle, DLSample, [], DLResultBatch)

Combinations with other operators🔗

Combinations

Possible predecessors

create_dl_layer_inputCreateDlLayerInput

Possible successors

create_dl_layer_grid_sampleCreateDlLayerGridSample, create_dl_layer_permutationCreateDlLayerPermutation

See also

affine_trans_image_sizeAffineTransImageSize

Module🔗

Deep Learning Professional