class_docstr: Self attention layer for nd.
class_docstr_tok: ["Self","attention","layer","for","nd","."]
code: def forward(self, x):
      # Notation from https://arxiv.org/pdf/1805.08318.pdf
      size = x.shape
      x = paddle.reshape(x, list(size[:2]) + [-1])
      f, g, h = self.query(x), self.key(x), self.value(x)
  
      beta = paddle.nn.functional.softmax(
          paddle.bmm(paddle.transpose(f, [0, 2, 1]), g), axis=1
      )
      o = self.gamma * paddle.bmm(h, beta) + x
      return paddle.reshape(o, size)
  
imports: import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle.vision.models import resnet101
  from .None import utils
label_desc: Use image node_id 2 for calling the SelfAttention obj's underlying member method code with example usage: obj.forward(x) and returns: paddle