-
Notifications
You must be signed in to change notification settings - Fork 4
/
tryhw4.py
35 lines (29 loc) · 902 Bytes
/
tryhw4.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
import sys
sys.dont_write_bytecode = True
from uwimg import *
def softmax_model(inputs, outputs):
l = [make_layer(inputs, outputs, SOFTMAX)]
return make_model(l)
def neural_net(inputs, outputs):
print(inputs)
l = [ make_layer(inputs, 32, LOGISTIC),
make_layer(32, outputs, SOFTMAX)]
return make_model(l)
print("loading data...")
train = load_classification_data(b"mnist.train", b"mnist.labels", 1)
test = load_classification_data(b"mnist.test", b"mnist.labels", 1)
print("done")
print
print("training model...")
batch = 128
iters = 1000
rate = .01
momentum = .9
decay = .0
m = softmax_model(train.X.cols, train.y.cols)
train_model(m, train, batch, iters, rate, momentum, decay)
print("done")
print
print("evaluating model...")
print("training accuracy: %0.2f %%"%(100*accuracy_model(m, train)))
print("test accuracy: %0.2f %%"%(100*accuracy_model(m, test)))