forked from EvelynFan/FaceFormer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_procss.py
45 lines (36 loc) · 1.43 KB
/
data_procss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os, sys
import pickle
import numpy as np
def avg():
npys = {}
root_dir = "/root/mlinxiang/vh_exp/FaceFormer/HDTF/vertices_npy"
for item in os.listdir(root_dir):
if item.endswith(".npy"):
npy_path = os.path.join(root_dir, item)
frames = []
with open(npy_path, "rb") as f:
data = pickle.load(f)
for frame in data:
frames.append(frame['v3d'])
mean_frame = np.mean(frames, axis=0)
npys[item] = np.reshape(mean_frame, (-1))
with open("/root/mlinxiang/vh_exp/FaceFormer/HDTF/templates.pkl", "wb") as f:
pickle.dump(npys, f)
def re_avg():
sub_projs = {}
with open("/root/mlinxiang/vh_exp/FaceFormer/HDTF/templates.pkl", "rb") as f:
npys = pickle.load(f)
for item in npys.keys():
print(item)
name = "_".join(item.split("_")[:-1])
if name in sub_projs:
sub_projs[name].append(npys[item])
else:
sub_projs[name] = [npys[item]]
for item in sub_projs.keys():
projs = sub_projs[item]
sub_projs[item] = np.mean(projs, axis=0)
print(f"projs={len(projs)} shape={sub_projs[item].shape}")
with open("/root/mlinxiang/vh_exp/FaceFormer/HDTF/templates_new.pkl", "wb") as f:
pickle.dump(sub_projs, f)
re_avg()