Exercise:Convolution and Pooling
From Ufldl
(→Step 3a: Convolution) |
(→Step 3a: Convolution) |
||
Line 81: | Line 81: | ||
convolvedTemp = zeros(imageDim - patchDim + 1, imageDim - patchDim + 1, 3); | convolvedTemp = zeros(imageDim - patchDim + 1, imageDim - patchDim + 1, 3); | ||
for channel = 1:3 | for channel = 1:3 | ||
- | % Flip the feature matrix because of the definition of convolution, as explained | + | % Flip the feature matrix because of the definition of convolution, as explained later |
- | + | ||
Wt(:, :, channel) = flipud(fliplr(squeeze(Wt(:, :, channel)))); | Wt(:, :, channel) = flipud(fliplr(squeeze(Wt(:, :, channel)))); | ||
convolvedTemp(:, :, channel) = conv2(squeeze(images(:, :, channel, imageNum)), squeeze(Wt(:, :, channel)), 'valid'); | convolvedTemp(:, :, channel) = conv2(squeeze(images(:, :, channel, imageNum)), squeeze(Wt(:, :, channel)), 'valid'); | ||
Line 92: | Line 91: | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | The following implementation tip explains the "flipping" of feature matrices when using MATLAB's convolution functions: | ||
<div style="border:1px solid black; padding: 5px"> | <div style="border:1px solid black; padding: 5px"> |