41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import torch
|
|
import torch.nn as nn
|
|
from common.debug import debug
|
|
|
|
class Audio2MotionHead(nn.Module):
|
|
|
|
def __init__(self, opt):
|
|
super(Audio2MotionHead, self).__init__()
|
|
|
|
self.opt = opt
|
|
self.dim_motion = opt.MODEL.dim_motion # 53
|
|
self.dim_speech = opt.MODEL.dim_speech # 27
|
|
print(f"dim_speech={self.dim_speech}")
|
|
|
|
# encoder
|
|
self.head = nn.Sequential( # nbatch x nseqlen x 27
|
|
nn.Linear(in_features=self.dim_speech, out_features=256),
|
|
nn.LeakyReLU(0.2),
|
|
|
|
nn.Linear(in_features=256, out_features=self.dim_motion),
|
|
nn.Tanh()
|
|
)
|
|
|
|
|
|
def forward(self, x):
|
|
""" forward function
|
|
Args:
|
|
x: torch.Tensor, [nbatch x seqlen x dim_condit]
|
|
return:
|
|
pred: torch.Tensor, [nbatch x seqlen x dim_motion]
|
|
"""
|
|
debug(self.opt, f"[forward] input x shape = {x.shape}", verbose=False)
|
|
|
|
pred = self.head(x) # [nbatch x nseqlen x dim_hidden]
|
|
|
|
debug(self.opt, f"[forward] decoder shape = {pred.shape}", verbose=False)
|
|
|
|
return pred
|
|
|
|
|