-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
61 lines (47 loc) · 2.29 KB
/
runner.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
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
from IPython import embed
from neural_net import NeuralNet
from image_vectorizer import ImageVectorizer
vectorizer = ImageVectorizer()
paths = vectorizer.get_image_paths()
############################################################
################### Assignment Questions ###################
############################################################
############################################################
# Train a feedforward neural network with one hidden layer #
# of size 3 to learn representations of those digits. #
# Try using (a) Linear transform function #
############################################################
net_3lin = NeuralNet(3, 'linear')
net_3lin.train(paths)
weights = net_3lin.input_weights_of_hidden_layer()
vectorizer.vectors_to_images(weights, '3_hidden_layer_linear')
############################################################
# (b) Sigmoid transform function for the hidden layer #
############################################################
net_3sig = NeuralNet(3, 'sigmoid')
net_3sig.train(paths)
weights = net_3sig.input_weights_of_hidden_layer()
vectorizer.vectors_to_images(weights, '3_hidden_layer_sigmoid')
############################################################
# Change the size of hidden layer to 6 and retrain #
############################################################
net_6sig = NeuralNet(6, 'sigmoid')
net_6sig.train(paths)
weights = net_6sig.input_weights_of_hidden_layer()
vectorizer.vectors_to_images(weights, '6_hidden_layer_sigmoid')
############################################################
# Change the size of hidden layer to 9 and retrain #
############################################################
net_9sig = NeuralNet(9, 'sigmoid')
net_9sig.train(paths)
weights = net_9sig.input_weights_of_hidden_layer()
vectorizer.vectors_to_images(weights, '9_hidden_layer_sigmoid')
############################################################
# Change the size of hidden layer to 15 and retrain #
############################################################
net_15sig = NeuralNet(15, 'sigmoid')
net_15sig.train(paths)
weights = net_15sig.input_weights_of_hidden_layer()
vectorizer.vectors_to_images(weights, '15_hidden_layer_sigmoid')