fix some path
This commit is contained in:
1 parent
e0f24982d1
commit
51c96565e7
16 files changed
+525
-44
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,80 @@
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# fid = "Bringing-Our-Workplace-Policies-into-the-21st-Century"
|
||||
fid = "2-23min"
|
||||
path_root = Path("/yrfs/lsen/DATA/Actor1/processing")
|
||||
|
||||
path_data = path_root.joinpath(fid)
|
||||
|
||||
path_coeff = path_data.joinpath("DECA_coeff")
|
||||
vpath_coeff = sorted(path_coeff.glob("*.npy"), reverse=False)
|
||||
print(f"Have {len(vpath_coeff)} frames")
|
||||
|
||||
|
||||
feat_shape = []
|
||||
feat_tex = []
|
||||
feat_cam = []
|
||||
feat_exp = []
|
||||
feat_pos = []
|
||||
feat_light = []
|
||||
feat_detail = []
|
||||
|
||||
for ipath_coeff in vpath_coeff:
|
||||
|
||||
data_coeff = np.load(ipath_coeff, allow_pickle=True).item()
|
||||
|
||||
# print(data_coeff.keys())
|
||||
|
||||
feat_exp.append(data_coeff["exp"])
|
||||
feat_pos.append(data_coeff["pose"])
|
||||
feat_tex.append(data_coeff["tex"])
|
||||
feat_cam.append(data_coeff["cam"])
|
||||
feat_light.append(data_coeff["light"])
|
||||
feat_detail.append(data_coeff["detail"])
|
||||
feat_shape.append(data_coeff["shape"])
|
||||
|
||||
# save
|
||||
feat_exp = np.array(feat_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.array(feat_pos) # (nframe_trim, 6)
|
||||
feat_tex = np.array(feat_tex) # (nframe_trim, 50)
|
||||
feat_cam = np.array(feat_cam) # (nframe_trim, 6)
|
||||
feat_light = np.array(feat_light) # (nframe_trim, 50)
|
||||
feat_detail = np.array(feat_detail) # (nframe_trim, 6)
|
||||
feat_shape = np.array(feat_shape) # (nframe_trim, 50)
|
||||
|
||||
mean_exp = feat_exp.mean(axis=0)
|
||||
mean_pos = feat_pos.mean(axis=0)
|
||||
mean_tex = feat_tex.mean(axis=0)
|
||||
mean_cam = feat_cam.mean(axis=0)
|
||||
mean_light = feat_light.mean(axis=0)
|
||||
mean_detail = feat_detail.mean(axis=0)
|
||||
mean_shape = feat_shape.mean(axis=0)
|
||||
|
||||
print(f"feat_exp shape = {feat_exp.shape}, mean = {mean_exp.shape}, \n{mean_exp}")
|
||||
print(f"mean_pos shape = {feat_pos.shape}, mean = {mean_pos.shape}, \n{mean_pos}")
|
||||
print(f"mean_tex shape = {feat_tex.shape}, mean = {mean_tex.shape}, \n{mean_tex}")
|
||||
print(f"mean_cam shape = {feat_cam.shape}, mean = {mean_cam.shape}, \n{mean_cam}")
|
||||
print(f"mean_light shape = {feat_light.shape}, mean = {mean_light.shape}, \n{mean_light}")
|
||||
print(f"mean_detail shape = {feat_detail.shape}, mean = {mean_detail.shape}, \n{mean_detail}")
|
||||
print(f"mean_shape shape = {feat_shape.shape}, mean = {mean_shape.shape}, \n{mean_shape}")
|
||||
|
||||
# save
|
||||
mean_DECA = {
|
||||
"exp": mean_exp, # (50, )
|
||||
"pose": mean_pos, # (6, )
|
||||
"tex": mean_tex, # (50, )
|
||||
"cam": mean_cam, # (3, )
|
||||
"light": mean_light, # (9, 3)
|
||||
"detail": mean_detail,# (128, )
|
||||
"shape": mean_shape, # (100, )
|
||||
}
|
||||
|
||||
path_save = "./data/Actor1/DECA_Actor1_mean.npy"
|
||||
np.save(path_save, mean_DECA)
|
||||
print("save to --> ", path_save)
|
||||
print(f"mean deca = \n {mean_DECA}")
|
||||
|
||||
@@ -96,6 +96,7 @@ if __name__ == "__main__":
|
||||
|
||||
else:
|
||||
print("ERROR, skip! ")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import torch
|
||||
from pathlib import Path
|
||||
|
||||
# common
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/Audio2Motion")
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/audio-to-motion")
|
||||
from common.animation import save_images_with_audio
|
||||
|
||||
sys.path.insert(0, "/ssdata1/lsen/CODE/DECA_old")
|
||||
@@ -25,7 +25,9 @@ def tensor2image(tensor):
|
||||
if __name__ == "__main__":
|
||||
|
||||
# load data
|
||||
pid = "2022-P01" # "2021-P22", actor-2HD
|
||||
pid = "2-23min" # "2021-P22", actor-2HD
|
||||
device = torch.device("cuda:9")
|
||||
|
||||
# path_root = Path("/yrfs/lsen/DATA/TestData/processing/")
|
||||
path_root = Path("/yrfs/lsen/DATA/Actor1/processing")
|
||||
|
||||
@@ -34,22 +36,26 @@ if __name__ == "__main__":
|
||||
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_60_120s.wav")
|
||||
# path_audio = path_data.joinpath("audio/audio_trim.wav")
|
||||
path_audio = path_data.joinpath("audio/audio_trim_120_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
|
||||
|
||||
# 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
|
||||
|
||||
data_pos = np.load(path_pos)[6000:6000+6000] # N x 6
|
||||
data_idn = np.load(path_idn)[6000:6000+6000] # N x 100
|
||||
data_exp = np.load(path_exp)[6000:6000+6000] # N x 50
|
||||
N = data_exp.shape[0]
|
||||
|
||||
|
||||
# load mean
|
||||
path_deca_mean = Path("./data/DECA_LuoXData_mean.npy")
|
||||
path_deca_mean = Path("./data/Actor1/DECA_Actor1_mean.npy")
|
||||
mean_dict = np.load(path_deca_mean, allow_pickle=True).item()
|
||||
print(mean_dict.keys())
|
||||
|
||||
# load deca model
|
||||
device = torch.device("cuda:0")
|
||||
deca_cfg.model.use_tex = False
|
||||
deca_cfg.dataset.image_size = 512
|
||||
netR = DECA(config = deca_cfg, device=device)
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import librosa
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
from scipy import interpolate
|
||||
|
||||
import torchaudio
|
||||
|
||||
def landmark_resample_fps(y, source_fps = 30, target_fps=25):
|
||||
""" y, N x 136, with 30fps
|
||||
"""
|
||||
|
||||
nsteps = y.shape[0]
|
||||
x = np.arange(0, nsteps, 1)
|
||||
# print("x:", x[::30], x[-10:])
|
||||
func = interpolate.interp1d(x, y=y, axis=0)
|
||||
|
||||
x_new = np.arange(0, nsteps-1, 1.0*source_fps/target_fps)
|
||||
# print("x_new", x_new[::30], x_new[-10:])
|
||||
y_new = func(x_new)
|
||||
|
||||
if source_fps < target_fps:
|
||||
y_new = np.concatenate([y_new, y[-1:]])
|
||||
|
||||
return y_new
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
path_data = Path("/yrfs/lsen/DATA/Actor1/processing")
|
||||
|
||||
path_save = Path('data/Actor1/Actor1-raw-5h') # processing
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*/audio/feat_DECA_exp_trim.npy"))
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
v_dir_videos = [ipath.parent.parent for ipath in v_dir_videos]
|
||||
vids = set([ipath.stem for ipath in v_dir_videos])
|
||||
# print(f"vids total= {vids}")
|
||||
|
||||
vid_test = set(["2-23min"])
|
||||
vid_valid = set(["2-23min"])
|
||||
vid_train = vids - vid_test - vid_valid
|
||||
|
||||
# vids = set(["2021-P09", "2021-P14", "2021-P22"])
|
||||
# vid_test = set(["2021-P09" ])
|
||||
# vid_valid = set(["2021-P14" ])
|
||||
# vid_train = set(["2021-P22" ])
|
||||
|
||||
print(f"vid test= {vid_test} \nvalid= {vid_valid}")
|
||||
print(f"vid train= {vid_train}")
|
||||
|
||||
# for each video
|
||||
data_train, data_valid, data_test = {}, {}, {}
|
||||
durations_train, durations_valid, durations_test = 0, 0, 0
|
||||
for i, ipath_data in enumerate(v_dir_videos):
|
||||
vid = ipath_data.stem
|
||||
|
||||
# if vid not in vids: continue
|
||||
# if vid in vid_test: continue
|
||||
# if vid in vid_valid:continue
|
||||
if durations_train / 3600 > 5: break
|
||||
|
||||
print(f"\n processing the {i}-th video {vid} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
ipath_feat_exp = ipath_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
ipath_feat_pos = ipath_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
ipath_feat_idn = ipath_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
ipath_speech = ipath_data.joinpath("audio/audio_trim.wav")
|
||||
|
||||
# check existing
|
||||
if not ipath_speech.exists():
|
||||
print(f"NOT existing {ipath_speech}")
|
||||
continue
|
||||
|
||||
if not ipath_feat_exp.exists():
|
||||
print(f"NOT existing {ipath_feat_exp}")
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["fps"]
|
||||
nframes = info['nframes']
|
||||
print(f"info={info}, duration = {nframes/fps}")
|
||||
assert fps == 50, "fps should be 50"
|
||||
|
||||
|
||||
# laod motion
|
||||
data_exp = np.load(ipath_feat_exp) # (nframe, 50)
|
||||
data_pos = np.load(ipath_feat_pos) # (nframe, 6)
|
||||
data_idn = np.load(ipath_feat_idn) # (nframe, 100)
|
||||
|
||||
assert data_exp.shape[0] == data_pos.shape[0], f"data_exp shape={data_exp.shape}, data_pos shape={data_pos.shape}"
|
||||
assert data_exp.shape[0] == data_idn.shape[0], f"data_exp shape={data_exp.shape}, data_idn shape={data_idn.shape}"
|
||||
|
||||
data_pos_head = data_pos[:, :3] # (nframe, 3)
|
||||
data_pos_lips = data_pos[:, 3:] # (nframe, 3)
|
||||
data_motion = np.concatenate([data_exp, data_pos_lips], axis=1) # (nframe, 53) --> fps=30
|
||||
print(f"motion = {data_motion.shape}")
|
||||
|
||||
|
||||
# load raw audio
|
||||
audio_raw, sample_rate = torchaudio.load(ipath_speech)
|
||||
print(f"audio_raw shape = {audio_raw.shape}, sr = {sample_rate}, duration = {(len(audio_raw[0])/sample_rate)}")
|
||||
|
||||
if len(audio_raw.shape) == 2:
|
||||
audio_raw = audio_raw[0]
|
||||
|
||||
if sample_rate != 16000:
|
||||
resampler = torchaudio.transforms.Resample(sample_rate, 16_000)
|
||||
audio_raw = resampler(audio_raw).squeeze().numpy()
|
||||
print(f"audio_raw shape = {audio_raw.shape}, sr = {16000}, duration = {(len(audio_raw)/16000)}")
|
||||
|
||||
# ####################################
|
||||
# # clips 4min
|
||||
# nclip = 4
|
||||
# nframes = nclip * 60 * 50 # min * 60s * fps
|
||||
# nsegmts = nclip * 60 * 16000 # min * 60s * sr
|
||||
# data_motion = data_motion[:nframes]
|
||||
# audio_raw = audio_raw[:nsegmts]
|
||||
# data_idn = data_idn[:nframes]
|
||||
# ####################################
|
||||
|
||||
if vid in vid_train:
|
||||
durations_train += nframes/fps
|
||||
|
||||
data_train[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_idn,
|
||||
}
|
||||
|
||||
if vid in vid_valid:
|
||||
durations_valid += nframes/fps
|
||||
|
||||
data_valid[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_idn,
|
||||
}
|
||||
|
||||
|
||||
if vid in vid_test:
|
||||
durations_test += nframes/fps
|
||||
|
||||
data_test[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_motion": data_motion,
|
||||
"data_speech": audio_raw,
|
||||
"data_shape": data_idn,
|
||||
}
|
||||
|
||||
|
||||
np.savez(path_save.joinpath("data_train.npz"), data=data_train)
|
||||
np.savez(path_save.joinpath("data_valid.npz"), data=data_valid)
|
||||
np.savez(path_save.joinpath("data_test.npz"), data=data_test)
|
||||
|
||||
print(f"Total frames: data_train ({durations_train / 60 } min) ({durations_train / 3600 } h) , ids = ({len(data_train)})")
|
||||
print(f"Total frames: data_valid ({durations_valid / 60 } min) ({durations_valid / 3600 } h) , ids = ({len(data_valid)})")
|
||||
print(f"Total frames: data_test ({durations_test / 60 } min) ({durations_test / 3600 } h) , ids = ({len(data_test)})")
|
||||
|
||||
# print(f"Total ids: data_train ({len(data_train)}), data_test ({len(data_test)}) data_valid({len(data_valid)})")
|
||||
# print(f"Total frames: data_train ({durations_train / 60 } min) ({durations_train / 3600 } h) , data_test ({durations_test / 60 } min) data_valid({durations_valid / 60} min)")
|
||||
print(f"--> {path_save}")
|
||||
@@ -9,28 +9,29 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
fps_save = 50
|
||||
path_save = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/video/predict_compare_3.mp4"
|
||||
path_save = "/yrfs/lsen/DATA/Actor1/processing/2-23min/video/predict_compare_2.mp4"
|
||||
|
||||
path_clipA = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/video/deca_render.mp4"
|
||||
path_clipB = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/video/deca_render_no_pos.mp4"
|
||||
path_clipC = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/video/deca_render_no_pos_no_idn.mp4"
|
||||
path_clipA = "experiments/audio2mesh/infer_audio2mesh_CN_20220314/20220315-17H39M14S/audio_trim_120_120s_infer_20220315-02H14M18S_epoch_040_002.mp4"
|
||||
path_clipB = '/yrfs/lsen/DATA/Actor1/processing/2-23min/video/deca_render_no_pos2.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"
|
||||
# path_clipBB = "experiments/audio2mesh/infer_audio2mesh_CN_20220208/20220223-20H51M40S/audio_trim_60_120s_infer_20220222-10H37M51S_epoch_235_00.mp4"
|
||||
# path_clipCC = "/yrfs/lsen/DATA/LuoXData/processing2/2021-P09/video/deca_render_no_pos_60_120s.mp4"
|
||||
|
||||
|
||||
path_audio = "/yrfs/lsen/DATA/TestData/processing/1645666605877506/audio/audio_trim.wav"
|
||||
path_audio = "/yrfs/lsen/DATA/Actor1/processing/2-23min/audio/audio_trim_120_120s.wav"
|
||||
|
||||
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)
|
||||
# clip_BB = mpy.VideoFileClip(path_clipBB)
|
||||
# clip_CC = mpy.VideoFileClip(path_clipCC)
|
||||
|
||||
audio = mpy.AudioFileClip(path_audio)
|
||||
print(f"audio duration = {audio.duration}")
|
||||
|
||||
# txtClip = mpy.TextClip('orignal',color='white', kerning = 5, fontsize=18)
|
||||
# clip_A = mpy.CompositeVideoClip( [clip_A, txtClip.set_pos('top')], size=(512,512))
|
||||
@@ -49,9 +50,12 @@ if __name__ == "__main__":
|
||||
# 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]]) # clip_C
|
||||
video = mpy.clips_array([[clip_A, clip_B]]) # clip_C
|
||||
video = video.set_audio(audio) # audd audio
|
||||
|
||||
# save
|
||||
|
||||
@@ -18,7 +18,7 @@ def main(args):
|
||||
|
||||
|
||||
# device = args.device
|
||||
device = "cuda:0"
|
||||
device = "cuda:2"
|
||||
|
||||
# run DECA
|
||||
deca_cfg.model.use_tex = args.useTex
|
||||
@@ -39,7 +39,7 @@ def main(args):
|
||||
print(f"\n processing {i}/{len(v_dir_videos)} ...", ivideo_name)
|
||||
# if ivideo_name not in IDs: continue
|
||||
|
||||
if i > 18: break
|
||||
# if i > 25: break
|
||||
|
||||
ipath_infor = ipath_data.joinpath("video/info.json")
|
||||
ipath_frame = ipath_data.joinpath("frames")
|
||||
|
||||
Reference in new issue
Block a user