-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmotion.py
More file actions
91 lines (73 loc) · 2.15 KB
/
motion.py
File metadata and controls
91 lines (73 loc) · 2.15 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Mocap data
# See: http://www.uoguelph.ca/~gwtaylor/publications/nips2006mhmublv/code.html
#
# Download:
# http://www.uoguelph.ca/~gwtaylor/publications/nips2006mhmublv/motion.mat
#
# Data originally from Eugene Hsu, MIT.
# http://people.csail.mit.edu/ehsu/work/sig05stf/
#
# @author Graham Taylor, Kei Taneishi
import numpy as np
from numpy import arange
import scipy.io
import theano
def preprocess_data(Motion):
n_seq = Motion.shape[1]
# assume data is MIT format for now
indx = np.r_[
arange(0,6),
arange(6,9),
13,
arange(18,21),
25,
arange(30,33),
37,
arange(42,45),
49,
arange(54,57),
arange(60,63),
arange(66,69),
arange(72,75),
arange(78,81),
arange(84,87),
arange(90,93),
arange(96,99),
arange(102,105)]
row1 = Motion[0,0][0]
offsets = np.r_[
row1[None,9:12],
row1[None,15:18],
row1[None,21:24],
row1[None,27:30],
row1[None,33:36],
row1[None,39:42],
row1[None,45:48],
row1[None,51:54],
row1[None,57:60],
row1[None,63:66],
row1[None,69:72],
row1[None,75:78],
row1[None,81:84],
row1[None,87:90],
row1[None,93:96],
row1[None,99:102],
row1[None,105:108]]
# collapse sequences
batchdata = np.concatenate([m[:, indx] for m in Motion.flat], axis=0)
data_mean = batchdata.mean(axis=0)
data_std = batchdata.std(axis=0)
batchdata = (batchdata - data_mean) / data_std
# get sequence lengths
seqlen = [s.shape[0] for s in Motion.flat]
return batchdata, seqlen, data_mean, data_std
def load_data(filename):
# load data post preprocess1
mat_dict = scipy.io.loadmat(filename)
Motion = mat_dict['Motion']
batchdata, seqlen, data_mean, data_std = preprocess_data(Motion)
# put data into shared memory
shared_x = theano.shared(np.asarray(batchdata, dtype=theano.config.floatX))
return shared_x, seqlen, data_mean, data_std
if __name__ == "__main__":
batchdata, seqlen, data_mean, data_std = load_data('./data/motion.mat')