python numpy 手写maxpooling,超简洁写法
简洁易懂
def max_pooling(image, pooling_size, stride):
c,h,w = image.shape()
p_h,p_w = pooling_size.shape()
out_h = (h-p_h)//stride+1
out_w = (w-p_w)//stride+1
out = np.zeros((c,out_h, out_w))
for i in range(c):
for x in range(out_h):
for y in range(out_w):
out[i][x][y] = np.max(image[i][x*stride:(x+1)*stride][y*stride:(y+1)*stride])
return out