beta add render
This commit is contained in:
1 parent
83f99d9ec5
commit
b4c197a8ac
30 files changed
+3210
-235
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import librosa
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path("/ssdata1/lsen/DATA/Actor5/processing")
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"), reverse=False)
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
# for each video
|
||||
duration_frame, duration_coeff = 0, 0
|
||||
for ipath_data in v_dir_videos:
|
||||
ivideo_name = ipath_data.stem
|
||||
|
||||
print(f"\n processing {ivideo_name} ... ")
|
||||
ipath_infors = ipath_data.joinpath("video/info.json")
|
||||
ipath_coeff = ipath_data.joinpath("DECA_coeff")
|
||||
ipath_frame = ipath_data.joinpath("frames")
|
||||
ipath_save_exp = ipath_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
ipath_save_pos = ipath_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
ipath_save_idn = ipath_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
|
||||
if ipath_save_exp.exists() and ipath_save_pos.exists():
|
||||
print(f"ipath_save_exp have already save > {ipath_save_exp}")
|
||||
continue
|
||||
|
||||
if not ipath_infors.exists():
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_infors), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["fps"]
|
||||
nframes = info["nframes"]
|
||||
|
||||
print(f"info = {info}, duration ={nframes / fps / 60}")
|
||||
|
||||
# check
|
||||
vframe_frame = list(ipath_frame.glob("*.jpg"))
|
||||
vframe_coeff = list(ipath_coeff.glob("*.npy"))
|
||||
print(f"vframe_frame len = {len(vframe_frame)}, vframe_coeff={len(vframe_coeff)}")
|
||||
|
||||
duration_frame += len(vframe_frame) / 50 / 60
|
||||
duration_coeff += len(vframe_coeff) / 50 / 60
|
||||
print(f"add duration_frame = {duration_frame} min, duration_coeff={duration_coeff} min")
|
||||
|
||||
if len(vframe_frame) != nframes:
|
||||
print(f"\n ERROR: nframe_real ={len(vframe_frame)} / nframe_info ={nframes}")
|
||||
continue
|
||||
|
||||
if len(vframe_coeff)+1 < nframes:
|
||||
print(f"\n ERROR: nframe_coeff ={len(vframe_coeff)} / nframe_info ={nframes}")
|
||||
continue
|
||||
|
||||
if ipath_save_exp.exists() and ipath_save_pos.exists():
|
||||
print(f"ipath_save_exp have already save > {ipath_save_exp}")
|
||||
continue
|
||||
|
||||
feat_exp = []
|
||||
feat_pos = []
|
||||
feat_idn = []
|
||||
for j in range(len(vframe_frame)):
|
||||
|
||||
jpath_coeff = ipath_coeff.joinpath(f"frame-{j:06d}.json.npy")
|
||||
|
||||
if not jpath_coeff.exists():
|
||||
print(f"\n ERROR: Path NOT FOUND! -> {jpath_coeff}")
|
||||
break
|
||||
|
||||
data_coeff = np.load(jpath_coeff, allow_pickle=True).item()
|
||||
feat_exp.append(data_coeff["exp"])
|
||||
feat_pos.append(data_coeff["pose"])
|
||||
feat_idn.append(data_coeff["shape"])
|
||||
|
||||
# save
|
||||
feat_exp = np.array(feat_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.array(feat_pos) # (nframe_trim, 6)
|
||||
feat_idn = np.array(feat_idn) # (nframe_trim, 100)
|
||||
|
||||
# # pad one
|
||||
# feat_exp = np.pad(feat_exp, ((0,1),(0,0)), mode="edge")
|
||||
# feat_pos = np.pad(feat_pos, ((0,1),(0,0)), mode="edge")
|
||||
# feat_idn = np.pad(feat_idn, ((0,1),(0,0)), mode="edge")
|
||||
|
||||
if nframes == feat_idn.shape[0]:
|
||||
np.save(ipath_save_exp, feat_exp)
|
||||
np.save(ipath_save_pos, feat_pos)
|
||||
np.save(ipath_save_idn, feat_idn)
|
||||
print(f"SAVE OK! exp shape = {feat_exp.shape},pos = {feat_pos.shape}, idn={feat_idn.shape} nframe={nframes}\n save to -> {ipath_save_exp}") # (nframe, 68, 2)
|
||||
|
||||
else:
|
||||
print("ERROR, skip! ")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
import json
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
import torchaudio
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# path_data = Path("/mfs/lsen/DATA/Actor4/smile")
|
||||
path_data = Path("/ssdata1/lsen/DATA/Actor5/processing")
|
||||
|
||||
path_save = Path('data/Actor5/Actor5-raw-3h') # processing
|
||||
# path_save = Path('data/Actor5/Actor5-smile-1h') # 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}")
|
||||
|
||||
# # actor5 raw
|
||||
vid_test = set(["4R3A0063", "4R3A0071"])
|
||||
vid_valid = set(["4R3A0063", "4R3A0071"])
|
||||
vid_train = vids - vid_test - vid_valid
|
||||
|
||||
# actor5 smile
|
||||
# vid_test = set(["4R3A0071"])
|
||||
# vid_valid = set(["4R3A0071"])
|
||||
# vid_train = set(["4R3A0070", "4R3A0072", "4R3A0073", "4R3A0074", "4R3A0075"])
|
||||
|
||||
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 > 6: 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,
|
||||
}
|
||||
|
||||
|
||||
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)})")
|
||||
|
||||
|
||||
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 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}")
|
||||
@@ -0,0 +1,159 @@
|
||||
import json
|
||||
from loguru import logger
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
import torchaudio
|
||||
|
||||
import os, sys
|
||||
sys.path.insert(0, os.getcwd())
|
||||
|
||||
from common.logger import Logger
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
subfolder = "processing" # processing, smile, body
|
||||
path_data = Path(f"/ssdata1/lsen/DATA/Actor5/{subfolder}")
|
||||
path_save = Path(f'data/Actor5/data-list-{subfolder}-1h')
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# set logging
|
||||
logger = Logger(path_save)
|
||||
|
||||
# get files
|
||||
v_dir_videos = sorted(path_data.glob("*"))
|
||||
logger.info(f"Have {len(v_dir_videos)} dir files")
|
||||
vids = set([ipath.stem for ipath in v_dir_videos])
|
||||
logger.info(f"vids total= {vids}")
|
||||
|
||||
# # # actor5 raw
|
||||
# vid_test = set(["4R3A0063", "4R3A0071"])
|
||||
# vid_valid = set(["4R3A0063", "4R3A0071"])
|
||||
# vid_train = vids - vid_test - vid_valid
|
||||
|
||||
# actor5 smile
|
||||
if subfolder == "smile":
|
||||
vid_test = set(["4R3A0071"])
|
||||
vid_valid = set(["4R3A0071"])
|
||||
vid_train = set(["4R3A0070", "4R3A0072", "4R3A0073", "4R3A0074", "4R3A0075", "4R3A0076"])
|
||||
logger.info(f"vid test= {vid_test} \nvalid= {vid_valid}")
|
||||
logger.info(f"vid train= {vid_train}")
|
||||
else:
|
||||
vid_test = set(["4R3A0063", "4R3A0071"])
|
||||
vid_valid = set(["4R3A0063", "4R3A0071"])
|
||||
vid_train = vids - vid_test - vid_valid
|
||||
logger.info(f"vid test= {vid_test} \nvalid= {vid_valid}")
|
||||
logger.info(f"vid train= {vid_train}")
|
||||
|
||||
|
||||
# for each video
|
||||
data_train, data_valid, data_test = {}, {}, {}
|
||||
list_train, list_valid, list_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 > 6: break
|
||||
logger.info(f"\n\n processing the {i}-th video {vid} ... ")
|
||||
|
||||
ipath_info = ipath_data.joinpath("video/info.json")
|
||||
ipath_coeff = ipath_data.joinpath("DECA_coeff") # DECA coeff of shape/exp/light
|
||||
ipath_frame = ipath_data.joinpath("frames_crop_512") # cropped image 512x512
|
||||
ipath_ldmks = ipath_data.joinpath("frames_crop_ldmks_512") # cropped landmarks within 512x512
|
||||
ipath_parse = ipath_data.joinpath("frames_crop_parse_512") # cropped mask
|
||||
ipath_speech = ipath_data.joinpath("audio/audio_trim.wav") # audio path
|
||||
|
||||
# check info existing
|
||||
if not ipath_info.exists():
|
||||
logger.info(f"NOT existing {ipath_info}")
|
||||
continue
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_info), "r") as f:
|
||||
info = json.load(f)
|
||||
fps = info["fps"]
|
||||
nframes = info['nframes']
|
||||
assert fps == 50, "fps should be 50"
|
||||
logger.info(f"info={info}, duration = {nframes/fps}")
|
||||
|
||||
|
||||
# check files total exists
|
||||
num_coeff = len(list(ipath_coeff.glob("*.npy")))
|
||||
num_frame = len(list(ipath_frame.glob("*.jpg")))
|
||||
num_ldmks = len(list(ipath_ldmks.glob("*.txt")))
|
||||
num_parse = len(list(ipath_parse.glob("*.npy")))
|
||||
|
||||
if (num_coeff != nframes) or (num_frame != nframes) or (num_ldmks != nframes) or (num_parse != nframes):
|
||||
logger.info(f"num of ipath_coeff ({num_coeff}) shoud be {nframes} > {ipath_coeff}")
|
||||
logger.info(f"num of ipath_frame ({num_frame}) shoud be {nframes} > {ipath_frame}")
|
||||
logger.info(f"num of ipath_ldmks ({num_ldmks}) shoud be {nframes} > {ipath_ldmks}")
|
||||
logger.info(f"num of ipath_parse ({num_parse}) shoud be {nframes} > {ipath_parse}")
|
||||
continue
|
||||
|
||||
# load raw audio
|
||||
audio_raw, sample_rate = torchaudio.load(ipath_speech)
|
||||
logger.info(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()
|
||||
logger.info(f"audio_raw shape = {audio_raw.shape}, sr = {16000}, duration = {(len(audio_raw)/16000)}")
|
||||
|
||||
|
||||
if vid in vid_train:
|
||||
durations_train += nframes/fps
|
||||
list_train.append(vid)
|
||||
|
||||
data_train[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_speech": audio_raw,
|
||||
"path_data": str(ipath_data)
|
||||
}
|
||||
|
||||
if vid in vid_valid:
|
||||
durations_valid += nframes/fps
|
||||
list_valid.append(vid)
|
||||
|
||||
data_valid[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_speech": audio_raw,
|
||||
"path_data": str(ipath_data)
|
||||
}
|
||||
|
||||
|
||||
if vid in vid_test:
|
||||
durations_test += nframes/fps
|
||||
list_test.append(vid)
|
||||
|
||||
data_test[vid] = {
|
||||
"fps": info["fps"],
|
||||
"sr": 16000,
|
||||
"nframe": nframes,
|
||||
"data_speech": audio_raw,
|
||||
"path_data": str(ipath_data)
|
||||
}
|
||||
|
||||
logger.info(f"Total frames: data_train ({durations_train/60:.2f} min) ({durations_train/3600:.2f} h) , ids = ({len(data_train)})")
|
||||
logger.info(f"Total frames: data_valid ({durations_valid/60:.2f} min) ({durations_valid/3600:.2f} h) , ids = ({len(data_valid)})")
|
||||
logger.info(f"Total frames: data_test ({durations_test/60:.2f} min) ({durations_test/3600:.2f} h) , ids = ({len(data_test)})")
|
||||
|
||||
logger.info(f"actual train ID: > {list_train} ")
|
||||
logger.info(f"actual valid ID: > {list_valid} ")
|
||||
logger.info(f"actual test ID: > {list_test} ")
|
||||
|
||||
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)
|
||||
|
||||
logger.info(f"--> {path_save}")
|
||||
Reference in new issue
Block a user