-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtryhw0.py
44 lines (36 loc) · 1.14 KB
/
tryhw0.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
from uwnet import *
mnist = 1
inputs = 784 if mnist else 3072
def softmax_model():
l = [make_connected_layer(inputs, 10),
make_activation_layer(SOFTMAX)]
return make_net(l)
def neural_net():
l = [ make_connected_layer(inputs, 32),
make_activation_layer(RELU),
make_connected_layer(32, 10),
make_activation_layer(SOFTMAX)]
return make_net(l)
print("loading data...")
if mnist:
train = load_image_classification_data("mnist/mnist.train", "mnist/mnist.labels")
test = load_image_classification_data("mnist/mnist.test", "mnist/mnist.labels")
else:
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 = 5000
rate = .01
momentum = .9
decay = .0
m = softmax_model()
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))