update Actor6
This commit is contained in:
1 parent
dac314c9a5
commit
e9b2b238b2
35 files changed
+1226
-697
No files matched your search
@@ -0,0 +1,103 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
import torch
|
||||
from pathlib import Path
|
||||
|
||||
# common
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/Audio2Motion")
|
||||
from common.animation import save_images_with_audio
|
||||
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/DECA_old")
|
||||
from decalib.deca import DECA
|
||||
from decalib.utils import util
|
||||
from decalib.utils.config import cfg as deca_cfg
|
||||
|
||||
def tensor2image(tensor):
|
||||
image = tensor.detach().cpu().numpy()
|
||||
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()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# load data
|
||||
device = torch.device("cuda:4")
|
||||
|
||||
pid = "AA7A9568" # "2021-P22", actor-2HD
|
||||
# path_root = Path("/yrfs/lsen/DATA/TestData/processing/")
|
||||
path_root = Path("/yrfs/lsen/DATA/Actor2/processing")
|
||||
|
||||
path_data = path_root.joinpath(pid)
|
||||
|
||||
path_pos = path_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
path_idn = path_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
path_exp = path_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
# path_audio = path_data.joinpath("audio/audio_trim.wav")
|
||||
path_audio = path_data.joinpath("audio/audio_trim_120s.wav")
|
||||
|
||||
# data_pos = np.load(path_pos)[:] # N x 6
|
||||
# data_idn = np.load(path_idn) # N x 100
|
||||
# data_exp = np.load(path_exp) # N x 50
|
||||
# N = data_exp.shape[0]
|
||||
|
||||
data_pos = np.load(path_pos)[:6000] # N x 6
|
||||
data_idn = np.load(path_idn)[:6000] # N x 100
|
||||
data_exp = np.load(path_exp)[:6000] # N x 50
|
||||
N = data_exp.shape[0]
|
||||
|
||||
# load mean
|
||||
path_deca_mean = Path("./data/Actor2/DECA_Actor2_mean.npy")
|
||||
mean_dict = np.load(path_deca_mean, allow_pickle=True).item()
|
||||
print(mean_dict.keys())
|
||||
|
||||
# load deca model
|
||||
deca_cfg.model.use_tex = False
|
||||
deca_cfg.dataset.image_size = 512
|
||||
netR = DECA(config = deca_cfg, device=device)
|
||||
|
||||
# render
|
||||
path_save = path_data.joinpath("video/deca_render_no_pos_trim_120s.mp4")
|
||||
v_render_pt = []
|
||||
nbatch_render = 5
|
||||
|
||||
for k in range(0, N, nbatch_render):
|
||||
codedict = {}
|
||||
|
||||
codedict["exp"] = data_exp[k:k+nbatch_render, :50] # (nbatch_render, 50)
|
||||
|
||||
nbatch_real = codedict["exp"].shape[0]
|
||||
|
||||
codedict["pose"] = np.zeros((nbatch_real, 6)) # (nbatch_render, 6)
|
||||
codedict["pose"][:, 3:6] = data_pos[k:k+nbatch_render, 3:6]
|
||||
# codedict["pose"] = data_pos[k:k+nbatch_render, :] # (nbatch_render, 6)
|
||||
|
||||
# codedict["shape"] = np.zeros((nbatch_real, 100)) # (nabtch_render, 100)
|
||||
codedict["shape"] = data_idn[k:k+nbatch_render, :] # (nabatch_render, 100)
|
||||
|
||||
# others ==> to mean
|
||||
mean_cam = [[5,0,0]] # or [self.mean_dict["cam"]]
|
||||
codedict["cam"] = np.repeat(mean_cam, nbatch_real, axis=0) # (nbatch_render, 3)
|
||||
codedict["light"] = np.repeat([mean_dict["light"]], nbatch_real, axis=0) # (nbatch_render, 9, 3)
|
||||
codedict["detail"] = np.repeat([mean_dict["detail"]], nbatch_real, axis=0) # (nbatch_render, 128)
|
||||
|
||||
_, visdict_pt = netR.decode_one(codedict, nbatch_real, device)
|
||||
render_pt = visdict_pt["shape_images"] # (nbatch_render, 3, 224, 224)
|
||||
# print(f"render pt shape = {render_pt.shape}")
|
||||
|
||||
for m in range(nbatch_real):
|
||||
# cv2.imwrite(str(kpath_image), util.tensor2image(render_image[m, ...]))
|
||||
v_render_pt.append(tensor2image(render_pt[m, ...]))
|
||||
|
||||
|
||||
|
||||
save_images_with_audio(v_render_pt, path_audio, path_save)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user