| 73 | |
| 74 | class Block(nn.Module): |
| 75 | def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0., |
| 76 | drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm, sr_ratio=1): |
| 77 | super().__init__() |
| 78 | self.norm1 = norm_layer(dim) |
| 79 | self.attn = Attention( |
| 80 | dim, |
| 81 | num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, |
| 82 | attn_drop=attn_drop, proj_drop=drop, sr_ratio=sr_ratio) |
| 83 | # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here |
| 84 | self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity() |
| 85 | self.norm2 = norm_layer(dim) |
| 86 | mlp_hidden_dim = int(dim * mlp_ratio) |
| 87 | self.mlp = MLPLayer(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) |
| 88 | |
| 89 | def forward(self, x, H, W): |
| 90 | x = x + self.drop_path(self.attn(self.norm1(x), H, W)) |