update Actor6

This commit is contained in:
liangsen committed 2022-05-27 16:23:49 +08:00
1 parent dac314c9a5
commit e9b2b238b2
35 files changed
+1226 -697

No files matched your search

+3 -2
View File
@@ -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']
+25 -9
View File
@@ -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
+1
View File
@@ -167,6 +167,7 @@ class Audio2motionLiveModel(Base):
loss = 0
loss_dict = {}
batch_pdt_exp = batch_pdt[..., :50]
batch_pdt_pos = batch_pdt[..., 50:]
+1
View File
@@ -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)