Is it possible to do strided 2d pooling using only reshape and slice operations? In a nutshell, can you do strided 2d pooling using only np.reshape and slice (eg. arr.data[0:5])?

Here is an example of 2d pooling with support for only kernel_size:

kernel_x = 2
kernel_y = 2
xup = arr.data[:, :, :arr.shape[2]-arr.shape[2]%kernel_y, :arr.shape[3]-arr.shape[3]%kernel_x]
arr.reshape(shape=(arr.shape[0], arr.shape[1], arr.shape[2]//kernel_y, kernel_y, arr.shape[3]//kernel_x, kernel_x))

(Max and average pooling is only a matter of doing a .mean or .max along axis 3 & 5 after this)

Does anyone know how, or if it is possible to incorporate a stride (preferably 2-dimensional, however a one dimensional would be fenomenal too) into this kind of 2d pooling solution with only slice & reshape operations? Any help is appreciated, thank you in advance!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.