# Exercise:Convolution and Pooling

### From Ufldl

(→Step 2a: Implement convolution) |
(→Step 2a: Implement convolution) |
||

Line 77: | Line 77: | ||

</math> | </math> | ||

- | If the original layout of <tt>W</tt> was correct, after flipping, it would be incorrect. For the layout to be correct after flipping, you will have to flip <tt>W</tt> before passing it into <tt>conv2</tt>, so that after MATLAB flips <tt>W</tt> in <tt>conv2</tt>, the layout will be correct. For <tt>conv2</tt>, this means reversing the rows and columns, which can be done with <tt>flipud</tt> and <tt>fliplr</tt>, as | + | If the original layout of <tt>W</tt> was correct, after flipping, it would be incorrect. For the layout to be correct after flipping, you will have to flip <tt>W</tt> before passing it into <tt>conv2</tt>, so that after MATLAB flips <tt>W</tt> in <tt>conv2</tt>, the layout will be correct. For <tt>conv2</tt>, this means reversing the rows and columns, which can be done with <tt>flipud</tt> and <tt>fliplr</tt>, as shown below: |

<syntaxhighlight lang="matlab"> | <syntaxhighlight lang="matlab"> | ||

- | % Flip W for use in conv2 | + | % Flip W for use in conv2 |

- | + | W = flipud(fliplr(W)); | |

- | + | ||

- | + | ||

</syntaxhighlight> | </syntaxhighlight> | ||