AffineGrid

Description

Generates a 2D or 3D flow field (sampling grid), given a batch of affine matrices theta (https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html).

 

Documentation illustration (illustration unavailable in the archive).

 

An affine matrix theta is applied to a position tensor represented in its homogeneous expression. Here is an example in 3D :

[r00, r01, r02, t0]   [x]   [x']
[r10, r11, r12, t1] * [y] = [y']
[r20, r21, r22, t2]   [z]   [z']
[0,   0,   0,   1 ]   [1]   [1 ]

where (x, y, z) is the position in the original space, (x', y', z') is the position in the output space. The last row is always [0, 0, 0, 1] and is not stored in the affine matrix. Therefore we have theta of shape (N, 2, 3) for 2D or (N, 3, 4) for 3D.

Input size is used to define grid of positions evenly spaced in the original 2D or 3D space, with dimensions ranging from -1 to 1. The output grid contains positions in the output space.

When align_corners=1, consider -1 and 1 to refer to the centers of the corner pixels (mark v in illustration).

v            v            v            v
|-------------------|------------------|
-1                  0                  1

When align_corners=0, consider -1 and 1 to refer to the outer edge of the corner pixels.

    v        v         v         v
|------------------|-------------------|
-1                 0                   1

Input parameters

 

specified_outputs_name : array, this parameter lets you manually assign custom names to the output tensors of a node.

 Graphs in : cluster, ONNX model architecture.

theta (heterogeneous) – T1 : object, input batch of affine matrices with shape (N, 2, 3) for 2D or (N, 3, 4) for 3D.
size (heterogeneous) – T2 : object, the target output image size (N, C, H, W) for 2D or (N, C, D, H, W) for 3D.

Documentation illustration (illustration unavailable in the archive).

 Parameters : cluster,

align_corners : boolean, if align_corners = 1, consider -1 and 1 to refer to the centers of the corner pixels. if align_corners=0, consider -1 and 1 to refer to the outer edge the corner pixels.
Default value “False”.
 training? : boolean, whether the layer is in training mode (can store data for backward).
Default value “True”.
 lda coeff : float, defines the coefficient by which the loss derivative will be multiplied before being sent to the previous layer (since during the backward run we go backwards).
Default value “1”.

 name (optional) : string, name of the node.

Documentation illustration (illustration unavailable in the archive).

Output parameters

 

grid (heterogeneous) – T1 : object, output tensor of shape (N, H, W, 2) of 2D sample coordinates or (N, D, H, W, 3) of 3D sample coordinates.

Type Constraints

T1 in (tensor(bfloat16), tensor(double), tensor(float), tensor(float16)) : Constrain grid types to float tensors.

T2 in (tensor(int64)) : Constrain size’s type to int64 tensors.

 

Example

All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install Deep Learning library to run it).