-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing.py
More file actions
52 lines (45 loc) · 1.5 KB
/
Copy pathpreprocessing.py
File metadata and controls
52 lines (45 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
import csv
import logging
import numpy as np
activity_mapping = {
1 : 0,
2 : 1,
4 : 2,
5 : 3,
6 : 4,
8 : 5}
def get_id_offset(id_str):
ids = map(int, id_str.split('+'))
return max(ids) - min(ids)
def get_id_max(id_str):
ids = map(int, id_str.split('+'))
return max(ids)
def load_au_file(fname, num_classes=6, num_feats=3):
rows = []
with open(fname, newline='') as csvfile:
aureader = csv.DictReader(csvfile, delimiter='\t')
rows = [row for row in aureader]
logging.info('Read {0} data rows'.format(len(rows)))
Labels = np.zeros((len(rows), num_classes))
Features = np.zeros((len(rows), num_feats))
prev_maximum_src = 1
prev_maximum_trg = 1
for i, row in enumerate(rows):
activity_id = int(row['Type'])
Labels[i, activity_mapping[activity_id]] = 1.0
# Features: Dur STid TTid
Features[i, 0] = float(row['Dur'])
Features[i, 1] = get_id_max(row['STid']) - prev_maximum_src
prev_maximum_src = get_id_max(row['STid'])
Features[i, 2] = get_id_max(row['TTid']) - prev_maximum_trg
prev_maximum_trg = get_id_max(row['TTid'])
# Labels = np.delete(Labels, [0], axis=0)
# Features = np.delete(Features, [-1], axis=0)
Labels = Labels[1:,:]
Features = Features[:-1,:]
return Features, Labels
def print_model_architecture(model, fname):
with open(fname, 'w') as fh:
model.summary(print_fn=lambda x: fh.write(x + '\n'))
return