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

Class FacePerceiver

animation/modules/id_encoder.py:69–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67 )
68
69class FacePerceiver(torch.nn.Module):
70 def __init__(
71 self,
72 dim=768,
73 depth=4,
74 dim_head=64,
75 heads=16,
76 embedding_dim=1280,
77 output_dim=768,
78 ff_mult=4,
79 ):
80 super().__init__()
81
82 self.proj_in = torch.nn.Linear(embedding_dim, dim)
83 self.proj_out = torch.nn.Linear(dim, output_dim)
84 self.norm_out = torch.nn.LayerNorm(output_dim)
85 self.layers = torch.nn.ModuleList([])
86 for _ in range(depth):
87 self.layers.append(
88 torch.nn.ModuleList(
89 [
90 PerceiverAttention(dim=dim, dim_head=dim_head, heads=heads),
91 FeedForward(dim=dim, mult=ff_mult),
92 ]
93 )
94 )
95
96 nn.init.constant_(self.proj_out.weight, 0)
97 if self.proj_out.bias is not None:
98 nn.init.constant_(self.proj_out.bias, 0)
99
100 def forward(self, latents, x):
101 x = self.proj_in(x)
102 for attn, ff in self.layers:
103 latents = attn(x, latents) + latents
104 latents = ff(latents) + latents
105 latents = self.proj_out(latents)
106 return self.norm_out(latents)
107
108
109class FusionFaceId(ModelMixin):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected