Submitted by Logon1028 t3_zn1f3j in deeplearning
Does anyone here know where I could find an efficient implementation of max pooling? I have been working on my own deep learning library. And I wrote an implementation of max pooling (however it is slower than I would like). It basically takes a 3 dimensional input (kernel_depth, kernel_size, kernel_size) and uses the numpy function as_strided for the forward pass. However, during the forward pass I need to keep track of the max value indexes used in the forward pass because those are the only ones the backward gradient will be applied to (like a mask). My problem is to track the forward indices I basically use a triple nested for loop for the as_strided result.
for depth in range(strided_result.shape[0]):
for x in range(strided_result.shape[1]):
for y in range(strided_result.shape[2]):
Then I use the numpy argmax function to find the index of the max argument (for each stride result). Is there are more efficient way that you can track the input index of the strided max values?
elbiot t1_j0fitwk wrote
Can't you just reshape the array and use argmax (so no as_strided). Reshaping is often free. You'd have to do some arithmetic to get the indices for the original shape, but it would just be one operation
I.e. you can take a shape (99,) array and reshape it to (3,33) and then get 33 maxes.