Exercise:Convolution and Pooling

From Ufldl

Jump to: navigation, search
(Step 3a: Convolution)
Line 66: Line 66:
To use these convolution functions, we will have to convolve the features with the large images one at a time. That is, for every feature, we 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.  
To use these convolution functions, we will have to convolve the features with the large images one at a time. That is, for every feature, we 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.  
-
'''Implementation tip:''' Using <tt>conv2</tt> and <tt>convn</tt>:
+
'''Implementation tip:''' Using <tt>conv2</tt> and <tt>convn</tt>
Because the mathematical definition of convolution involves "flipping" the matrix to convolve with, to use MATLAB's convolution functions, you must first "flip" the weight matrix so that when MATLAB "flips" it according to the mathematical definition the entries will be at the correct place. For example, suppose you wanted to convolve two matrices <math>X</math> (the large image) and <math>W</math> (the feature) using <tt>conv2(X, W)</tt>, and W is a 3x3 matrix as below:
Because the mathematical definition of convolution involves "flipping" the matrix to convolve with, to use MATLAB's convolution functions, you must first "flip" the weight matrix so that when MATLAB "flips" it according to the mathematical definition the entries will be at the correct place. For example, suppose you wanted to convolve two matrices <math>X</math> (the large image) and <math>W</math> (the feature) using <tt>conv2(X, W)</tt>, and W is a 3x3 matrix as below:

Revision as of 07:46, 8 May 2011

Personal tools