class_docstr: The :class:`SpatialTransformer2dAffine` class is a 2D `Spatial Transformer Layer <https://arxiv.org/abs/1506.02025>`__ for
  `2D Affine Transformation <https://en.wikipedia.org/wiki/Affine_transformation>`__.
  
  Parameters
  -----------
  out_size : tuple of int or None
      - The size of the output of the network (height, width), the feature maps will be resized by this.
  in_channels : int
      The number of in channels.
  data_format : str
      "channel_last" (NHWC, default) or "channels_first" (NCHW).
  name : str
      - A unique layer name.
  
  References
  -----------
  - `Spatial Transformer Networks <https://arxiv.org/abs/1506.02025>`__
  - `TensorFlow/Models <https://github.com/tensorflow/models/tree/master/transformer>`__
class_docstr_tok: ["The",":","class",":","`","SpatialTransformer2dAffine","`","class","is","a","2D","`","Spatial","Transformer","Layer","<","https",":","\/\/arxiv.org\/abs\/1506.02025",">","`","__","for","`","2D","Affine","Transformation","<","https",":","\/\/en.wikipedia.org\/wiki\/Affine_transformation",">","`","__",".","Parameters","--","--","--","--","--","-","out_size",":","tuple","of","int","or","None","-","The","size","of","the","output","of","the","network","(","height",",","width",")",",","the","feature","maps","will","be","resized","by","this",".","in_channels",":","int","The","number","of","in","channels",".","data_format",":","str","``","channel_last","''","(","NHWC",",","default",")","or","``","channels_first","''","(","NCHW",")",".","name",":","str","-","A","unique","layer","name",".","References","--","--","--","--","--","-","-","`","Spatial","Transformer","Networks","<","https",":","\/\/arxiv.org\/abs\/1506.02025",">","`","__","-","`","TensorFlow\/Models","<","https",":","\/\/github.com\/tensorflow\/models\/tree\/master\/transformer",">","`","__"]
docstr: :param inputs: a tuple (theta_input, U).
              - theta_input is of size [batch, in_channels]. We will use a :class:`Dense` to
              make the theta size to [batch, 6], value range to [0, 1] (via tanh).
              - U is the previous layer, which the affine transformation is applied to.
  :return: tensor of size [batch, out_size[0], out_size[1], n_channels] after affine transformation,
              n_channels is identical to that of U.
docstr_tok: [":","param","inputs",":","a","tuple","(","theta_input",",","U",")",".","-","theta_input","is","of","size","[","batch",",","in_channels","]",".","We","will","use","a",":","class",":","`","Dense","`","to","make","the","theta","size","to","[","batch",",","6","]",",","value","range","to","[","0",",","1","]","(","via","tanh",")",".","-","U","is","the","previous","layer",",","which","the","affine","transformation","is","applied","to",".",":","return",":","tensor","of","size","[","batch",",","out_size","[","0","]",",","out_size","[","1","]",",","n_channels","]","after","affine","transformation",",","n_channels","is","identical","to","that","of","U","."]
code: def forward(self, inputs):
      """
      :param inputs: a tuple (theta_input, U).
                  - theta_input is of size [batch, in_channels]. We will use a :class:`Dense` to
                  make the theta size to [batch, 6], value range to [0, 1] (via tanh).
                  - U is the previous layer, which the affine transformation is applied to.
      :return: tensor of size [batch, out_size[0], out_size[1], n_channels] after affine transformation,
                  n_channels is identical to that of U.
      """
      theta_input, U = inputs
      theta = tf.nn.tanh(tf.matmul(theta_input, self.W) + self.b)
      outputs = transformer(U, theta, out_size=self.out_size)
      # automatically set batch_size and channels
      # e.g. [?, 40, 40, ?] --> [64, 40, 40, 1] or [64, 20, 20, 4]
      batch_size = theta_input.shape[0]
      n_channels = U.shape[-1]
      if self.data_format == "channel_last":
          outputs = tf.reshape(
              outputs,
              shape=[
                  batch_size,
                  self.out_size[0],
                  self.out_size[1],
                  n_channels,
              ],
          )
      else:
          raise Exception(
              "unimplement data_format {}".format(self.data_format)
          )
      return outputs
  
file_path: TensorLayer/tensorlayer/layers/spatial_transformer.py
imports: import numpy
  import tensorflow
  from six.moves import xrange
  from tensorflow.python.ops import array_ops
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.decorators import deprecated_alias
  from tensorlayer.layers.core import Layer
  from tensorlayer.layers.utils import flatten_reshape
label_desc: Use image node_id 4 for calling the SpatialTransformer2dAffine obj's underlying member method code with example usage: obj.forward(inputs) and returns: outputs