class_docstr: Non-local block
  
  Parameters
  ----------
  in_channels : int.
      Input channels of each block.
  nonlocal_type : str.
      Types of design for non-local block.
  dim : int, default 3.
      2D or 3D non-local block.
  embed_dim : int.
      Intermediate number of channels.
  sub_sample : bool.
      Whether to downsample the feature map to save computation.
  use_bn : bool.
      Whether to use batch normalization layer inside a non-local block.
  norm_layer : object
      Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
      Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
  norm_kwargs : dict
      Additional `norm_layer` arguments, for example `num_devices=4`
      for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
  ctx : Context, default CPU.
      The context in which to load the pretrained weights.
code: def __init__(
      self,
      in_channels=1024,
      nonlocal_type="gaussian",
      dim=3,
      embed=True,
      embed_dim=None,
      sub_sample=False,
      use_bn=True,
      norm_layer=BatchNorm,
      norm_kwargs=None,
      ctx=None,
      **kwargs,
  ):
      super(NonLocal, self).__init__()
  
      assert nonlocal_type in ["gaussian", "dot", "concat"]
      self.nonlocal_type = nonlocal_type
      self.embed = embed
      self.embed_dim = (
          embed_dim if embed_dim is not None else in_channels // 2
      )
      self.sub_sample = sub_sample
      self.use_bn = use_bn
  
      with self.name_scope():
          if self.embed:
              if dim == 2:
                  self.theta = nn.Conv2D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1),
                      strides=(1, 1),
                      padding=(0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
                  self.phi = nn.Conv2D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1),
                      strides=(1, 1),
                      padding=(0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
                  self.g = nn.Conv2D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1),
                      strides=(1, 1),
                      padding=(0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
              elif dim == 3:
                  self.theta = nn.Conv3D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1, 1),
                      strides=(1, 1, 1),
                      padding=(0, 0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
                  self.phi = nn.Conv3D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1, 1),
                      strides=(1, 1, 1),
                      padding=(0, 0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
                  self.g = nn.Conv3D(
                      in_channels=in_channels,
                      channels=self.embed_dim,
                      kernel_size=(1, 1, 1),
                      strides=(1, 1, 1),
                      padding=(0, 0, 0),
                      weight_initializer=init.MSRAPrelu(),
                  )
  
          if self.nonlocal_type == "concat":
              if dim == 2:
                  self.concat_proj = nn.HybridSequential()
                  self.concat_proj.add(
                      nn.Conv2D(
                          in_channels=self.embed_dim * 2,
                          channels=1,
                          kernel_size=(1, 1),
                          strides=(1, 1),
                          padding=(0, 0),
                          weight_initializer=init.MSRAPrelu(),
                      )
                  )
                  self.concat_proj.add(nn.Activation("relu"))
              elif dim == 3:
                  self.concat_proj = nn.HybridSequential()
                  self.concat_proj.add(
                      nn.Conv3D(
                          in_channels=self.embed_dim * 2,
                          channels=1,
                          kernel_size=(1, 1, 1),
                          strides=(1, 1, 1),
                          padding=(0, 0, 0),
                          weight_initializer=init.MSRAPrelu(),
                      )
                  )
                  self.concat_proj.add(nn.Activation("relu"))
  
          if sub_sample:
              if dim == 2:
                  self.max_pool = nn.MaxPool2D(pool_size=(2, 2))
              elif dim == 3:
                  self.max_pool = nn.MaxPool3D(pool_size=(1, 2, 2))
              self.sub_phi = nn.HybridSequential()
              self.sub_phi.add(self.phi)
              self.sub_phi.add(self.max_pool)
              self.sub_g = nn.HybridSequential()
              self.sub_g.add(self.g)
              self.sub_g.add(self.max_pool)
  
          if dim == 2:
              self.W = nn.Conv2D(
                  in_channels=self.embed_dim,
                  channels=in_channels,
                  kernel_size=(1, 1),
                  strides=(1, 1),
                  padding=(0, 0),
                  weight_initializer=init.MSRAPrelu(),
              )
          elif dim == 3:
              self.W = nn.Conv3D(
                  in_channels=self.embed_dim,
                  channels=in_channels,
                  kernel_size=(1, 1, 1),
                  strides=(1, 1, 1),
                  padding=(0, 0, 0),
                  weight_initializer=init.MSRAPrelu(),
              )
  
          if use_bn:
              self.bn = norm_layer(
                  in_channels=in_channels,
                  gamma_initializer="zeros",
                  **({} if norm_kwargs is None else norm_kwargs),
              )
              self.W_bn = nn.HybridSequential()
              self.W_bn.add(self.W)
              self.W_bn.add(self.bn)
  
file_path: gluon-cv/gluoncv/model_zoo/action_recognition/non_local.py
imports: from mxnet.gluon.block import HybridBlock
  from mxnet import init
  from mxnet.gluon import nn
  from mxnet.gluon.nn import BatchNorm
label_desc: Use image node_id 1 to create a new NonLocal object from inherited base classes: HybridBlock with example: obj = NonLocal(in_channels, nonlocal_type, dim, embed, embed_dim, sub_sample, use_bn, norm_layer, norm_kwargs, ctx)