-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtomato_model_dn.jl
73 lines (52 loc) · 2.82 KB
/
tomato_model_dn.jl
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
using Mocha
data_tr_layer = HDF5DataLayer(name="data-train", source="train.txt", batch_size=1, shuffle=true)
data_tt_layer = HDF5DataLayer(name="data-test", source="test.txt", batch_size=1)
conv1_layer = ConvolutionLayer(name="conv1", n_filter=32, kernel=(5,5), pad=(2,2),
stride=(1,1), filter_init=GaussianInitializer(std=0.0001),
bottoms=[:data], tops=[:conv1])
pool1_layer = PoolingLayer(name="pool1", kernel=(3,3), stride=(2,2), neuron=Neurons.ReLU(),
bottoms=[:conv1], tops=[:pool1])
norm1_layer = LRNLayer(name="norm1", kernel=3, scale=5e-5, power=0.75, mode=LRNMode.AcrossChannel(),
bottoms=[:pool1], tops=[:norm1])
conv2_layer = ConvolutionLayer(name="conv2", n_filter=32, kernel=(5,5), pad=(2,2),
stride=(1,1), filter_init=GaussianInitializer(std=0.01),
bottoms=[:norm1], tops=[:conv2], neuron=Neurons.ReLU())
pool2_layer = PoolingLayer(name="pool2", kernel=(3,3), stride=(2,2), pooling=Pooling.Mean(),
bottoms=[:conv2], tops=[:pool2])
norm2_layer = LRNLayer(name="norm2", kernel=3, scale=5e-5, power=0.75, mode=LRNMode.AcrossChannel(),
bottoms=[:pool2], tops=[:norm2])
conv3_layer = ConvolutionLayer(name="conv3", n_filter=64, kernel=(5,5), pad=(2,2),
stride=(1,1), filter_init=GaussianInitializer(std=0.01),
bottoms=[:norm2], tops=[:conv3], neuron=Neurons.ReLU())
pool3_layer = PoolingLayer(name="pool3", kernel=(3,3), stride=(2,2), pooling=Pooling.Mean(),
bottoms=[:conv3], tops=[:pool3])
ip1_layer = InnerProductLayer(name="ip1", output_dim=10, weight_init=GaussianInitializer(std=0.01),
weight_regu=L2Regu(250), bottoms=[:pool3], tops=[:ip1])
loss_layer = SoftmaxLossLayer(name="softmax", bottoms=[:ip1, :label])
acc_layer = AccuracyLayer(name="accuracy", bottoms=[:ip1, :label])
common_layers = [conv1_layer, pool1_layer, norm1_layer, conv2_layer, pool2_layer, norm2_layer,
conv3_layer, pool3_layer, ip1_layer]
backend = DefaultBackend()
init(backend)
net = Net("TOMATO-train", backend, [data_tr_layer, common_layers..., loss_layer])
lr_policy = LRPolicy.Staged(
(300, LRPolicy.Fixed(0.001)),
(240, LRPolicy.Fixed(0.0001)),
(240, LRPolicy.Fixed(0.00001)),
)
method = SGD()
solver_params = make_solver_parameters(method, max_iter=70000,
regu_coef=0.004, mom_policy=MomPolicy.Fixed(0.9), lr_policy=lr_policy,
load_from="snapshots")
solver = Solver(method, solver_params)
# report training progress every 200 iterations
add_coffee_break(solver, TrainingSummary(), every_n_iter=200)
# save snapshots every 5000 iterations
add_coffee_break(solver, Snapshot("snapshots"), every_n_iter=5000)
# show performance on test data every 1000 iterations
test_net = Net("TOMATO-test", backend, [data_tt_layer, common_layers..., acc_layer])
add_coffee_break(solver, ValidationPerformance(test_net), every_n_iter=1000)
solve(solver, net)
destroy(net)
destroy(test_net)
shutdown(backend)