MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / Block

Class Block

detection/backbone/vit_SelfPatch.py:95–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93
94
95class Block(nn.Module):
96 def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0.,
97 drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm):
98 super().__init__()
99 self.norm1 = norm_layer(dim)
100 self.attn = Attention(
101 dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)
102 self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
103 self.norm2 = norm_layer(dim)
104 mlp_hidden_dim = int(dim * mlp_ratio)
105 self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
106
107 def forward(self, x, return_attention=False):
108 y, attn = self.attn(self.norm1(x))
109 if return_attention:
110 return attn
111 x = x + self.drop_path(y)
112 x = x + self.drop_path(self.mlp(self.norm2(x)))
113 return x
114
115
116class PatchEmbed(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected