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 forward(self, x):
      if self.embed:
          theta = self.theta(x)
          if self.sub_sample:
              phi = self.sub_phi(x)
              g = self.sub_g(x)
          else:
              phi = self.phi(x)
              g = self.g(x)
      else:
          theta = x
          phi = x
          g = x
  
      theta_shape_5d = theta.shape
      if self.nonlocal_type == "gaussian":
          # reshape [BxCxTxHxW] to [BxCxTHW]
          theta = theta.view(theta_shape_5d[0], theta_shape_5d[1], -1)
          phi = phi.view(theta_shape_5d[0], theta_shape_5d[1], -1)
          g = g.view(theta_shape_5d[0], theta_shape_5d[1], -1)
  
          theta_phi = torch.bmm(theta.transpose(1, 2), phi)
          # Normalizing the affinity tensor theta_phi before softmax.
          theta_phi = theta_phi * (self.embed_dim**-0.5)
          attn = F.softmax(theta_phi, dim=-1)
      elif self.non_local_type == "concat":
          raise NotImplementedError
      elif self.non_local_type == "dot":
          raise NotImplementedError
      else:
          raise NotImplementedError
  
      y = torch.bmm(g, attn.transpose(1, 2))
      y = y.view(theta_shape_5d)
  
      if self.use_bn:
          z = self.W_bn(y) + x
      else:
          z = self.W(y) + x
      return z
  
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 3 for calling the NonLocal obj's underlying member method code with example usage: obj.forward(x) and returns: z