-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathutils.py
42 lines (33 loc) · 1.33 KB
/
utils.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
import os
import numpy as np
eps = np.finfo(np.float).eps
def create_folder(_fold_path):
if not os.path.exists(_fold_path):
os.makedirs(_fold_path)
def reshape_3Dto2D(A):
return A.reshape(A.shape[0] * A.shape[1], A.shape[2])
def split_multi_channels(data, num_channels):
in_shape = data.shape
if len(in_shape) == 3:
hop = in_shape[2] // num_channels
tmp = np.zeros((in_shape[0], num_channels, in_shape[1], hop))
for i in range(num_channels):
tmp[:, i, :, :] = data[:, :, i * hop:(i + 1) * hop]
else:
print("ERROR: The input should be a 3D matrix but it seems to have dimensions ", in_shape)
exit()
return tmp
def split_in_seqs(data, subdivs):
if len(data.shape) == 1:
if data.shape[0] % subdivs:
data = data[:-(data.shape[0] % subdivs), :]
data = data.reshape((data.shape[0] // subdivs, subdivs, 1))
elif len(data.shape) == 2:
if data.shape[0] % subdivs:
data = data[:-(data.shape[0] % subdivs), :]
data = data.reshape((data.shape[0] // subdivs, subdivs, data.shape[1]))
elif len(data.shape) == 3:
if data.shape[0] % subdivs:
data = data[:-(data.shape[0] % subdivs), :, :]
data = data.reshape((data.shape[0] // subdivs, subdivs, data.shape[1], data.shape[2]))
return data