class_docstr: The ExternalAttention implementation based on PaddlePaddle.
  Args:
      in_channels (int, optional): The input channels.
      inter_channels (int, optional): The channels of intermediate feature.
      out_channels (int, optional): The output channels.
      num_heads (int, optional): The num of heads in attention. Default: 8
      use_cross_kv (bool, optional): Wheter use cross_kv. Default: False
class_docstr_tok: ["The","ExternalAttention","implementation","based","on","PaddlePaddle",".","Args",":","in_channels","(","int",",","optional",")",":","The","input","channels",".","inter_channels","(","int",",","optional",")",":","The","channels","of","intermediate","feature",".","out_channels","(","int",",","optional",")",":","The","output","channels",".","num_heads","(","int",",","optional",")",":","The","num","of","heads","in","attention",".","Default",":","8","use_cross_kv","(","bool",",","optional",")",":","Wheter","use","cross_kv",".","Default",":","False"]
code: def __init__(
      self,
      in_channels,
      out_channels,
      inter_channels,
      num_heads=8,
      use_cross_kv=False,
  ):
      super().__init__()
      assert (
          out_channels % num_heads == 0
      ), "out_channels ({}) should be be a multiple of num_heads ({})".format(
          out_channels, num_heads
      )
      self.in_channels = in_channels
      self.out_channels = out_channels
      self.inter_channels = inter_channels
      self.num_heads = num_heads
      self.use_cross_kv = use_cross_kv
      self.norm = bn2d(in_channels)
      self.same_in_out_chs = in_channels == out_channels
  
      if use_cross_kv:
          assert (
              self.same_in_out_chs
          ), "in_channels is not equal to out_channels when use_cross_kv is True"
      else:
          self.k = self.create_parameter(
              shape=(inter_channels, in_channels, 1, 1),
              default_initializer=paddle.nn.initializer.Normal(
                  std=0.001
              ),
          )
          self.v = self.create_parameter(
              shape=(out_channels, inter_channels, 1, 1),
              default_initializer=paddle.nn.initializer.Normal(
                  std=0.001
              ),
          )
  
      self.apply(self._init_weights)
  
imports: from functools import partial
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager, param_init
  from paddleseg.models import layers
  from paddleseg.utils import utils
  from paddleseg.models.backbones.transformer_utils import DropPath, Identity
  from paddleseg.cvlibs.param_init import constant_init, kaiming_normal_init, trunc_normal_init
label_desc: Use image node_id 1 to create a new ExternalAttention object from inherited base classes: nn with example: obj = ExternalAttention(in_channels, out_channels, inter_channels, num_heads, use_cross_kv)