add infer support for audio2motion
This commit is contained in:
1 parent
0b46d9f3eb
commit
23fdd42edd
23 files changed
+824
-74
No files matched your search
@@ -534,7 +534,7 @@ def tensor2image(tensor):
|
||||
image = image*255.
|
||||
image = np.maximum(np.minimum(image, 255), 0)
|
||||
image = image.transpose(1,2,0)[:,:,[2,1,0]]
|
||||
|
||||
|
||||
return image.astype(np.uint8).copy()
|
||||
|
||||
|
||||
|
||||
@@ -157,8 +157,6 @@ class Audio2MotionModel(Base):
|
||||
|
||||
return loss_dict
|
||||
|
||||
|
||||
|
||||
def validation(self, batch_input):
|
||||
self.eval() # set eval model
|
||||
self.set_input(batch_input)
|
||||
@@ -171,23 +169,31 @@ class Audio2MotionModel(Base):
|
||||
return loss_dict
|
||||
|
||||
|
||||
def infer(self, batch_cond, path_audio, suffix=""):
|
||||
def infer(self, batch_cond, batch_speech, suffix="", save_npy=True):
|
||||
self.eval()
|
||||
self.cond = batch_cond.float().to(self.device) # (nsteps, dim_cond)
|
||||
|
||||
with torch.no_grad():
|
||||
samples_pt = self.netG(self.cond).cpu().numpy() # B x N x dim_motion
|
||||
print(f"testing pt shape = {samples_pt.shape}")
|
||||
batch_pdt = self.netG(self.cond) # B x N x dim_motion
|
||||
print(f"testing pt shape = {batch_pdt.shape}")
|
||||
|
||||
self.save_reconstruct(samples_pt, path_audio,
|
||||
path_save=Path(self.opt.OUTPUT_DIR),
|
||||
suffix=suffix)
|
||||
# to geo
|
||||
batch_pdt_geo, *_ = self.get_vertices(batch_pdt) # B x N x 5023 x 3
|
||||
print(f"testing batch_pdt shape = {batch_pdt.shape}, batch_pdt_geo = {batch_pdt_geo.shape}")
|
||||
|
||||
# save result
|
||||
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}")
|
||||
|
||||
# render & and save
|
||||
self.save_reconstruct(batch_pdt_geo, batch_speech, path_save=Path(self.opt.OUTPUT_DIR),
|
||||
suffix=suffix, vis_landmarks=False)
|
||||
|
||||
if save_npy:
|
||||
# save result
|
||||
# batch_pdt_geo = batch_pdt_geo.cpu().numpy()
|
||||
batch_pdt = batch_pdt.cpu().numpy()
|
||||
path_save_npy = Path(self.opt.OUTPUT_DIR).joinpath(f"{suffix}_coeff.npy")
|
||||
np.save(path_save_npy, batch_pdt)
|
||||
print(f"save infer_result shape = {batch_pdt.shape} -> {path_save_npy}")
|
||||
|
||||
|
||||
def testing(self, batch_input, idx_epoch=0, idx_batch=0):
|
||||
self.eval() # set eval model
|
||||
|
||||
@@ -57,7 +57,7 @@ class Audio2Motion(nn.Module):
|
||||
nn.Linear(in_features=128, out_features=self.dim_motion),
|
||||
)
|
||||
|
||||
|
||||
|
||||
def forward(self, x):
|
||||
""" forward function
|
||||
Args:
|
||||
|
||||
Reference in new issue
Block a user