class_docstr: Non-local module from Non-local Neural Networks
  CVPR 2018, https://arxiv.org/abs/1711.07971
  
  Args:
      in_channels (int): Channels of the input feature map.
      nonlocal_type (str): Types of design for non-local block,
                           such as 'gaussian', 'dot' and 'concat'.
      dim (int): 2D or 3D non-local block..
      embed_dim (int): Channels of the intermediate feature map,
                       usually are half of the in_channels.
      sub_sample (bool): Default: False. Whether to apply max pooling after pairwise
                         function (Note that the `sub_sample` is applied on spatial only).
      use_bn (bool): Default: True. Whether to use a batch normalization layer
                     inside a non-local block.
class_docstr_tok: ["Non-local","module","from","Non-local","Neural","Networks","CVPR","2018",",","https",":","\/\/arxiv.org\/abs\/1711.07971","Args",":","in_channels","(","int",")",":","Channels","of","the","input","feature","map",".","nonlocal_type","(","str",")",":","Types","of","design","for","non-local","block",",","such","as","'gaussian","'",",","'dot","'","and","'concat","'",".","dim","(","int",")",":","2D","or","3D","non-local","block","..","embed_dim","(","int",")",":","Channels","of","the","intermediate","feature","map",",","usually","are","half","of","the","in_channels",".","sub_sample","(","bool",")",":","Default",":","False",".","Whether","to","apply","max","pooling","after","pairwise","function","(","Note","that","the","`","sub_sample","`","is","applied","on","spatial","only",")",".","use_bn","(","bool",")",":","Default",":","True",".","Whether","to","use","a","batch","normalization","layer","inside","a","non-local","block","."]
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=BatchNorm3d,
      norm_kwargs=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
  
      if self.embed:
          if dim == 2:
              self.theta = nn.Conv2d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1),
                  stride=(1, 1),
                  padding=(0, 0),
              )
              self.phi = nn.Conv2d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1),
                  stride=(1, 1),
                  padding=(0, 0),
              )
              self.g = nn.Conv2d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1),
                  stride=(1, 1),
                  padding=(0, 0),
              )
          elif dim == 3:
              self.theta = nn.Conv3d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1, 1),
                  stride=(1, 1, 1),
                  padding=(0, 0, 0),
              )
              self.phi = nn.Conv3d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1, 1),
                  stride=(1, 1, 1),
                  padding=(0, 0, 0),
              )
              self.g = nn.Conv3d(
                  in_channels=in_channels,
                  out_channels=self.embed_dim,
                  kernel_size=(1, 1, 1),
                  stride=(1, 1, 1),
                  padding=(0, 0, 0),
              )
  
      if self.nonlocal_type == "concat":
          if dim == 2:
              self.concat_proj = nn.Sequential(
                  nn.Conv2d(
                      in_channels=self.embed_dim * 2,
                      out_channels=1,
                      kernel_size=(1, 1),
                      stride=(1, 1),
                      padding=(0, 0),
                  ),
                  nn.ReLU(inplace=True),
              )
          elif dim == 3:
              self.concat_proj = nn.Sequential(
                  nn.Conv3d(
                      in_channels=self.embed_dim * 2,
                      out_channels=1,
                      kernel_size=(1, 1, 1),
                      stride=(1, 1, 1),
                      padding=(0, 0, 0),
                  ),
                  nn.ReLU(inplace=True),
              )
  
      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.Sequential(self.phi, self.max_pool)
          self.sub_g = nn.Sequential(self.g, self.max_pool)
  
      if dim == 2:
          self.W = nn.Conv2d(
              in_channels=self.embed_dim,
              out_channels=in_channels,
              kernel_size=(1, 1),
              stride=(1, 1),
              padding=(0, 0),
          )
      elif dim == 3:
          self.W = nn.Conv3d(
              in_channels=self.embed_dim,
              out_channels=in_channels,
              kernel_size=(1, 1, 1),
              stride=(1, 1, 1),
              padding=(0, 0, 0),
          )
  
      if self.use_bn:
          self.bn = norm_layer(
              num_features=in_channels,
              momentum=0.9,
              **({} if norm_kwargs is None else norm_kwargs),
          )
          self.W_bn = nn.Sequential(self.W, self.bn)
  
      self.init_weights()
  
file_path: gluon-cv/gluoncv/torch/model_zoo/action_recognition/non_local.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn import BatchNorm3d
  from ...utils.utils import constant_init, normal_init
label_desc: Use image node_id 1 to create a new NonLocal object from inherited base classes: nn with example: obj = NonLocal(in_channels, nonlocal_type, dim, embed, embed_dim, sub_sample, use_bn, norm_layer, norm_kwargs)