Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/operator/image/image_random-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ void FlipImpl(const mxnet::TShape &shape, DType *src, DType *dst) {
for (int i = axis+1; i < shape.ndim(); ++i) tail *= shape[i];

for (int i = 0; i < head; ++i) {
for (int j = 0; j < (mid >> 1); ++j) {
// if inplace flip, skip the mid point in axis, otherwise copy is required
int mid2 = (src == dst) ? mid >> 1 : (mid + 1) >> 1;
for (int j = 0; j < mid2; ++j) {
int idx1 = (i*mid + j) * tail;
int idx2 = idx1 + (mid-(j << 1)-1) * tail;
for (int k = 0; k < tail; ++k, ++idx1, ++idx2) {
Expand Down
19 changes: 10 additions & 9 deletions tests/python/unittest/test_gluon_data_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,20 @@ def test_crop_backward(test_nd_arr, TestCase):

@with_seed()
def test_flip_left_right():
data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8)
flip_in = data_in[:, ::-1, :]
data_trans = nd.image.flip_left_right(nd.array(data_in, dtype='uint8'))
assert_almost_equal(flip_in, data_trans.asnumpy())
for width in range(3, 301, 7):
data_in = np.random.uniform(0, 255, (300, width, 3)).astype(dtype=np.uint8)
flip_in = data_in[:, ::-1, :]
data_trans = nd.image.flip_left_right(nd.array(data_in, dtype='uint8'))
assert_almost_equal(flip_in, data_trans.asnumpy())


@with_seed()
def test_flip_top_bottom():
data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8)
flip_in = data_in[::-1, :, :]
data_trans = nd.image.flip_top_bottom(nd.array(data_in, dtype='uint8'))
assert_almost_equal(flip_in, data_trans.asnumpy())
for height in range(3, 301, 7):
data_in = np.random.uniform(0, 255, (height, 300, 3)).astype(dtype=np.uint8)
flip_in = data_in[::-1, :, :]
data_trans = nd.image.flip_top_bottom(nd.array(data_in, dtype='uint8'))
assert_almost_equal(flip_in, data_trans.asnumpy())


@with_seed()
Expand Down Expand Up @@ -445,4 +447,3 @@ def test_bbox_crop():
im_out, im_bbox = transform(img, bbox)
assert im_out.shape == (3, 3, 3)
assert im_bbox[0][2] == 3