def test_horizontal_flip_with_swap(self):
"""
Test horizontal flip with swapping axes
NB: horizontal flip <=> reverse order on columns
"""
np.random.seed(0)
# 5 images of size 10 x 10 x 3
shape = [5, 10, 10, 3]
batch = np.random.random(size=shape).astype(np.float32)
# move axis and then flip horizontally
flipped_1 = np.moveaxis(batch, 3, 1)[:, :, :, ::-1]
# flip horizontally without moving axis
flipped_2 = batch[:, :, ::-1, :]
for i in range(shape[0]):
for j in range(shape[3]):
assert np.all(np.isclose(flipped_1[i, j],
flipped_2[i, :, :, j]))
评论列表
文章目录