Write your own pooling operation
As we have seen before, CNNs can have a lot of parameters. Pooling layers are often added between the convolutional layers of a neural network to summarize their outputs in a condensed manner, and reduce the number of parameters in the next layer in the network. This can help us if we want to train the network more rapidly, or if we don't have enough data to learn a very large number of parameters.
A pooling layer can be described as a particular kind of convolution. For every window in the input it finds the maximal pixel value and passes only this pixel through. In this exercise, you will write your own max pooling operation, based on the code that you previously used to write a two-dimensional convolution operation.
Deze oefening maakt deel uit van de cursus
Image Modeling with Keras
Oefeninstructies
- Index into the input array (
im) and select the right window. - Find the maximum in this window.
- Allocate this into the right entry in the output array (
result).
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Result placeholder
result = np.zeros((im.shape[0]//2, im.shape[1]//2))
# Pooling operation
for ii in range(result.shape[0]):
for jj in range(result.shape[1]):
result[ii, jj] = np.max(____)