import numpy as np

x = np.random.randn(64, 512, 96, 32) pool_shape = (2, 4, 8, 4) stride = (2, 4, 8, 4)

N, C, H, W = x.shape pool_H, pool_W, pool_D, pool_M = pool_shape stride_H, stride_W, stride_D, stride_M = stride

out_H = (H - pool_H) // stride_H + 1 out_W = (W - pool_W) // stride_W + 1 out_D = (D - pool_D) // stride_D + 1 out_M = (M - pool_M) // stride_M + 1

out = np.zeros((N, C, out_H, out_W, out_D, out_M))

for h in range(out_H): for w in range(out_W): for d in range(out_D): for m in range(out_M): vert_start = h * stride_H vert_end = vert_start + pool_H horiz_start = w * stride_W horiz_end = horiz_start + pool_W depth_start = d * stride_D depth_end = depth_start + pool_D channel_start = m * stride_M channel_end = channel_start + pool_M

            x_slice = x[:, :, vert_start:vert_end, horiz_start:horiz_end, depth_start:depth_end, channel_start:channel_end]
            
            out[:, :, h, w, d, m] = np.max(x_slice, axis=(2, 3, 4, 5))

print(out.shape) # (64, 512, 12, 8)

64 512 96 32池化为64 1024 12 8python代码

原文地址: https://www.cveoy.top/t/topic/bvMd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录