This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
forked from pjreddie/uwnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tryhw2.py
49 lines (42 loc) · 1.59 KB
/
tryhw2.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
from uwnet import *
def conv_net():
l = [ make_convolutional_layer(32, 32, 3, 8, 3, 2),
make_activation_layer(RELU),
make_maxpool_layer(16, 16, 8, 3, 2),
make_convolutional_layer(8, 8, 8, 16, 3, 1),
make_batchnorm_layer(8),
make_activation_layer(RELU),
make_maxpool_layer(8, 8, 16, 3, 2),
make_convolutional_layer(4, 4, 16, 32, 3, 1),
make_batchnorm_layer(16),
make_activation_layer(RELU),
make_connected_layer(512, 10),
make_activation_layer(SOFTMAX)]
return make_net(l)
print("loading data...")
train = load_image_classification_data("cifar/cifar.train", "cifar/cifar.labels")
test = load_image_classification_data("cifar/cifar.test", "cifar/cifar.labels")
print("done")
print
print("making model...")
batch = 128
iters = 100
rate = .01
momentum = .9
decay = .005
m = conv_net()
print("training...")
train_image_classifier(m, train, batch, iters, rate, momentum, decay)
print("done")
print
print("evaluating model...")
print("training accuracy: %f", accuracy_net(m, train))
print("test accuracy: %f", accuracy_net(m, test))
# 7.6 Question: What do you notice about training the convnet with/without batch normalization0?
# How does it affect convergence? How does it affect what magnitude of learning rate you can use?
# Write down any observations from your experiments:
# TODO: Your answer
"""
With batch normalization, the convergence becomes much faster. With a batch normalization,
we can use higher learning rates, which would accelerate the learning as well.
"""