class_docstr: A self-attention module.
class_docstr_tok: ["A","self-attention","module","."]
code: def forward(self, x, proxy):
      x_shape = paddle.shape(x)
      # query : from (n, c1, h1, w1) to (n, h1*w1, key_channels)
      query = self.f_pixel(x)
      query = paddle.reshape(query, (0, self.key_channels, -1))
      query = paddle.transpose(query, (0, 2, 1))
  
      # key : from (n, c2, h2, w2) to (n, key_channels, h2*w2)
      key = self.f_object(proxy)
      key = paddle.reshape(key, (0, self.key_channels, -1))
  
      # value : from (n, c2, h2, w2) to (n, h2*w2, key_channels)
      value = self.f_down(proxy)
      value = paddle.reshape(value, (0, self.key_channels, -1))
      value = paddle.transpose(value, (0, 2, 1))
  
      # sim_map (n, h1*w1, h2*w2)
      sim_map = paddle.bmm(query, key)
      sim_map = (self.key_channels**-0.5) * sim_map
      sim_map = F.softmax(sim_map, axis=-1)
  
      # context from (n, h1*w1, key_channels) to (n , out_channels, h1, w1)
      context = paddle.bmm(sim_map, value)
      context = paddle.transpose(context, (0, 2, 1))
      context = paddle.reshape(
          context, (0, self.key_channels, x_shape[2], x_shape[3])
      )
      context = self.f_up(context)
  
      return context
  
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg import utils
  from paddleseg.cvlibs import manager, param_init
  from paddleseg.models import layers
label_desc: Use image node_id 2 for calling the ObjectAttentionBlock obj's underlying member method code with example usage: obj.forward(x, proxy) and returns: context