fix template_verts

This commit is contained in:
Sen Liang committed 2022-03-17 17:08:43 +08:00
1 parent f6ccefc247
commit 11277e478f
2 files changed
+34 -8

No files matched your search

+30 -6
View File
@@ -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: