initial commit
This commit is contained in:
commit
c7175dd7ff
127 files changed
+13949
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import torch
|
||||
import numpy as np
|
||||
from pathlib2 import Path
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
path_data = Path('/mnt/data2/DATA/Obama/processing/processing') # '../data/trinity/source'
|
||||
|
||||
v_dir_videos = sorted(path_data.glob("*"))
|
||||
print(f"Have {len(v_dir_videos)} dir files")
|
||||
|
||||
# set windows
|
||||
nwin_train_secs = 2 # 6, 2
|
||||
overlap = 0.8
|
||||
fps = 30
|
||||
|
||||
# for each video
|
||||
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_exp = ipath_data.joinpath("audio/feat_DECA_exp_trim.npy")
|
||||
ipath_pos = ipath_data.joinpath("audio/feat_DECA_pos_trim.npy")
|
||||
ipath_idn = ipath_data.joinpath("audio/feat_DECA_idn_trim.npy")
|
||||
|
||||
ipath_save = ipath_data.joinpath("audio/feat_DECA_trim_split_2s.npy") # feat_mel_trim_split
|
||||
|
||||
if not ipath_exp.exists() or not ipath_pos.exists() or not ipath_idn.exists():
|
||||
print(f"ERROR: NOT Exist {ipath_exp} or {ipath_pos} or {ipath_idn}" )
|
||||
continue
|
||||
|
||||
print(f"\n processing {ivideo_name} ... ")
|
||||
|
||||
# load video info
|
||||
with open(str(ipath_infors), "r") as f:
|
||||
info = json.load(f)
|
||||
width = info["width"][0] # 1280 or 1920
|
||||
height = info["height"][0] # 720 or 1080
|
||||
print("\nwidth=",width, "height=",height, "fps=",info["fps"], "-->", ipath_data)
|
||||
|
||||
# fps = info["fps"]
|
||||
if len(info["active_frames"]) == 2:
|
||||
ibeg = info["active_frames"][0]
|
||||
iend = info["active_frames"][1]
|
||||
nframe_trim = iend - ibeg
|
||||
# print(f"frame trim = {nframe_trim}, info['active_frames'] = {info['active_frames']}")
|
||||
else:
|
||||
print(f"ERROR: info['active_frames'] = {info['active_frames']}")
|
||||
continue
|
||||
|
||||
|
||||
feat_idn = np.load(ipath_idn) # (nframe_trim, 100)
|
||||
feat_exp = np.load(ipath_exp) # (nframe_trim, 50)
|
||||
feat_pos = np.load(ipath_pos) # (nframe_trim, 6)
|
||||
feat_3dmm = np.concatenate([feat_idn, feat_exp, feat_pos], axis=1)
|
||||
|
||||
|
||||
if nframe_trim != feat_3dmm.shape[0]:
|
||||
print(f"ERROR: nframe_trim = {nframe_trim} != feat_3dmm len {feat_3dmm.shape[0]}")
|
||||
continue
|
||||
|
||||
# split
|
||||
nsize_split = int( nwin_train_secs * fps )
|
||||
nstep_split = int( nwin_train_secs * fps * (1-overlap) )
|
||||
|
||||
feat_3dmm = torch.from_numpy(feat_3dmm).float()
|
||||
feat_3dmm2 = feat_3dmm.unfold(dimension=0, size=nsize_split, step=nstep_split) # (nframe_trim//30, 136, 30)
|
||||
feat_3dmm2 = feat_3dmm2.permute(0, 2, 1) # (nsplits, nsteps, 136)
|
||||
|
||||
print(f"data feat_3dmm unfold = {feat_3dmm2.shape}")
|
||||
# print(f"check data landmark[32, ::50] = {data_ladmk[62, ::50]}, \n data_ladmk2[1, ::50, 2] = {data_ladmk2[2, ::50, 2]}")
|
||||
print(f"ldmk ==> nsize = {nsize_split}, nstep = {nstep_split}, len = {(nframe_trim - nsize_split) // nstep_split + 1}")
|
||||
|
||||
# save
|
||||
np.save(ipath_save, feat_3dmm2) # (nsplit, 60, 136)
|
||||
print(f"feat_3dmm={feat_3dmm.shape}, feat_3dmm2={feat_3dmm2.shape}, save to -> {ipath_save}") # (nframe, 68, 2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user