class_docstr: General self-attention block/non-local block.
  
  The original article refers to refer to https://arxiv.org/abs/1706.03762.
  Args:
      key_in_channels (int): Input channels of key feature.
      query_in_channels (int): Input channels of query feature.
      channels (int): Output channels of key/query transform.
      out_channels (int): Output channels.
      share_key_query (bool): Whether share projection weight between key
          and query projection.
      query_downsample (nn.Module): Query downsample module.
      key_downsample (nn.Module): Key downsample module.
      key_query_num_convs (int): Number of convs for key/query projection.
      value_out_num_convs (int): Number of convs for value projection.
      key_query_norm (bool): Whether to use BN for key/query projection.
      value_out_norm (bool): Whether to use BN for value projection.
      matmul_norm (bool): Whether normalize attention map with sqrt of
          channels
      with_out (bool): Whether use out projection.
code: def forward(
      self, query_feats: paddle.Tensor, key_feats: paddle.Tensor
  ) -> paddle.Tensor:
      query_shape = paddle.shape(query_feats)
      query = self.query_project(query_feats)
      if self.query_downsample is not None:
          query = self.query_downsample(query)
      query = query.flatten(2).transpose([0, 2, 1])
  
      key = self.key_project(key_feats)
      value = self.value_project(key_feats)
  
      if self.key_downsample is not None:
          key = self.key_downsample(key)
          value = self.key_downsample(value)
  
      key = key.flatten(2)
      value = value.flatten(2).transpose([0, 2, 1])
      sim_map = paddle.matmul(query, key)
      if self.matmul_norm:
          sim_map = (self.channels**-0.5) * sim_map
      sim_map = F.softmax(sim_map, axis=-1)
  
      context = paddle.matmul(sim_map, value)
      context = paddle.transpose(context, [0, 2, 1])
  
      context = paddle.reshape(
          context,
          [0, self.out_channels, query_shape[2], query_shape[3]],
      )
  
      if self.out_project is not None:
          context = self.out_project(context)
      return context
  
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.layer import activation
  from paddle.nn import Conv2D, AvgPool2D
label_desc: Use image node_id 3 for calling the AttentionBlock obj's underlying member method code with example usage: obj.forward(query_feats, key_feats) and returns: context