Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy max pooling convolution

Tags:

python

numpy

Edit:

What I actually wanted to do is finding local maxima, which is explained good below, and the same solution is also explained here:

http://scikit-image.org/docs/dev/auto_examples/plot_peak_local_max.html




It seems you can do linear convolution in Numpy.

Is it possible to do a non-linear max pooling convolution? Use a NxM patch and stride over the input image, zeroing the current pixel if it's not the maximum in the vicinity?

So a non-linear max convolution works like this, here is my image

  3 4 5 2 3
  3 5 1 2 7
  2 2 5 1 7

And given a 2x2 max pooling gives this output

  0 0 5 0 0
  0 5 0 0 7
  0 0 5 0 7

You have a 2x2 patch that strides over the image, and zeroes everything, only keeping the max value.

like image 576
user1506145 Avatar asked Jul 04 '16 08:07

user1506145


People also ask

What is Max pooling in python?

Pooling layers are placed between convolution layers. Pooling layers reduce the size of the image across layers by sampling. The sampling is done by selecting the maximum value in a window. Average pooling averages over the window.

What is the advantage of Max pooling?

Max pooling is done to in part to help over-fitting by providing an abstracted form of the representation. As well, it reduces the computational cost by reducing the number of parameters to learn and provides basic translation invariance to the internal representation.

What is Max pooling?

Max pooling is a pooling operation that selects the maximum element from the region of the feature map covered by the filter. Thus, the output after max-pooling layer would be a feature map containing the most prominent features of the previous feature map.


1 Answers

You could use Scipy's maximum_filer -

from scipy.ndimage.filters import maximum_filter

arr*(arr == maximum_filter(arr,footprint=np.ones((3,3))))

Sample run -

In [19]: arr
Out[19]: 
array([[3, 4, 5, 2, 3],
       [3, 5, 1, 2, 7],
       [2, 2, 5, 6, 7]])

In [20]: arr*(arr == maximum_filter(arr,footprint=np.ones((3,3))))
Out[20]: 
array([[0, 0, 5, 0, 0],
       [0, 5, 0, 0, 7],
       [0, 0, 0, 0, 7]])
like image 152
Divakar Avatar answered Oct 15 '22 02:10

Divakar