MCPcopy Create free account
hub / github.com/360CVGroup/FancyVideo / VanillaTemporalModule

Class VanillaTemporalModule

fancyvideo/models/motion_module.py:50–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48
49
50class VanillaTemporalModule(nn.Module):
51 def __init__(
52 self,
53 in_channels,
54 num_attention_heads = 8,
55 num_transformer_block = 2,
56 attention_block_types =( "Temporal_Self", "Temporal_Self" ),
57 cross_frame_attention_mode = None,
58 temporal_position_encoding = False,
59 temporal_position_encoding_max_len = 24,
60 temporal_attention_dim_div = 1,
61 zero_initialize = True,
62 ):
63 super().__init__()
64
65 self.temporal_transformer = TemporalTransformer3DModel(
66 in_channels=in_channels,
67 num_attention_heads=num_attention_heads,
68 attention_head_dim=in_channels // num_attention_heads // temporal_attention_dim_div,
69 num_layers=num_transformer_block,
70 attention_block_types=attention_block_types,
71 norm_num_groups=11 if in_channels==77 else 32,
72 cross_frame_attention_mode=cross_frame_attention_mode,
73 temporal_position_encoding=temporal_position_encoding,
74 temporal_position_encoding_max_len=temporal_position_encoding_max_len,
75 )
76
77 if zero_initialize:
78 self.temporal_transformer.proj_out = zero_module(self.temporal_transformer.proj_out)
79
80 def forward(self, input_tensor, temb, encoder_hidden_states, attention_mask=None, anchor_frame_idx=None):
81 hidden_states = input_tensor
82 hidden_states = self.temporal_transformer(hidden_states, encoder_hidden_states, attention_mask)
83
84 output = hidden_states
85 return output
86
87
88class TemporalTransformer3DModel(nn.Module):

Callers 1

get_motion_moduleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected