luciayen commited on
Commit
558c6ba
·
verified ·
1 Parent(s): a9165d8

Final architecture alignment: BatchNorm(64) for temporal normalization

Browse files
Files changed (1) hide show
  1. model.py +9 -9
model.py CHANGED
@@ -6,13 +6,13 @@ class SignVLM(nn.Module):
6
  def __init__(self, input_dim=225, hidden_dim=512, num_heads=8, num_layers=4, num_classes=60):
7
  super(SignVLM, self).__init__()
8
 
9
- # Updated hidden_dim to 512 to match the checkpoint
10
  self.feature_extractor = nn.Sequential(
11
  nn.Linear(input_dim, hidden_dim),
12
- nn.BatchNorm1d(hidden_dim)
 
13
  )
14
 
15
- # Updated dim_feedforward to 1024 (hidden_dim * 2)
16
  encoder_layer = nn.TransformerEncoderLayer(
17
  d_model=hidden_dim,
18
  nhead=num_heads,
@@ -22,17 +22,17 @@ class SignVLM(nn.Module):
22
  self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=num_layers)
23
 
24
  self.classifier = nn.Sequential(
25
- nn.Linear(hidden_dim, 256), # First layer reduces 512 -> 256
26
  nn.ReLU(),
27
  nn.Dropout(0.5),
28
  nn.Linear(256, num_classes)
29
  )
30
 
31
  def forward(self, x):
32
- batch_size, seq_len, features = x.shape
33
- x = x.view(-1, features)
34
- x = self.feature_extractor(x)
35
- x = x.view(batch_size, seq_len, -1)
36
  x = self.transformer(x)
37
- x = x.mean(dim=1)
38
  return self.classifier(x)
 
6
  def __init__(self, input_dim=225, hidden_dim=512, num_heads=8, num_layers=4, num_classes=60):
7
  super(SignVLM, self).__init__()
8
 
9
+ # Layer 0: Projection to 512
10
  self.feature_extractor = nn.Sequential(
11
  nn.Linear(input_dim, hidden_dim),
12
+ # Layer 1: BatchNorm across the 64 frames
13
+ nn.BatchNorm1d(64)
14
  )
15
 
 
16
  encoder_layer = nn.TransformerEncoderLayer(
17
  d_model=hidden_dim,
18
  nhead=num_heads,
 
22
  self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=num_layers)
23
 
24
  self.classifier = nn.Sequential(
25
+ nn.Linear(hidden_dim, 256),
26
  nn.ReLU(),
27
  nn.Dropout(0.5),
28
  nn.Linear(256, num_classes)
29
  )
30
 
31
  def forward(self, x):
32
+ # x: [batch, 64, 225]
33
+ x = self.feature_extractor[0](x) # Linear projection: [batch, 64, 512]
34
+ x = self.feature_extractor[1](x) # BatchNorm1d: [batch, 64, 512] (normalizing dim 1)
35
+
36
  x = self.transformer(x)
37
+ x = x.mean(dim=1) # Global Average Pooling
38
  return self.classifier(x)