I'm trying to implement fprop for MaxPooling layer in Conv Networks with no overlapping and pooling regions 2x2. To do so, I need to split my input matrix into matrices of size 2x2 so that I can extract the maximum. I am then creating a mask which I can use later on in bprop. To carry out the splitting I am splitting my input matrix first vertically and then horizontally and then finding the maximum using vsplit, hsplit and amax respectively. This keeps crashing however with index out of bounds exceptions and I am not sure where the error is. Is there a simpler way to split the 24 x 24 input matrix into 144 2x2 matrices so that I can obtain the maximum.
I am doing the following to do so:
for i in range(inputs.shape[0]):
for j in range(inputs.shape[1]):
for k in range(inputs.shape[2] // 2):
for h in range(inputs.shape[3] // 2):
outputs[i,j,k,h] = np.amax(np.hsplit(np.vsplit(inputs[i,j], inputs.shape[2] // 2)[k], inputs.shape[1] // 2)[h])
max_ind = np.argmax(np.hsplit(np.vsplit(inputs[i,j], inputs.shape[2] // 2)[k], inputs.shape[1] // 2)[h])
max_ind_y = max_ind // inputs.shape[2]
if (max_ind_y == 0):
max_ind_x = max_ind
else:
max_ind_x = max_ind % inputs.shape[3]
self.mask[i,j,max_ind_y + 2 * k, max_ind_x + 2 * h] = outputs[i,j,k,h]
EDIT:
This is the output produced by reshape:
What I would like instead is
[0 1
4 5]
[2 3
6 7]
and so on...
