-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
42 lines (34 loc) · 1.08 KB
/
utils.py
File metadata and controls
42 lines (34 loc) · 1.08 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
32
33
34
35
36
37
38
39
40
41
from __future__ import print_function
import numpy as np
def zero_pad(X, seq_len):
return np.array([x[:seq_len - 1] + [0] * max(seq_len - len(x), 1) for x in X])
def zero_pad_test(X, seq_len_div):
diff = seq_len_div - (len(X)%seq_len_div)
return np.concatenate((np.array([x for x in X]),np.zeros((diff,len(X[0])))), axis = 0)
def batch_generator(X, y, batch_size, seq_len = 1):
"""Primitive batch generator
"""
size = X.shape[0]//seq_len
X_copy = X.copy()
y_copy = y.copy()
i = 0
while True:
if i + batch_size <= size:
yield X_copy[i * seq_len:(i + batch_size)* seq_len], y_copy[i:i + batch_size]
i += batch_size
else:
i = 0
continue
def test_batch_generator(X, batch_size, seq_len = 1):
"""Primitive batch generator
"""
size = X.shape[0]//seq_len
X_copy = X.copy()
i = 0
while True:
if i + batch_size <= size:
yield X_copy[i * seq_len:(i + batch_size)* seq_len]
i += batch_size
else:
i = 0
continue