class_docstr: Basic Non-local module.
  This model is the implementation of "Non-local Neural Networks"
  (https://arxiv.org/abs/1711.07971)
  
  Args:
      in_channels (int): Channels of the input feature map.
      reduction (int): Channel reduction ratio. Default: 2.
      use_scale (bool): Whether to scale pairwise_weight by `1/sqrt(inter_channels)` when the mode is `embedded_gaussian`. Default: True.
      sub_sample (bool): Whether to utilize max pooling after pairwise function. Default: False.
      mode (str): Options are `gaussian`, `concatenation`, `embedded_gaussian` and `dot_product`. Default: embedded_gaussian.
code: def forward(self, x):
      n, c, h, w = x.shape
      g_x = paddle.reshape(self.g(x), [n, self.inter_channels, -1])
      g_x = paddle.transpose(g_x, [0, 2, 1])
  
      if self.mode == "gaussian":
          theta_x = paddle.reshape(x, [n, self.inter_channels, -1])
          theta_x = paddle.transpose(theta_x, [0, 2, 1])
          if self.sub_sample:
              phi_x = paddle.reshape(
                  self.phi(x), [n, self.inter_channels, -1]
              )
          else:
              phi_x = paddle.reshape(x, [n, self.in_channels, -1])
  
      elif self.mode == "concatenation":
          theta_x = paddle.reshape(
              self.theta(x), [n, self.inter_channels, -1, 1]
          )
          phi_x = paddle.reshape(
              self.phi(x), [n, self.inter_channels, 1, -1]
          )
  
      else:
          theta_x = paddle.reshape(
              self.theta(x), [n, self.inter_channels, -1]
          )
          theta_x = paddle.transpose(theta_x, [0, 2, 1])
          phi_x = paddle.reshape(
              self.phi(x), [n, self.inter_channels, -1]
          )
  
      pairwise_func = getattr(self, self.mode)
      pairwise_weight = pairwise_func(theta_x, phi_x)
      y = paddle.matmul(pairwise_weight, g_x)
      y = paddle.transpose(y, [0, 2, 1])
      y = paddle.reshape(y, [n, self.inter_channels, h, w])
  
      output = x + self.conv_out(y)
  
      return output
  
file_path: PaddleSeg/paddleseg/models/layers/nonlocal2d.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.models import layers
label_desc: Use image node_id 6 for calling the NonLocal2D obj's underlying member method code with example usage: obj.forward(x) and returns: output