class_docstr: Spatial NL block for image classification.
  
  This was adapted from https://github.com/BA-Transform/BAT-Image-Classification
  Their NonLocal impl inspired by https://github.com/facebookresearch/video-nonlocal-net.
class_docstr_tok: ["Spatial","NL","block","for","image","classification",".","This","was","adapted","from","https",":","\/\/github.com\/BA-Transform\/BAT-Image-Classification","Their","NonLocal","impl","inspired","by","https",":","\/\/github.com\/facebookresearch\/video-nonlocal-net","."]
code: def forward(self, x):
      shortcut = x
  
      t = self.t(x)
      p = self.p(x)
      g = self.g(x)
  
      B, C, H, W = t.size()
      t = t.view(B, C, -1).permute(0, 2, 1)
      p = p.view(B, C, -1)
      g = g.view(B, C, -1).permute(0, 2, 1)
  
      att = torch.bmm(t, p) * self.scale
      att = F.softmax(att, dim=2)
      x = torch.bmm(att, g)
  
      x = x.permute(0, 2, 1).reshape(B, C, H, W)
      x = self.z(x)
      x = self.norm(x) + shortcut
  
      return x
  
file_path: pytorch-image-models/timm/layers/non_local_attn.py
imports: import torch
  from torch import nn
  from torch.nn import functional
  from .conv_bn_act import ConvNormAct
  from .helpers import make_divisible
  from .trace_utils import _assert
label_desc: Use image node_id 2 for calling the NonLocalAttn obj's underlying member method code with example usage: obj.forward(x) and returns: x