Spaces:
Sleeping

Speech2Face / s2f /decoder_heads.py
ProgramComputer's picture
Super-squash branch 'main' using huggingface_hub
5a5e72e
Raw History Blame Contribute Delete
1.18 kB
from __future__ import annotations
from torch import nn
DECODER_FEATURE_DIM = 4096
def _make_decoder_heads(
*,
landmark_count: int,
bounded_geometry: bool,
) -> tuple[nn.Linear, nn.Sequential, nn.Linear, nn.Sequential]:
fc3 = nn.Linear(DECODER_FEATURE_DIM, 1000)
geometry_head = nn.Sequential(
nn.Linear(1000, 800),
nn.ReLU(),
nn.Linear(800, 600),
nn.ReLU(),
nn.Linear(600, 400),
nn.ReLU(),
nn.Linear(400, 200),
nn.ReLU(),
nn.Linear(200, landmark_count * 2),
*([nn.Tanh()] if bounded_geometry else []),
)
texture_fc = nn.Linear(1000, 14 * 14 * 256)
texture_decoder = nn.Sequential(
nn.ConvTranspose2d(256, 128, 5, stride=2, padding=2, output_padding=1),
nn.ReLU(),
nn.ConvTranspose2d(128, 64, 5, stride=2, padding=2, output_padding=1),
nn.ReLU(),
nn.ConvTranspose2d(64, 32, 5, stride=2, padding=2, output_padding=1),
nn.ReLU(),
nn.ConvTranspose2d(32, 32, 5, stride=2, padding=2, output_padding=1),
nn.ReLU(),
nn.Conv2d(32, 3, 1),
)
return fc3, geometry_head, texture_fc, texture_decoder