-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_analysis_swap_dropout.py
118 lines (94 loc) · 3.15 KB
/
run_analysis_swap_dropout.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
To use this script:
> python run_analysis.py fit
This will save the output to net-specialists.pickle
-OR-
> python run_analysis.py fit name.pickle
This will save the output to name.pickle
"""
from helpers import *
from reshape import *
net = NeuralNet(
layers=[
('input', layers.InputLayer),
('conv1', Conv2DLayer),
('pool1', MaxPool2DLayer),
('dropout1', layers.DropoutLayer),
('conv2', Conv2DLayer),
('pool2', MaxPool2DLayer),
('dropout2', layers.DropoutLayer),
('conv3', Conv2DLayer),
('pool3', MaxPool2DLayer),
('dropout3', layers.DropoutLayer),
('conv4', Conv2DLayer),
('pool4', MaxPool2DLayer),
('dropout4', layers.DropoutLayer),
('hidden5', layers.DenseLayer),
('maxout5', Maxout),
('dropout5', layers.DropoutLayer),
('hidden6', layers.DenseLayer),
('maxout6', Maxout),
('dropout6', layers.DropoutLayer),
('output', layers.DenseLayer),
],
input_shape=(None, 1, PIXELS, PIXELS),
conv1_num_filters=208, conv1_filter_size=(6, 6), pool1_ds=(2, 2),
dropout1_p=0.2,
conv2_num_filters=384, conv2_filter_size=(4, 4), pool2_ds=(2, 2),
dropout2_p=0.2,
conv3_num_filters=512, conv3_filter_size=(3, 3), pool3_ds=(2, 2),
dropout3_p=0.2,
conv4_num_filters=896, conv4_filter_size=(3, 3), pool4_ds=(2, 2),
dropout4_p=0.2,
hidden5_num_units=8192,
maxout5_ds=2,
dropout5_p=0.5,
hidden6_num_units=8192,
maxout6_ds=2,
dropout6_p=0.5,
output_num_units=121,
output_nonlinearity=nonlinearities.softmax,
update_learning_rate=theano.shared(float32(0.03)),
update_momentum=theano.shared(float32(0.9)),
regression=False,
batch_iterator_train=DataAugmentationBatchIterator(batch_size=128),
batch_iterator_test=BatchIterator(batch_size=128),
on_epoch_finished=[
AdjustVariable_custom('update_learning_rate', start=0.03, stop=0.001),
],
max_epochs=70,
verbose=1,
eval_size=0.0
)
def fit(output='net-specialists.pickle', fname_pretrain=None):
if fname_pretrain:
print "Using Pretrainig:",fname_pretrain
with open(fname_pretrain, 'rb') as f:
net_pretrain = pickle.load(f)
else:
net_pretrain = None
specialists = OrderedDict()
print "Saving Output to:", output
print "Running for Pixels = ",PIXELS
for setting in SPECIALIST_SETTINGS:
cols = setting['columns']
#X, y = load2d(cols=cols)
X, y = load2d()
model = clone(net)
if 'kwargs' in setting:
vars(model).update(setting['kwargs'])
if net_pretrain is not None:
print "GONNA LOAD>......"
model.load_weights_from(net_pretrain)
print("Training model for columns {} for {} epochs".format(
cols, model.max_epochs))
model.fit(X, y)
specialists[cols] = model
with open(output, 'wb') as f:
pickle.dump(specialists, f, -1)
if __name__ == '__main__':
if len(sys.argv) < 2:
print(__doc__)
else:
func = globals()[sys.argv[1]]
func(*sys.argv[2:])