MCPcopy Create free account
hub / github.com/Francis-Rings/StableAnimator / __init__

Method __init__

animation/helper/backbones/vit.py:75–105  ·  view source on GitHub ↗
(self,
                 dim: int,
                 num_heads: int,
                 num_patches: int,
                 mlp_ratio: float = 4.,
                 qkv_bias: bool = False,
                 qk_scale: Optional[None] = None,
                 drop: float = 0.,
                 attn_drop: float = 0.,
                 drop_path: float = 0.,
                 act_layer: Callable = nn.ReLU6,
                 norm_layer: str = "ln", 
                 patch_n: int = 144)

Source from the content-addressed store, hash-verified

73class Block(nn.Module):
74
75 def __init__(self,
76 dim: int,
77 num_heads: int,
78 num_patches: int,
79 mlp_ratio: float = 4.,
80 qkv_bias: bool = False,
81 qk_scale: Optional[None] = None,
82 drop: float = 0.,
83 attn_drop: float = 0.,
84 drop_path: float = 0.,
85 act_layer: Callable = nn.ReLU6,
86 norm_layer: str = "ln",
87 patch_n: int = 144):
88 super().__init__()
89
90 if norm_layer == "bn":
91 self.norm1 = VITBatchNorm(num_features=num_patches)
92 self.norm2 = VITBatchNorm(num_features=num_patches)
93 elif norm_layer == "ln":
94 self.norm1 = nn.LayerNorm(dim)
95 self.norm2 = nn.LayerNorm(dim)
96
97 self.attn = Attention(
98 dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)
99 # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
100 self.drop_path = DropPath(
101 drop_path) if drop_path > 0. else nn.Identity()
102 mlp_hidden_dim = int(dim * mlp_ratio)
103 self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim,
104 act_layer=act_layer, drop=drop)
105 self.extra_gflops = (num_heads * patch_n * (dim//num_heads)*patch_n * 2) / (1000**3)
106
107 def forward(self, x):
108 x = x + self.drop_path(self.attn(self.norm1(x)))

Callers

nothing calls this directly

Calls 4

VITBatchNormClass · 0.85
AttentionClass · 0.85
MlpClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected