update Actor6
This commit is contained in:
1 parent
dac314c9a5
commit
e9b2b238b2
35 files changed
+1226
-697
No files matched your search
@@ -8,6 +8,7 @@ from scipy.signal import savgol_filter
|
||||
|
||||
# common
|
||||
from common.resampling import resample_by_nsteps
|
||||
from audiomentations import Compose, AddGaussianNoise, TimeStretch, PitchShift, Shift
|
||||
|
||||
|
||||
class MotionLiveDataset(Dataset):
|
||||
@@ -42,6 +43,10 @@ class MotionLiveDataset(Dataset):
|
||||
f'''nsteps_frame={self.nsteps_frame}\t'''
|
||||
f'''nsteps_segmt={self.nsteps_segmt} ''')
|
||||
|
||||
self.audio_augment = Compose([
|
||||
AddGaussianNoise(min_amplitude=0.001, max_amplitude=0.015, p=0.2),
|
||||
PitchShift(min_semitones=-4, max_semitones=4, p=0.2),
|
||||
])
|
||||
|
||||
|
||||
def __len__(self):
|
||||
@@ -72,6 +77,7 @@ class MotionLiveDataset(Dataset):
|
||||
nframe = data_motion.shape[0]
|
||||
nsegmt = data_speech.shape[0]
|
||||
|
||||
|
||||
if self.phase == "train" and self.opt.DATASET.shifting_speed and random.random() < 0.3:
|
||||
speed = random.sample({0.5, 0.7, 0.8, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5},1)[0]
|
||||
|
||||
@@ -109,6 +115,12 @@ class MotionLiveDataset(Dataset):
|
||||
assert data_motion.shape[0] == self.nsteps_frame, f"data_motion shape={data_motion.shape}, vid={vid}"
|
||||
|
||||
|
||||
# audio augment
|
||||
data_speech = self.audio_augment(samples=data_speech, sample_rate=self.sr )
|
||||
# print(f"after augment data speech = {data_speech.shape}, before nsegmt = {nsegmt}, nframe={nframe}")
|
||||
# assert data_speech.shape[0] == (end_segmt-beg_segmt), f"after augment data speech {data_speech.shape} should = {end_segmt-beg_segmt}"
|
||||
|
||||
|
||||
# filter, explore doc: ./notebook/explore_pose.ipynb
|
||||
if self.opt.DATASET.filter == "savgol":
|
||||
data_motion = savgol_filter(data_motion, window_length=5, polyorder=3, axis=0, mode='nearest')
|
||||
|
||||
+3
-2
@@ -145,10 +145,11 @@ class Base():
|
||||
"""
|
||||
for scheduler in self.schedulers:
|
||||
if self.opt.TRAIN.lr_policy == 'plateau':
|
||||
scheduler.step(cur_loss)
|
||||
if cur_loss is not None:
|
||||
scheduler.step(cur_loss)
|
||||
else:
|
||||
scheduler.step()
|
||||
|
||||
|
||||
msg = ""
|
||||
for i, optimize in enumerate(self.optimizers):
|
||||
lr = optimize.param_groups[0]['lr']
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import numpy as np
|
||||
from collections import OrderedDict
|
||||
|
||||
import pickle
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from pathlib import Path
|
||||
@@ -61,12 +63,21 @@ class Audio2MeshModel(Base):
|
||||
self.temp_verts_specific, self.temp_ldmk2d_specific, self.temp_ldmk3d_specific \
|
||||
= self.get_template_vertices(self.mean_dict) # verts: (1 x 1 x 5023 x 3), ldmk: (1 x 1 x 68 x 3)
|
||||
|
||||
# save template mesh
|
||||
path_deca_mean = Path(path_deca_mean)
|
||||
path_temp_pkl = path_deca_mean.parent.joinpath(path_deca_mean.stem + "_data_template_mesh.pkl")
|
||||
if not path_temp_pkl.exists(): # load from cache
|
||||
self.logger.info(f"Load template mesh from raw 3DMM... (!NOT FOUND {path_temp_pkl}) ")
|
||||
template_mesh = self.temp_verts_specific.cpu().numpy() # verts: (1 x 1 x 5023 x 3)
|
||||
# save template data
|
||||
with open(str(path_temp_pkl), 'wb') as f:
|
||||
pickle.dump(template_mesh, f)
|
||||
|
||||
# self.temp_verts_specific = np.load("/ssdata1/lsen/CODE/audio-to-motion/data/Actor4/template_meiyan2.npy") # (5023, 3)
|
||||
# self.temp_verts_specific = self.temp_verts_specific.reshape(1, 1, 5023, 3)
|
||||
# self.temp_verts_specific = torch.from_numpy(self.temp_verts_specific).to(self.device)
|
||||
|
||||
# save to
|
||||
|
||||
# loss function
|
||||
self.loss_func_wing = WingLoss(reduction="none") # return (B, )
|
||||
self.loss_func_l1 = nn.L1Loss(reduction="none")
|
||||
@@ -184,22 +195,28 @@ class Audio2MeshModel(Base):
|
||||
|
||||
|
||||
def infer_with_gt(self, batch_cond, batch_data, batch_speech, suffix="", save_npy=True):
|
||||
"""
|
||||
batch batch = [B, nsegment]
|
||||
"""
|
||||
print(f"batch_speech.shape = {batch_speech.shape}")
|
||||
|
||||
self.eval()
|
||||
|
||||
cond = batch_cond.float().to(self.device) # (nsteps, dim_cond)
|
||||
data = batch_data.float().to(self.device) # (B, nframe, 53)
|
||||
|
||||
vert, ldmk2d, ldmk3d = self.get_vertices(data)
|
||||
vert = vert - self.temp_verts + self.temp_verts_specific # add template
|
||||
|
||||
# add a dimensions
|
||||
# if batch_speech.dims == 1:
|
||||
print(f"batch_speech shape = {batch_speech}")
|
||||
batch_speech = batch_speech[np.newaxis, :] # (B, nsegmt)
|
||||
|
||||
batch_speech = batch_speech[np.newaxis, :] # (B, nsegmt)
|
||||
print(f"batch_speech shape = {batch_speech.shape}") # (1, nsegmt)
|
||||
|
||||
with torch.no_grad():
|
||||
batch_pdt_geo = self.netG(cond) # B x N x dim_motion
|
||||
batch_pdt_geo += self.temp_verts # B x N x 5023 x 3
|
||||
print(f"testing pt shape = {batch_pdt_geo.shape}")
|
||||
batch_pdt_geo = self.netG(cond) # B x N x dim_motion
|
||||
batch_pdt_geo += self.temp_verts # B x N x 5023 x 3
|
||||
print(f"testing pt shape = {batch_pdt_geo.shape}") # 1, 3000, 5023, 3
|
||||
|
||||
# !! add specific when render & output !!
|
||||
batch_pdt_geo = batch_pdt_geo - self.temp_verts + self.temp_verts_specific
|
||||
@@ -427,7 +444,7 @@ class Audio2MeshModel(Base):
|
||||
|
||||
# write video
|
||||
ipath_save = path_save.joinpath(f"{suffix}_{i:02d}_pt.mp4")
|
||||
write_video(v_render_pt, batch_speech, ipath_save, fps=50)
|
||||
write_video(v_render_pt, batch_speech[i], ipath_save, fps=50)
|
||||
self.logger.info(f"save video to -> {str(ipath_save)}")
|
||||
|
||||
|
||||
@@ -555,7 +572,6 @@ def define_FLAME(opt, device):
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def define_render(opt, device):
|
||||
from src.utils.renderer import SRenderY, set_rasterizer
|
||||
|
||||
|
||||
@@ -167,6 +167,7 @@ class Audio2motionLiveModel(Base):
|
||||
loss = 0
|
||||
loss_dict = {}
|
||||
|
||||
|
||||
batch_pdt_exp = batch_pdt[..., :50]
|
||||
batch_pdt_pos = batch_pdt[..., 50:]
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ class Audio2motionLive2Model(Base):
|
||||
debug(self.opt, f"\n a data = {self.data.shape}, dtype={self.data.dtype}, device={self.data.device}", verbose=False)
|
||||
debug(self.opt, f"a cond = {self.cond.shape}, dtype={self.cond.dtype}, device={self.cond.device}", verbose=False)
|
||||
|
||||
|
||||
def training(self, batch_input):
|
||||
self.train() # set train model
|
||||
self.set_input(batch_input)
|
||||
|
||||
@@ -51,7 +51,6 @@ class Audio2MotionVOCA(nn.Module):
|
||||
nn.Linear(in_features=2048, out_features=128) # 50,
|
||||
)
|
||||
|
||||
|
||||
# output
|
||||
self.decoder = nn.Sequential(
|
||||
nn.Linear(in_features=128, out_features=self.dim_motion),
|
||||
|
||||
Reference in new issue
Block a user