forked from EricGuo5513/HumanML3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal_mean_variance.py
54 lines (45 loc) · 1.97 KB
/
cal_mean_variance.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
46
47
48
49
50
51
52
53
54
import numpy as np
import sys
import os
from os.path import join as pjoin
# root_rot_velocity (B, seq_len, 1)
# root_linear_velocity (B, seq_len, 2)
# root_y (B, seq_len, 1)
# ric_data (B, seq_len, (joint_num - 1)*3)
# rot_data (B, seq_len, (joint_num - 1)*6)
# local_velocity (B, seq_len, joint_num*3)
# foot contact (B, seq_len, 4)
def mean_variance(data_dir, save_dir, joints_num):
file_list = os.listdir(data_dir)
data_list = []
for file in file_list:
data = np.load(pjoin(data_dir, file))
if np.isnan(data).any():
print(file)
continue
data_list.append(data)
data = np.concatenate(data_list, axis=0)
print(data.shape)
Mean = data.mean(axis=0)
Std = data.std(axis=0)
Std[0:1] = Std[0:1].mean() / 1.0
Std[1:3] = Std[1:3].mean() / 1.0
Std[3:4] = Std[3:4].mean() / 1.0
Std[4: 4+(joints_num - 1) * 3] = Std[4: 4+(joints_num - 1) * 3].mean() / 1.0
Std[4+(joints_num - 1) * 3: 4+(joints_num - 1) * 9] = Std[4+(joints_num - 1) * 3: 4+(joints_num - 1) * 9].mean() / 1.0
Std[4+(joints_num - 1) * 9: 4+(joints_num - 1) * 9 + joints_num*3] = Std[4+(joints_num - 1) * 9: 4+(joints_num - 1) * 9 + joints_num*3].mean() / 1.0
Std[4 + (joints_num - 1) * 9 + joints_num * 3: ] = Std[4 + (joints_num - 1) * 9 + joints_num * 3: ].mean() / 1.0
assert 8 + (joints_num - 1) * 9 + joints_num * 3 == Std.shape[-1]
np.save(pjoin(save_dir, 'Mean.npy'), Mean)
np.save(pjoin(save_dir, 'Std.npy'), Std)
return Mean, Std
# The given data is used to double check if you are on the right track.
reference1 = np.load('./HumanML3D/Mean.npy')
reference2 = np.load('./HumanML3D/Std.npy')
if __name__ == '__main__':
data_dir = './HumanML3D/new_joint_vecs/'
save_dir = './HumanML3D/'
mean, std = mean_variance(data_dir, save_dir, 22)
### Check if your data is correct. If it's aligned with the given reference, then it is right
print(abs(mean-reference1).sum())
print(abs(std-reference2).sum())