class_docstr: Position attention module
  from the paper `"Dual Attention Network for Scene Segmentation"
  <https://arxiv.org/abs/1809.02983>`
  PAM_Module captures long-range spatial contextual information.
class_docstr_tok: ["Position","attention","module","from","the","paper","`","``","Dual","Attention","Network","for","Scene","Segmentation","''","<","https",":","\/\/arxiv.org\/abs\/1809.02983",">","`","PAM_Module","captures","long-range","spatial","contextual","information","."]
docstr: inputs :
      x : input feature maps( B X C X H X W)
  returns :
      out : attention value + input feature
      attention: B X (HxW) X (HxW)
docstr_tok: ["inputs",":","x",":","input","feature","maps","(","B","X","C","X","H","X","W",")","returns",":","out",":","attention","value","+","input","feature","attention",":","B","X","(","HxW",")","X","(","HxW",")"]
code: def hybrid_forward(self, F, x, **kwargs):
      """
      inputs :
          x : input feature maps( B X C X H X W)
      returns :
          out : attention value + input feature
          attention: B X (HxW) X (HxW)
      """
      gamma = kwargs["gamma"]
      proj_query = F.reshape(self.query_conv(x), (0, 0, -1))
      proj_key = F.reshape(self.key_conv(x), (0, 0, -1))
      energy = F.batch_dot(proj_query, proj_key, transpose_a=True)
      attention = F.softmax(energy)
      proj_value = F.reshape(self.value_conv(x), (0, 0, -1))
      out = F.batch_dot(proj_value, attention, transpose_b=True)
      out = F.reshape_like(
          out, x, lhs_begin=2, lhs_end=None, rhs_begin=2, rhs_end=None
      )
  
      out = F.broadcast_mul(gamma, out) + x
  
      return out
  
file_path: gluon-cv/gluoncv/model_zoo/attention.py
imports: import mxnet
  from mxnet.gluon import nn
  from mxnet.gluon.nn import HybridBlock
label_desc: Use image node_id 2 for calling the PAM_Module obj's underlying member method code with example usage: obj.hybrid_forward(F, x) and returns: out