fix template_verts

This commit is contained in:
Sen Liang committed 2022-03-17 17:05:52 +08:00
1 parent e6f471eb64
commit f6ccefc247
5 files changed
+55 -30

No files matched your search

+4 -4
View File
@@ -49,11 +49,11 @@ class Audio2MeshModel(Base):
# path_deca_mean = Path("./data/DECA_obama_mean.npy")
path_deca_mean = self.opt.DATASET.path_mean_dict
self.mean_dict = np.load(path_deca_mean, allow_pickle=True).item()
print(f"load mean from {path_deca_mean}, \nmean_dict keys = {self.mean_dict.keys()}")
print(f"load mean deca coeff from > {path_deca_mean}, \nkeys = {self.mean_dict.keys()}")
self.template_verts = self.get_template_vertices()
debug(opt, f"template_verts shape = {self.template_verts.shape}")
debug(opt, f"mean_dict keys = {self.mean_dict.keys()}", verbose=True)
# get template
self.template_verts = self.get_template_vertices() # 1 x 1 x 5023 x 3
self.template_verts_specific = self.get_template_vertices(self.mean_dict) # 1 x 1 x 5023 x 3
# if filter outlier
# if self.opt.LOSS.filter_outlier:
+36 -14
View File
@@ -50,14 +50,11 @@ class Audio2MeshARModel(Base):
self.mean_dict = np.load(path_deca_mean, allow_pickle=True).item()
print(f"load mean deca coeff from > {path_deca_mean}, \nkeys = {self.mean_dict.keys()}")
if self.isTrain:
self.template_verts = self.get_template_vertices()
print(f"! get template_verts from zero expression + zero expression")
else:
self.template_verts = self.get_template_vertices(self.mean_dict)
print(f"! get template_verts from {path_deca_mean}")
# get template
self.template_verts = self.get_template_vertices() # 1 x 1 x 5023 x 3
self.template_verts_specific = self.get_template_vertices(self.mean_dict) # 1 x 1 x 5023 x 3
# if filter outlier
# if self.opt.LOSS.filter_outlier:
self.loss_func_wing = WingLoss(reduction="none") # return (B, )
@@ -175,6 +172,7 @@ class Audio2MeshARModel(Base):
return loss
def validation(self, batch_input):
self.eval() # set eval model
self.set_input(batch_input)
@@ -191,6 +189,25 @@ class Audio2MeshARModel(Base):
return loss
def validation2(self, batch_input):
self.eval() # set eval model
self.set_input(batch_input)
with torch.no_grad():
batch_x = self.x[:, 1:] # B x nsteps-1 x nwind x nc_condit
batch_y_tgt = self.y_tgt[:, 1:] # B x nsteps-1 x 5023 x 3
batch_y_pre = self.y_tgt[:, :-1] # B x nsteps-1 x 5023 x 3
batch_y_pdf = self.netG(batch_x, batch_y_pre) # B x nsteps-1 x 5023 x 3
batch_y_pdf += self.template_verts # B x nsteps-1 x 5023 x 3
loss, self.loss_dict = self.eval_losses(batch_y_pdf, batch_y_tgt)
return loss
def infer(self, batch_cond, path_audio, suffix=""):
@@ -201,8 +218,8 @@ class Audio2MeshARModel(Base):
with torch.no_grad():
# prepare batch_y_pdf
batch_y_pdf = torch.zeros(B, nsteps, self.template_verts.shape[-2], 3) # B x nsteps x 5023 x 3
ibatch_y_pre = self.template_verts.expand(B, -1, -1, -1) # B x 1 x 5023 x 3
batch_y_pdf = torch.zeros(B, nsteps, self.template_verts.shape[-2], 3).to(self.device) # B x nsteps x 5023 x 3
ibatch_y_pre = self.template_verts.expand(B, -1, -1, -1) # B x 1 x 5023 x 3
for istep in range(nsteps):
@@ -210,18 +227,21 @@ class Audio2MeshARModel(Base):
ibatch_y_pdt = self.netG(ibatch_x, ibatch_y_pre) # B x 1 x 5023 x 3
ibatch_y_pdt += self.template_verts # B x 1 x 5023 x 3
ibatch_y_pre = ibatch_y_pdt[:] # update ibatch_y_pre
batch_y_pdf[:, istep] = ibatch_y_pdt.cpu().detach()[:, -1] # update y_tgt
ibatch_y_pre = ibatch_y_pdt[:] # update ibatch_y_pre
batch_y_pdf[:, istep] = ibatch_y_pdt[:, -1] # update y_tgt
# !! add specific when render & output !!
batch_y_pdf = batch_y_pdf - self.template_verts + self.template_verts_specific
print(f"testing pt shape = {batch_y_pdf.shape}, x shape = {x.shape}")
self.save_reconstruct(batch_y_pdf, path_audio, path_save=Path(self.opt.OUTPUT_DIR), suffix=suffix)
# save result
samples_pt = samples_pt.numpy()
batch_y_pdf = batch_y_pdf.cpu().numpy()
path_save_npy = Path(self.opt.OUTPUT_DIR).joinpath(f"{suffix}.npy")
np.save(path_save_npy, samples_pt)
print(f"save infer_result shape = {samples_pt.shape} -> {path_save_npy}")
np.save(path_save_npy, batch_y_pdf)
print(f"save infer_result shape = {batch_y_pdf.shape} -> {path_save_npy}")
def testing(self, batch_input, cur_epoch=0, cur_batch=0):
@@ -246,6 +266,8 @@ class Audio2MeshARModel(Base):
ibatch_y_pre = ibatch_y_pdt[:] # update ibatch_y_pre
batch_y_pdf[:, istep] = ibatch_y_pdt[:, -1] # update y_tgt
# !! add specific when render & output !!
batch_y_pdf = batch_y_pdf - self.template_verts + self.template_verts_specific
# samples_gt = samples_gt.cpu().numpy() # B x N x 5023 x 3
print(f"testing pt shape = {batch_y_pdf.shape}, gt shape = {self.y_tgt.shape}")