forked from lpigou/Theano-3D-ConvNet
/
run.py
93 lines (81 loc) · 2.77 KB
/
run.py
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
92
93
#!/usr/bin/env python2.7
# Copyright 2014 G.K SUDHARSHAN <sudharpun90@gmail.com> IIT Madras
# Copyright 2014 Abil N George<mail@abilng.in> IIT Madras
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
# WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
# MERCHANTABLITY OR NON-INFRINGEMENT.
# See the Apache 2 License for the specific language governing permissions and
# limitations under the License.
import os, time,sys
from cnn import CNN;
import numpy as np
import theano
floatX=theano.config.floatX
hidden_layer_configs = {
"activation": "tanh",
"adv_activation": None,
"do_dropout": False,
"hidden_layers": [100, 200],
"l1_reg": None,
"l2_reg": None,
"max_col_norm": None,
"pretrained_layers": -1
}
conv_layer_configs=[{
"n_in_maps": 3,
"kernel_shape": [3,7, 7],
"video_shape": [7, 60, 40],
"n_out_maps": 6,
"poolsize": [2, 2],
"update": True
},
{
"n_in_maps": 6,
"kernel_shape": [3, 7, 6],
"video_shape": [5, 27, 17],
"n_out_maps": 3,
"poolsize": [3, 3],
"update": True
},
{
"n_in_maps": 3,
"kernel_shape": [1, 7, 4],
"video_shape": [3, 7, 4],
"n_out_maps": 3,
"output_shape": [1,7,4],
"poolsize": [],
"update": True
},
]
batch_size = 10
input_shape = [3, 60, 40];
def random_matrix(shape, np_rng, name=None,type=floatX):
return theano.shared(np.require(np_rng.randn(*shape), dtype=type),
borrow=True, name=name)
# define inputs and filters
in_time = 7
in_channels, in_width, in_height = input_shape;
flt_channels = 10
flt_time = 2
flt_width = 3
flt_height = 4
rng = np.random.RandomState(42)
#(batch, row, column, time, in channel)
train_x = random_matrix((batch_size, in_height, in_width, in_time, in_channels),rng, 'x');
train_y = random_matrix((batch_size,),rng,'y',type=np.dtype('int32'));
valid_x = random_matrix((batch_size, in_height, in_width, in_time, in_channels),rng, 'x');
valid_y = random_matrix((batch_size,),rng,'y',type=np.dtype('int32'));
numpy_rng = np.random.RandomState(89677)
#theano_rng = RandomStreams(numpy_rng.randint(2 ** 30))
cnn = CNN(numpy_rng,batch_size=batch_size, n_outs=10,conv_layer_configs = conv_layer_configs,
hidden_layer_configs=hidden_layer_configs);
train_fn, validate_fn = cnn.build_finetune_functions((train_x,train_y),
(valid_x,valid_y), batch_size=batch_size)