MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / evaluate_lenet5

Function evaluate_lenet5

code/convolutional_mlp.py:120–342  ·  view source on GitHub ↗

Demonstrates lenet on MNIST dataset :type learning_rate: float :param learning_rate: learning rate used (factor for the stochastic gradient) :type n_epochs: int :param n_epochs: maximal number of epochs to run the optimizer :type dataset: string

(learning_rate=0.1, n_epochs=200,
                    dataset='mnist.pkl.gz',
                    nkerns=[20, 50], batch_size=500)

Source from the content-addressed store, hash-verified

118
119
120def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
121 dataset='mnist.pkl.gz',
122 nkerns=[20, 50], batch_size=500):
123 """ Demonstrates lenet on MNIST dataset
124
125 :type learning_rate: float
126 :param learning_rate: learning rate used (factor for the stochastic
127 gradient)
128
129 :type n_epochs: int
130 :param n_epochs: maximal number of epochs to run the optimizer
131
132 :type dataset: string
133 :param dataset: path to the dataset used for training /testing (MNIST here)
134
135 :type nkerns: list of ints
136 :param nkerns: number of kernels on each layer
137 """
138
139 rng = numpy.random.RandomState(23455)
140
141 datasets = load_data(dataset)
142
143 train_set_x, train_set_y = datasets[0]
144 valid_set_x, valid_set_y = datasets[1]
145 test_set_x, test_set_y = datasets[2]
146
147 # compute number of minibatches for training, validation and testing
148 n_train_batches = train_set_x.get_value(borrow=True).shape[0]
149 n_valid_batches = valid_set_x.get_value(borrow=True).shape[0]
150 n_test_batches = test_set_x.get_value(borrow=True).shape[0]
151 n_train_batches //= batch_size
152 n_valid_batches //= batch_size
153 n_test_batches //= batch_size
154
155 # allocate symbolic variables for the data
156 index = T.lscalar() # index to a [mini]batch
157
158 # start-snippet-1
159 x = T.matrix('x') # the data is presented as rasterized images
160 y = T.ivector('y') # the labels are presented as 1D vector of
161 # [int] labels
162
163 ######################
164 # BUILD ACTUAL MODEL #
165 ######################
166 print('... building the model')
167
168 # Reshape matrix of rasterized images of shape (batch_size, 28 * 28)
169 # to a 4D tensor, compatible with our LeNetConvPoolLayer
170 # (28, 28) is the size of MNIST images.
171 layer0_input = x.reshape((batch_size, 1, 28, 28))
172
173 # Construct the first convolutional pooling layer:
174 # filtering reduces the image size to (28-5+1 , 28-5+1) = (24, 24)
175 # maxpooling reduces this further to (24/2, 24/2) = (12, 12)
176 # 4D output tensor is thus of shape (batch_size, nkerns[0], 12, 12)
177 layer0 = LeNetConvPoolLayer(

Callers 2

experimentFunction · 0.85

Calls 6

errorsMethod · 0.95
load_dataFunction · 0.90
HiddenLayerClass · 0.90
LogisticRegressionClass · 0.90
LeNetConvPoolLayerClass · 0.85

Tested by

no test coverage detected