-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_data_processor.py
More file actions
28 lines (22 loc) · 862 Bytes
/
train_data_processor.py
File metadata and controls
28 lines (22 loc) · 862 Bytes
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
import numpy as np
from feature_creator import create_features
from frame import Frame
def prepare_features_labels(filename_label_list, alphabet, k):
feature_list = []
label_list = []
for filename, label in filename_label_list:
frames = read_train_frames(filename)
label_list += [np.zeros(len(frames)) if label == 0 else np.ones(len(frames))]
feature_list += [create_features(frames, alphabet=alphabet, k=k)]
train_features = np.concatenate(feature_list)
train_labels = np.concatenate(label_list)
return train_features, train_labels
def read_train_frames(file_path):
with open(file_path, "r") as f:
frames = []
should_read = 0
for line in f:
if should_read:
frames += [Frame(sequence=line[:-1], begin=0)]
should_read ^= 1
return frames