Files

120 lines
5.3 KiB
Python

import numpy as np
from pathlib import Path
if __name__ == "__main__":
# fid = "Bringing-Our-Workplace-Policies-into-the-21st-Century"
fid = "AA7A9571"
path_root = Path("/mfs/lsen/DATA/Actor2/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/Actor2/DECA_Actor2_mean.npy"
np.save(path_save, mean_DECA)
print("save to --> ", path_save)
print(f"mean deca = \n {mean_DECA}")
# Have 21499 frames
# 'cam': array([ 9.8221273e+00, -9.2755520e-04, 2.8869644e-02], dtype=float32),
# 'pose': array([ 0.04063781, -0.00623041, -0.01067916,
# 0.11206006, 0.00411261, 0.02320058], dtype=float32),
# 'exp': array([-0.6491158 , -0.0998203 , 0.10486019, 0.37043977, -0.29840025,
# -0.41017675, 0.327057 , 0.04885808, -0.06325228, 0.4434316 ,
# 0.05493879, 0.66853815, -0.10403663, 0.01440001, 0.25900015,
# -0.46350944, -0.41076973, -0.10278799, -0.08775225, 0.51222765,
# 0.10053314, -0.26408502, 0.11820181, -0.05676581, 0.02643572,
# 0.16058844, -0.11792275, 0.12630136, -0.23953533, -0.10915831,
# -0.16660552, 0.00958887, 0.2679962 , -0.26946628, 0.19901456,
# -0.09804437, -0.03807065, -0.12970755, 0.01078465, 0.19384004,
# -0.06548703, -0.03329738, 0.11319494, -0.02613433, 0.02363422,
# 0.02380173, -0.11122038, 0.13734889, 0.1255798 , 0.13813666],
# dtype=float32),
# 'shape': array([ 0.00951388, -0.22505675, -0.53953266, -0.4397285 , 0.37905172,
# 0.11540896, -0.36891365, -0.218832 , -0.3684414 , 0.24644622,
# 0.6223965 , -0.16298303, -0.35899413, -0.11834836, -0.04909257,
# -0.13188031, 0.35037243, -0.10429271, 0.25443867, -0.18088193,
# 0.16413063, 0.20566346, 0.0501059 , -0.19294368, -0.00809607,
# -0.08120474, -0.07019995, 0.01174292, 0.33962983, 0.04500978,
# -0.25193816, -0.2265279 , 0.14124256, 0.21158281, -0.09555811,
# 0.14076404, 0.04877019, 0.03229018, -0.00235608, -0.08356833,
# 0.09741616, 0.2644469 , 0.13229795, -0.14537199, -0.2314888 ,
# -0.48501098, -0.13492987, -0.13772976, -0.18299519, -0.11046503,
# 0.04127223, -0.4613573 , -0.06382176, 0.08914807, 0.08793663,
# 0.11848436, 0.03956904, 0.04172374, -0.04793308, 0.30301905,
# -0.06345342, 0.04190513, 0.13665007, -0.03253645, 0.08728135,
# 0.06684338, 0.02282041, 0.00583193, -0.11710295, -0.06365721,
# -0.00492529, -0.14196472, 0.03584495, -0.00815303, -0.00147824,
# 0.2087406 , -0.11037645, -0.04405028, -0.129121 , 0.03147175,
# -0.03467533, -0.00330734, 0.13060835, -0.02846657, 0.05666886,
# -0.07806987, -0.17371002, 0.05375125, -0.04018219, 0.08453278,
# -0.05303599, -0.11419729, -0.16071273, -0.00130347, -0.1172006 ,
# -0.06073425, -0.03826162, -0.0587554 , -0.06399846, -0.14208533],
# dtype=float32)}