def max_pool_3d(inpt, inpt_shape, ds, ignore_border=True):
# Downsize 'into the depth' by downsizing twice.
inpt_shape_4d = (
inpt_shape[0] * inpt_shape[1],
inpt_shape[2],
inpt_shape[3],
inpt_shape[4]
)
inpt_as_tensor4 = T.reshape(inpt, inpt_shape_4d, ndim=4)
# The first pooling only downsizes the height and the width.
pool_out1 = pool.pool_2d(inpt_as_tensor4, (ds[1], ds[2]),
ignore_border=True)
out_shape1 = T.join(0, inpt_shape[:-2], pool_out1.shape[-2:])
inpt_pooled_once = T.reshape(pool_out1, out_shape1, ndim=5)
# Shuffle dimensions so the depth is the last dimension.
inpt_shuffled = inpt_pooled_once.dimshuffle(0, 4, 2, 3, 1)
shuffled_shape = inpt_shuffled.shape
# Reshape input to be 4 dimensional.
shuffle_shape_4d = (
shuffled_shape[0] * shuffled_shape[1],
shuffled_shape[2],
shuffled_shape[3],
shuffled_shape[4]
)
inpt_shuffled_4d = T.reshape(inpt_shuffled, shuffle_shape_4d, ndim=4)
pool_out2 = pool.pool_2d(inpt_shuffled_4d, (1, ds[0]),
ignore_border=True)
out_shape2 = T.join(0, shuffled_shape[:-2], pool_out2.shape[-2:])
inpt_pooled_twice = T.reshape(pool_out2, out_shape2, ndim=5)
pool_output_fin = inpt_pooled_twice.dimshuffle(0, 4, 2, 3, 1)
return pool_output_fin
评论列表
文章目录