class_docstr: The :class:`DeformableConv2d` class is a 2D
  `Deformable Convolutional Networks <https://arxiv.org/abs/1703.06211>`__.
  
  Parameters
  ----------
  offset_layer : tf.Tensor
      To predict the offset of convolution operations.
      The shape is (batchsize, input height, input width, 2*(number of element in the convolution kernel))
      e.g. if apply a 3*3 kernel, the number of the last dimension should be 18 (2*3*3)
  n_filter : int
      The number of filters.
  filter_size : tuple of int
      The filter size (height, width).
  act : activation function
      The activation function of this layer.
  padding : str
      The padding algorithm type: "SAME" or "VALID".
  W_init : initializer
      The initializer for the weight matrix.
  b_init : initializer or None
      The initializer for the bias vector. If None, skip biases.
  in_channels : int
      The number of in channels.
  name : str
      A unique layer name.
  
  Examples
  --------
  With TensorLayer
  
  >>> net = tl.layers.InputLayer([5, 10, 10, 16], name='input')
  >>> offset1 = tl.layers.Conv2d(
  ...     n_filter=18, filter_size=(3, 3), strides=(1, 1), padding='SAME', name='offset1'
  ... )(net)
  >>> deformconv1 = tl.layers.DeformableConv2d(
  ...     offset_layer=offset1, n_filter=32, filter_size=(3, 3), name='deformable1'
  ... )(net)
  >>> offset2 = tl.layers.Conv2d(
  ...     n_filter=18, filter_size=(3, 3), strides=(1, 1), padding='SAME', name='offset2'
  ... )(deformconv1)
  >>> deformconv2 = tl.layers.DeformableConv2d(
  ...     offset_layer=offset2, n_filter=64, filter_size=(3, 3), name='deformable2'
  ... )(deformconv1)
  
  References
  ----------
  - The deformation operation was adapted from the implementation in `here <https://github.com/kastnerkyle/deform-conv>`__
  
  Notes
  -----
  - The padding is fixed to 'SAME'.
  - The current implementation is not optimized for memory usgae. Please use it carefully.
class_docstr_tok: ["The",":","class",":","`","DeformableConv2d","`","class","is","a","2D","`","Deformable","Convolutional","Networks","<","https",":","\/\/arxiv.org\/abs\/1703.06211",">","`","__",".","Parameters","--","--","--","--","--","offset_layer",":","tf.Tensor","To","predict","the","offset","of","convolution","operations",".","The","shape","is","(","batchsize",",","input","height",",","input","width",",","2","*","(","number","of","element","in","the","convolution","kernel",")",")","e.g",".","if","apply","a","3","*","3","kernel",",","the","number","of","the","last","dimension","should","be","18","(","2","*","3","*","3",")","n_filter",":","int","The","number","of","filters",".","filter_size",":","tuple","of","int","The","filter","size","(","height",",","width",")",".","act",":","activation","function","The","activation","function","of","this","layer",".","padding",":","str","The","padding","algorithm","type",":","``","SAME","''","or","``","VALID","''",".","W_init",":","initializer","The","initializer","for","the","weight","matrix",".","b_init",":","initializer","or","None","The","initializer","for","the","bias","vector",".","If","None",",","skip","biases",".","in_channels",":","int","The","number","of","in","channels",".","name",":","str","A","unique","layer","name",".","Examples","--","--","--","--","With","TensorLayer",">",">",">","net","=","tl.layers.InputLayer","(","[","5",",","10",",","10",",","16","]",",","name='input","'",")",">",">",">","offset1","=","tl.layers.Conv2d","(","...","n_filter=18",",","filter_size=","(","3",",","3",")",",","strides=","(","1",",","1",")",",","padding='SAME","'",",","name='offset1'","...",")","(","net",")",">",">",">","deformconv1","=","tl.layers.DeformableConv2d","(","...","offset_layer=offset1",",","n_filter=32",",","filter_size=","(","3",",","3",")",",","name='deformable1'","...",")","(","net",")",">",">",">","offset2","=","tl.layers.Conv2d","(","...","n_filter=18",",","filter_size=","(","3",",","3",")",",","strides=","(","1",",","1",")",",","padding='SAME","'",",","name='offset2'","...",")","(","deformconv1",")",">",">",">","deformconv2","=","tl.layers.DeformableConv2d","(","...","offset_layer=offset2",",","n_filter=64",",","filter_size=","(","3",",","3",")",",","name='deformable2'","...",")","(","deformconv1",")","References","--","--","--","--","--","-","The","deformation","operation","was","adapted","from","the","implementation","in","`","here","<","https",":","\/\/github.com\/kastnerkyle\/deform-conv",">","`","__","Notes","--","--","-","-","The","padding","is","fixed","to","'SAME","'",".","-","The","current","implementation","is","not","optimized","for","memory","usgae",".","Please","use","it","carefully","."]
code: def build(self, inputs_shape):
      self.in_channels = inputs_shape[-1]
  
      self.input_h = int(inputs_shape[1])
      self.input_w = int(inputs_shape[2])
      initial_offsets = tf.stack(
          tf.meshgrid(
              tf.range(self.filter_size[0]),
              tf.range(self.filter_size[1]),
              indexing="ij",
          )
      )  # initial_offsets --> (kh, kw, 2)
      initial_offsets = tf.reshape(
          initial_offsets, (-1, 2)
      )  # initial_offsets --> (n, 2)
      initial_offsets = tf.expand_dims(
          initial_offsets, 0
      )  # initial_offsets --> (1, n, 2)
      initial_offsets = tf.expand_dims(
          initial_offsets, 0
      )  # initial_offsets --> (1, 1, n, 2)
      initial_offsets = tf.tile(
          initial_offsets, [self.input_h, self.input_w, 1, 1]
      )  # initial_offsets --> (h, w, n, 2)
      initial_offsets = tf.cast(initial_offsets, "float32")
      grid = tf.meshgrid(
          tf.range(
              -int((self.filter_size[0] - 1) / 2.0),
              int(self.input_h - int((self.filter_size[0] - 1) / 2.0)),
              1,
          ),
          tf.range(
              -int((self.filter_size[1] - 1) / 2.0),
              int(self.input_w - int((self.filter_size[1] - 1) / 2.0)),
              1,
          ),
          indexing="ij",
      )
  
      grid = tf.stack(grid, axis=-1)
      grid = tf.cast(grid, "float32")  # grid --> (h, w, 2)
      grid = tf.expand_dims(grid, 2)  # grid --> (h, w, 1, 2)
      grid = tf.tile(
          grid, [1, 1, self.kernel_n, 1]
      )  # grid --> (h, w, n, 2)
      self.grid_offset = (
          grid + initial_offsets
      )  # grid_offset --> (h, w, n, 2)
  
      self.filter_shape = (
          1,
          1,
          self.kernel_n,
          self.in_channels,
          self.n_filter,
      )
  
      self.W = self._get_weights(
          "W_deformableconv2d",
          shape=self.filter_shape,
          init=self.W_init,
      )
  
      if self.b_init:
          self.b = self._get_weights(
              "b_deformableconv2d",
              shape=(self.n_filter,),
              init=self.b_init,
          )
  
file_path: TensorLayer/tensorlayer/layers/convolution/deformable_conv.py
imports: import tensorflow
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.decorators import deprecated_alias, private_method
  from tensorlayer.layers.core import Layer
label_desc: Use image node_id 3 for calling the DeformableConv2d obj's underlying member method code with example usage: obj.build(inputs_shape) without return types