class_docstr: The EABlock implementation based on PaddlePaddle.
  Args:
      in_channels (int, optional): The input channels.
      out_channels (int, optional): The output channels.
      num_heads (int, optional): The num of heads in attention. Default: 8
      drop_rate (float, optional): The drop rate in MLP. Default:0.
      drop_path_rate (float, optional): The drop path rate in EABlock. Default: 0.2
      use_injection (bool, optional): Whether inject the high feature into low feature. Default: True
      use_cross_kv (bool, optional): Wheter use cross_kv. Default: True
      cross_size (int, optional): The size of pooling in cross_kv. Default: 12
class_docstr_tok: ["The","EABlock","implementation","based","on","PaddlePaddle",".","Args",":","in_channels","(","int",",","optional",")",":","The","input","channels",".","out_channels","(","int",",","optional",")",":","The","output","channels",".","num_heads","(","int",",","optional",")",":","The","num","of","heads","in","attention",".","Default",":","8","drop_rate","(","float",",","optional",")",":","The","drop","rate","in","MLP",".","Default:0.","drop_path_rate","(","float",",","optional",")",":","The","drop","path","rate","in","EABlock",".","Default",":","0.2","use_injection","(","bool",",","optional",")",":","Whether","inject","the","high","feature","into","low","feature",".","Default",":","True","use_cross_kv","(","bool",",","optional",")",":","Wheter","use","cross_kv",".","Default",":","True","cross_size","(","int",",","optional",")",":","The","size","of","pooling","in","cross_kv",".","Default",":","12"]
code: def __init__(
      self,
      in_channels,
      out_channels,
      num_heads=8,
      drop_rate=0.0,
      drop_path_rate=0.0,
      use_injection=True,
      use_cross_kv=True,
      cross_size=12,
  ):
      super().__init__()
      in_channels_h, in_channels_l = in_channels
      out_channels_h, out_channels_l = out_channels
      assert (
          in_channels_h == out_channels_h
      ), "in_channels_h is not equal to out_channels_h"
      self.out_channels_h = out_channels_h
      self.proj_flag = in_channels_l != out_channels_l
      self.use_injection = use_injection
      self.use_cross_kv = use_cross_kv
      self.cross_size = cross_size
      # low resolution
      if self.proj_flag:
          self.attn_shortcut_l = nn.Sequential(
              bn2d(in_channels_l),
              conv2d(in_channels_l, out_channels_l, 1, 2, 0),
          )
          self.attn_shortcut_l.apply(self._init_weights_kaiming)
      self.attn_l = ExternalAttention(
          in_channels_l,
          out_channels_l,
          inter_channels=out_channels_l,
          num_heads=num_heads,
          use_cross_kv=False,
      )
      self.mlp_l = MLP(out_channels_l, drop_rate=drop_rate)
      self.drop_path = (
          DropPath(drop_path_rate)
          if drop_path_rate > 0.0
          else Identity()
      )
  
      # compression
      self.compression = nn.Sequential(
          bn2d(out_channels_l),
          nn.ReLU(),
          conv2d(out_channels_l, out_channels_h, kernel_size=1),
      )
      self.compression.apply(self._init_weights_kaiming)
  
      # high resolution
      self.attn_h = ExternalAttention(
          in_channels_h,
          in_channels_h,
          inter_channels=cross_size * cross_size,
          num_heads=num_heads,
          use_cross_kv=use_cross_kv,
      )
      self.mlp_h = MLP(out_channels_h, drop_rate=drop_rate)
      if use_cross_kv:
          self.cross_kv = nn.Sequential(
              bn2d(out_channels_l),
              nn.AdaptiveMaxPool2D(
                  output_size=(self.cross_size, self.cross_size)
              ),
              conv2d(out_channels_l, 2 * out_channels_h, 1, 1, 0),
          )
          self.cross_kv.apply(self._init_weights)
  
      # injection
      if use_injection:
          self.down = nn.Sequential(
              bn2d(out_channels_h),
              nn.ReLU(),
              conv2d(
                  out_channels_h,
                  out_channels_l // 2,
                  kernel_size=3,
                  stride=2,
                  padding=1,
              ),
              bn2d(out_channels_l // 2),
              nn.ReLU(),
              conv2d(
                  out_channels_l // 2,
                  out_channels_l,
                  kernel_size=3,
                  stride=2,
                  padding=1,
              ),
          )
          self.down.apply(self._init_weights_kaiming)
  
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 EABlock object from inherited base classes: nn with example: obj = EABlock(in_channels, out_channels, num_heads, drop_rate, drop_path_rate, use_injection, use_cross_kv, cross_size)