Repository navigation
Add channel_axis to rotate and affine_transform #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -522,6 +522,44 @@ def _test_fn(self, images_list, jax_fn, reference_fn): | |
| class TestCustom(parameterized.TestCase): | ||
| """Tests custom logic that is not covered by reference functions.""" | ||
|
|
||
| @parameterized.product( | ||
| mode_and_order=[("nearest", 0), ("nearest", 1), ("mirror", 1), | ||
| ("constant", 1)], | ||
| channel_axis=(0, -3), | ||
| ) | ||
| def test_affine_transform_channel_axis(self, mode_and_order, channel_axis): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add also the different ways of passing the dimensions/offset? See how test_affine_transform is done, and we just add channel axis to the product of the parameterized test. |
||
| mode, order = mode_and_order | ||
| image = np.random.RandomState(0).rand(10, 12, 3).astype(np.float32) | ||
| # Matrix and offset are always given in HWC order. | ||
| matrix = jnp.array([[0.8, 0.3, 0.], [-0.2, 1.1, 0.], [0., 0., 1.]]) | ||
| offset = jnp.array([1.5, -2., 0.]) | ||
| expected = augment.affine_transform( | ||
| image, matrix, offset=offset, mode=mode, order=order, cval=0.5) | ||
| result = augment.affine_transform( | ||
| np.moveaxis(image, -1, 0), matrix, offset=offset, mode=mode, | ||
| order=order, cval=0.5, channel_axis=channel_axis) | ||
| np.testing.assert_allclose( | ||
| result, np.moveaxis(expected, -1, 0), atol=1e-5) | ||
|
|
||
| @parameterized.product( | ||
| mode_and_order=[("nearest", 0), ("nearest", 1), ("mirror", 1), | ||
| ("constant", 1)], | ||
| angle=(np.pi / 2, -np.pi / 4), | ||
| channel_axis=(0, -3), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| ) | ||
| def test_rotate_channel_axis(self, mode_and_order, angle, channel_axis): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test it in the same manner we do test_rotate, we just need to add channel axis to that test probably. Scipy as reference function has axes of which oens you want to rotate. |
||
| mode, order = mode_and_order | ||
| image = np.random.RandomState(0).rand(10, 12, 3).astype(np.float32) | ||
| expected = augment.rotate(image, angle, mode=mode, order=order, cval=0.5) | ||
| rotate_fn = jax.jit( | ||
| augment.rotate, | ||
| static_argnames=("mode", "order", "cval", "channel_axis")) | ||
| result = rotate_fn( | ||
| np.moveaxis(image, -1, 0), angle, mode=mode, order=order, cval=0.5, | ||
| channel_axis=channel_axis) | ||
| np.testing.assert_allclose( | ||
| result, np.moveaxis(expected, -1, 0), atol=1e-5) | ||
|
|
||
| @parameterized.product( | ||
| shape_and_axis=( | ||
| ((5, 7, 3), 2), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
-3seems a bit unnecessary here. Can make it explicit?