Exercise:Convolution and Pooling

From Ufldl

Jump to: navigation, search
(Step 3a: Convolution)
Line 66: Line 66:
To use <tt>conv2</tt>, you will have to convolve the features with the large images one feature at a time (so you will still need a loop over the features). For every feature, take the matrix <math>W_f</math>, the weights from the input layer to the fth unit in the hidden layer, and convolve it with the large image, using <tt>C = conv2(images, W, 'valid')</tt>. <tt>C = conv2(images, W, 'valid')</tt> performs a ''valid'' convolution (as opposed to a ''full'' convolution, as described earlier) of <tt>W</tt> with <tt>images</tt>, yielding a matrix <tt>C</tt> of convolved features.
To use <tt>conv2</tt>, you will have to convolve the features with the large images one feature at a time (so you will still need a loop over the features). For every feature, take the matrix <math>W_f</math>, the weights from the input layer to the fth unit in the hidden layer, and convolve it with the large image, using <tt>C = conv2(images, W, 'valid')</tt>. <tt>C = conv2(images, W, 'valid')</tt> performs a ''valid'' convolution (as opposed to a ''full'' convolution, as described earlier) of <tt>W</tt> with <tt>images</tt>, yielding a matrix <tt>C</tt> of convolved features.
-
[[File:Convolution_schematic.png|300px]]
+
[[File:Convolution_schematic.gif|300px]]
-
<div style="border:1px solid black">
+
<div style="border:1px solid black; padding: 5px">
'''Implementation tip:''' Using <tt>conv2</tt> and <tt>convn</tt>
'''Implementation tip:''' Using <tt>conv2</tt> and <tt>convn</tt>
Line 117: Line 117:
==== Step 3b: Checking ====
==== Step 3b: Checking ====
 +
 +
We have provided some code for you to check that you have done the convolution correctly. The code randomly checks the convolved values for a number of (feature, row, column) tuples by computing the feature activations for the selected features and patches directly using the sparse autoencoder.
==== Step 3c: Pooling ====
==== Step 3c: Pooling ====
-
Implement pooling in <tt>cnnPool.m</tt>.
+
Implement [[pooling]] in the function <tt>cnnPool</tt> in <tt>cnnPool.m</tt>.
=== Step 4: Use pooled features for classification ===
=== Step 4: Use pooled features for classification ===
 +
 +
Once you have implemented pooling, you will use the pooled features to train a softmax classifier to map the pooled features to the class labels. The code in this section uses <tt>softmaxTrain</tt> from the softmax exercise to train a softmax classifier on the pooled features for 500 iterations, which should take less than 5 minutes.
=== Step 5: Test classifier ===
=== Step 5: Test classifier ===
 +
 +
Now that you have a trained softmax classifier, you can see how well it performs on the test set. This section contains code that will load the test set and obtain the pooled, convolved features for the images using the functions <tt>cnnConvolve</tt> and <tt>cnnPool</tt> which you wrote earlier, as well as the preprocessing matrices <tt>ZCAWhite</tt> and <tt>meanImage</tt> which were computed earlier in preprocessing the training images. These pooled features will then be run through the softmax classifier, and the accuracy of the predictions will be computed. Because object recognition is a difficult task, the accuracy will be relatively low - we obtained an accuracy of around XX%.

Revision as of 07:53, 14 May 2011

Personal tools