From 11277e478f9fdc261b1448681f7288e239cd7526 Mon Sep 17 00:00:00 2001 From: Sen Liang Date: Thu, 17 Mar 2022 17:08:43 +0800 Subject: [PATCH] fix template_verts --- src/models/model_audio2mesh.py | 36 +++++++++++++++++++++++++------ src/models/model_audio2mesh_ar.py | 6 ++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/models/model_audio2mesh.py b/src/models/model_audio2mesh.py index c870c8e..647cda5 100644 --- a/src/models/model_audio2mesh.py +++ b/src/models/model_audio2mesh.py @@ -211,11 +211,14 @@ class Audio2MeshModel(Base): path_save=Path(self.opt.OUTPUT_DIR), suffix=suffix) - # # save result - # samples_pt = samples_pt.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}") + # !! add specific when render & output !! + samples_pt = samples_pt - self.template_verts + self.template_verts_specific + + # save result + samples_pt = samples_pt.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}") def testing(self, batch_input, cur_epoch=0, cur_batch=0): @@ -229,13 +232,34 @@ class Audio2MeshModel(Base): samples_gt = self.get_vertices(self.data) # B x N x 5023 x 3 # samples_gt = samples_gt.cpu().numpy() # B x N x 5023 x 3 - print(f"testing pt shape = {samples_pt.shape}, gt shape = {samples_gt.shape}") + # !! add specific when render & output !! + samples_pt = samples_pt - self.template_verts + self.template_verts_specific + print(f"testing pt shape = {samples_pt.shape}, gt shape = {samples_gt.shape}") self.save_reconstruct_with_gt(samples_pt, samples_gt, path_save=Path(self.opt.OUTPUT_DIR), suffix=f'sampled_{cur_epoch:05d}_{cur_batch:03d}') + def get_template_vertices(self, mean_dict=None): + + batch_exp = torch.zeros(1, 50).to(self.device) + batch_pos = torch.zeros(1, 6).to(self.device) + + if mean_dict is not None: + batch_shape = self.mean_dict["shape"].reshape(1, 100) + batch_shape = torch.from_numpy(batch_shape).float().to(self.device) + else: + batch_shape = torch.zeros(1, 100).to(self.device) + + verts, _, _ = self.netR.get_vertices(batch_shape, batch_exp, batch_pos) # 1 x 5023 x 3 + print(f"template verts reshape = {verts.shape}") + # np.save("./data/template.npy", verts.squeeze().cpu().numpy()) + # print(f"save template.npy = {verts.squeeze().shape}") + # assert False + + return verts.unsqueeze(dim=0) # 1 x 1 x 5023 x 3 + def get_template_vertices(self, mean_dict=None): if mean_dict is not None: diff --git a/src/models/model_audio2mesh_ar.py b/src/models/model_audio2mesh_ar.py index b6368ba..f5cc98f 100644 --- a/src/models/model_audio2mesh_ar.py +++ b/src/models/model_audio2mesh_ar.py @@ -288,10 +288,12 @@ class Audio2MeshARModel(Base): batch_shape = torch.zeros(1, 100).to(self.device) verts, _, _ = self.netR.get_vertices(batch_shape, batch_exp, batch_pos) # 1 x 5023 x 3 - verts = verts.unsqueeze(dim=0) # 1 x 1 x 5023 x 3 print(f"template verts reshape = {verts.shape}") + # np.save("./data/template.npy", verts.squeeze().cpu().numpy()) + # print(f"save template.npy = {verts.squeeze().shape}") + # assert False - return verts + return verts.unsqueeze(dim=0) # 1 x 1 x 5023 x 3 def get_vertices(self, batch_motion):