MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / CBlock

Class CBlock

slowfast/models/uniformer.py:115–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114
115class CBlock(nn.Module):
116 def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0.,
117 drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm):
118 super().__init__()
119 self.pos_embed = conv_3x3x3(dim, dim, groups=dim)
120 self.norm1 = bn_3d(dim)
121 self.conv1 = conv_1x1x1(dim, dim, 1)
122 self.conv2 = conv_1x1x1(dim, dim, 1)
123 self.attn = conv_5x5x5(dim, dim, groups=dim)
124 # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
125 self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
126 self.norm2 = bn_3d(dim)
127 mlp_hidden_dim = int(dim * mlp_ratio)
128 self.mlp = CMlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
129
130 def forward(self, x):
131 x = x + self.pos_embed(x)
132 x = x + self.drop_path(self.conv2(self.attn(self.conv1(self.norm1(x)))))
133 x = x + self.drop_path(self.mlp(self.norm2(x)))
134 return x
135
136
137class SABlock(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected