-
Notifications
You must be signed in to change notification settings - Fork 51
/
compute_statistics.py
97 lines (85 loc) · 2.9 KB
/
compute_statistics.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
import os
from utils.util import get_files
from tqdm import tqdm
from utils.util import remove_outlier
from utils.hparams import HParam
if __name__ == "__main__":
hp = HParam("./configs/default.yaml")
min_e = []
min_p = []
max_e = []
max_p = []
nz_min_p = []
nz_min_e = []
energy_path = os.path.join(hp.data.data_dir, "energy")
pitch_path = os.path.join(hp.data.data_dir, "pitch")
mel_path = os.path.join(hp.data.data_dir, "mels")
energy_files = get_files(energy_path, extension=".npy")
pitch_files = get_files(pitch_path, extension=".npy")
mel_files = get_files(mel_path, extension=".npy")
assert len(energy_files) == len(pitch_files) == len(mel_files)
energy_vecs = []
for f in tqdm(energy_files):
e = np.load(f)
e = remove_outlier(e)
energy_vecs.append(e)
min_e.append(e.min())
nz_min_e.append(e[e > 0].min())
max_e.append(e.max())
nonzeros = np.concatenate([v[np.where(v != 0.0)[0]] for v in energy_vecs])
e_mean, e_std = np.mean(nonzeros), np.std(nonzeros)
print("Non zero Min Energy : {}".format(min(nz_min_e)))
print("Max Energy : {}".format(max(max_e)))
print("Energy mean : {}".format(e_mean))
print("Energy std: {}".format(e_std))
pitch_vecs = []
bad_pitch = []
for f in tqdm(pitch_files):
# print(f)
p = np.load(f)
p = remove_outlier(p)
pitch_vecs.append(p)
# print(len(p), "#########", p)
try:
min_p.append(p.min())
nz_min_p.append(p[p > 0].min())
max_p.append(p.max())
except ValueError:
bad_pitch.append(f)
nonzeros = np.concatenate([v[np.where(v != 0.0)[0]] for v in pitch_vecs])
f0_mean, f0_std = np.mean(nonzeros), np.std(nonzeros)
print("Min Pitch : {}".format(min(min_p)))
print("Non zero Min Pitch : {}".format(min(nz_min_p)))
print("Max Pitch : {}".format(max(max_p)))
print("Pitch mean : {}".format(f0_mean))
print("Pitch std: {}".format(f0_std))
np.save(
os.path.join(hp.data.data_dir, "e_mean.npy"),
e_mean.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data.data_dir, "e_std.npy"),
e_std.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data.data_dir, "f0_mean.npy"),
f0_mean.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data.data_dir, "f0_std.npy"),
f0_std.astype(np.float32),
allow_pickle=False,
)
print("The len of bad Pitch Vectors is ", len(bad_pitch))
# print(bad_pitch)
with open("bad_file.txt", "a") as f:
for i in bad_pitch:
c = i.split("/")[3].split(".")[0]
f.write(c)
f.write("\n")
# print("Min Energy : {}".format(min(min_e)))
# print("Min Pitch : {}".format(min(min_p)))