forked from dorajam/Convolutional-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
67 lines (53 loc) · 1.82 KB
/
run.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
62
63
64
65
66
67
# Dora Jambor
# May 2016, run.py
# Use this to setup the convolutional network
import mnist_loader
from toy import *
from backprop import *
import collections
######################### TEST IMAGE ##########################
import scipy
from scipy import ndimage, misc
import matplotlib.pyplot as plt
# im = scipy.ndimage.imread('images/cat.jpg', flatten=True)
# a = im.shape[0]
# b= im.shape[1]
# cat = scipy.misc.imresize(im, (a/40,b/40), interp='bilinear', mode=None)
# # normalize
# cat = 1.0 - cat/255.0
######################### TEST IMAGE ##########################
ETA = 1.5
EPOCHS = 30
INPUT_SHAPE = (28*28) # for mnist
BATCH_SIZE = 10
LMBDA = 0.1
# import ipdb; ipdb.set_trace()
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
'''
Args:
Convolutional Layer: filter_size, stride, padding, num_filters
Pooling Layer: poolsize
Fully Connected Layer: num_output, classify = True/False, num_classes (if classify True)
Gradient Descent: training data, batch_size, eta, num_epochs, lambda, test_data
'''
# training_data = cat.reshape((1,43,64))
# input_shape = training_data.shape
# label = np.asarray(([1,0])).reshape((2,1))
# training_data = (training_data, label)
x,y = training_data[0][0].shape
input_shape = (1,x,y)
print 'shape of input data: ', input_shape
net = Model(input_shape,
layer_config = [
{'conv_layer': {
'filter_size' : 5,
'stride' : 1,
'num_filters' : 20}},
{'pool_layer': {
'poolsize' : (2,2)}},
{'fc_layer': {
'num_output' : 30}},
{'final_layer': {
'num_classes' : 10}}
])
net.gradient_descent(training_data, BATCH_SIZE, ETA, EPOCHS, LMBDA, test_data = test_data[:20])