Yesterday’s failure brings today’s success. Sometimes you need to stop, take a look at the problem from another angle, and refer back to a working solution. The working solution I referred to is craffel@github’s Lasagne Tutorial.
Debugging yesterday’s error
In getting a convolutional neural network (CNN) to run, I realized the format of my input data was incorrectly specified. Originally, the data was formatted as a matrix (features along the columns and samples along the rows). The correct format is a nested data structure: dataset[sample][channel][row][column]
.
# Here is an example of the first sample in the correct format
# Data is found in only 1 "channel"
# (eg. notice the 2x square brackets before the first list of data)
array([[ [ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
...,
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.] ]], dtype=float32)
Another problem I discovered was that when specifying the input layer’s shape
, an error is returned if I specify the number of examples (n_examples), but no error is returned when None
is used.
l_in = lasagne.layers.InputLayer(
shape=(n_examples, n_channels, width, height))
Script: 5 main sections to make & run a CNN
- Load the data
- Define the CNN network structure
- Define the learning
(eg. what the error function is and how the network gets updated) - Define the classification/get output function
(for computing the network’s output given an input) - Do the training