[665646]: / dataset / create_augmented_dataset.py

Download this file

32 lines (21 with data), 1.1 kB

 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
import numpy as np
def create_augmented_dataset(raw_dataset, window_size = 512, stride = 64, verbose=False):
augmented_dataset = { }
for s,Xset_raw in raw_dataset.items():
if (verbose):
print('Processing set ' + s)
total_points = Xset_raw.shape[1]
# no. of examples generated from single training example using sliding window
# = floor((total_points - window_size) / stride) + 1
iterations = ((total_points - window_size) // stride) + 1
for x_raw in Xset_raw:
for i in range(iterations):
window_slice_from = i*stride
window_slice_to = i*stride + window_size
if (s in augmented_dataset):
augmented_dataset[s] = np.append(augmented_dataset[s], [x_raw[window_slice_from:window_slice_to]], axis=0)
else:
augmented_dataset[s] = np.array([x_raw[window_slice_from:window_slice_to]])
if (verbose):
print('Done.')
return augmented_dataset