fix template_verts
This commit is contained in:
1 parent
e6f471eb64
commit
f6ccefc247
5 files changed
+51
-26
No files matched your search
@@ -94,8 +94,8 @@ if __name__ == "__main__":
|
||||
processor = Wav2Vec2FeatureExtractor.from_pretrained(MODEL_ID)
|
||||
extractor = Wav2Vec2Model.from_pretrained(MODEL_ID).to(device)
|
||||
|
||||
# path_folder = Path("/mfs/dylan/tts/wav")
|
||||
path_folder = Path("/mfs/dylan/tts/wav_john/")
|
||||
path_folder = Path("/mfs/dylan/tts/wav")
|
||||
# path_folder = Path("/mfs/dylan/tts/wav_john/")
|
||||
# path_folder = Path("/ssdata1/lsen/CODE/Audio2Motion/data/test-20220315")
|
||||
vpath_wav = sorted(path_folder.glob("*.wav"))
|
||||
|
||||
@@ -107,7 +107,6 @@ if __name__ == "__main__":
|
||||
except:
|
||||
print("\n continue ! > ipath_audio",ipath_audio)
|
||||
|
||||
|
||||
# path_audio = Path("/yrfs/lsen/DATA/LuoXData/processing2/2021-P09/audio/audio_trim_60_120s.wav")
|
||||
|
||||
# path_audio = Path("./data/test/cut_NVP.wav")
|
||||
|
||||
+6
-3
@@ -12,6 +12,9 @@ from src.models import create_model
|
||||
from src.config import config as opt
|
||||
from src.config import update_config
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
from common.logger import Logger
|
||||
from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2Model
|
||||
|
||||
@@ -41,14 +44,14 @@ if __name__ == "__main__":
|
||||
logger = Logger(opt.OUTPUT_DIR, path_config=path_config, postfix=postfix)
|
||||
device = torch.device(f'cuda:{opt.GPUS[0]}') # get device name: CPU or GPU
|
||||
|
||||
logger.info(pprint.pformat(opt))
|
||||
# logger.info(pprint.pformat(opt))
|
||||
opt.OUTPUT_DIR = logger.path_output
|
||||
|
||||
# path_audio = Path("/yrfs/lsen/DATA/LuoXData/processing2/2021-P09/audio/audio_trim_60_120s.wav")
|
||||
|
||||
# path_audio = Path("/yrfs/lsen/DATA/Actor2/processing/AA7A9568/audio/audio_trim_120s.wav")
|
||||
path_audio = Path("/yrfs/lsen/DATA/Actor2/processing/AA7A9568/audio/audio_trim_120s.wav")
|
||||
|
||||
path_audio = Path("/yrfs/lsen/DATA/Actor1/processing/2-23min/audio/audio_trim_120_120s.wav")
|
||||
# path_audio = Path("/yrfs/lsen/DATA/Actor1/processing/2-23min/audio/audio_trim_120_120s.wav")
|
||||
|
||||
# path_audio = Path("./data/test/cut_NVP.wav")
|
||||
# path_audio = Path("./data/test/cut_LSP.wav")
|
||||
|
||||
@@ -9,10 +9,11 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
fps_save = 50
|
||||
path_save = "/yrfs/lsen/DATA/Actor2/processing/AA7A9568/video/predict_compare_22.mp4"
|
||||
path_save = "/yrfs/lsen/DATA/Actor2/processing/AA7A9568/video/predict_compare_3_AR.mp4"
|
||||
|
||||
path_clipA = "experiments/audio2mesh/infer_audio2mesh_CN_20220312/20220314-15H08M06S/audio_trim_120s_infer_20220313-13H26M47S_epoch_100_002.mp4"
|
||||
path_clipB = "/yrfs/lsen/DATA/Actor2/processing/AA7A9568/video/deca_render_no_pose_120s.mp4"
|
||||
path_clipB = "experiments/audio2mesh/infer_audio2meshAR_CN_20220314/20220317-15H57M26S/audio_trim_120s_infer_20220316-23H56M06S_epoch_050_002.mp4"
|
||||
path_clipC = "/yrfs/lsen/DATA/Actor2/processing/AA7A9568/video/deca_render_no_pose_120s.mp4"
|
||||
# path_clipC = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/video/deca_render_no_pos_no_idn.mp4"
|
||||
|
||||
# path_clipAA = "experiments/audio2mesh/infer_audio2mesh_EN_20220208/20220223-21H45M05S/audio_trim_60_120s_infer_20220215-15H12M28S_epoch_120_00.mp4"
|
||||
@@ -24,7 +25,7 @@ if __name__ == "__main__":
|
||||
|
||||
clip_A = mpy.VideoFileClip(path_clipA)
|
||||
clip_B = mpy.VideoFileClip(path_clipB)
|
||||
# clip_C = mpy.VideoFileClip(path_clipC)
|
||||
clip_C = mpy.VideoFileClip(path_clipC)
|
||||
|
||||
print(f"clip_A duration = {clip_A.duration}, clip_B duration = {clip_B.duration}")
|
||||
# clip_AA = mpy.VideoFileClip(path_clipAA)
|
||||
@@ -49,12 +50,12 @@ if __name__ == "__main__":
|
||||
|
||||
clip_A = clip_A.set_duration(duration)
|
||||
clip_B = clip_B.set_duration(duration)
|
||||
# clip_C = clip_C.set_duration(duration)
|
||||
clip_C = clip_C.set_duration(duration)
|
||||
audio = audio.set_duration(duration)
|
||||
|
||||
# stack
|
||||
# video = mpy.clips_array([[clip_A, clip_B, clip_C], [clip_AA, clip_BB, clip_CC]]) # clip_C
|
||||
video = mpy.clips_array([[clip_A, clip_B]]) # clip_C
|
||||
video = mpy.clips_array([[clip_A, clip_B, clip_C]]) # clip_C
|
||||
video = video.set_audio(audio) # audd audio
|
||||
|
||||
# save
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -50,12 +50,9 @@ 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
|
||||
@@ -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,7 +218,7 @@ 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
|
||||
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):
|
||||
@@ -211,17 +228,20 @@ class Audio2MeshARModel(Base):
|
||||
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
|
||||
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}")
|
||||
|
||||
Reference in new issue
Block a user