Repository navigation
Add channel_axis to rotate and affine_transform - #142
Open
krakken190 wants to merge 3 commits into
Open
krakken190 wants to merge 3 commits into
krakken190 wants to merge 3 commits into
Conversation
Author
|
Hi @claudiofantacci , I've resolved the merge conflict with master. Ready for review/merge whenever you get a chance! |
Author
|
@claudiofantacci Sorry, my merge-conflict resolution in the GitHub UI dropped the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #141.
Problem
rotateandaffine_transformsay they support HWC or CHW images, but they always treat the first two array axes as height and width. For CHW inputs this rotates or shifts across the channel axis and silently returns a corrupted image.Fix
channel_axis: int = -1toaffine_transform. When it is not-1, the channel axis is moved to the end before the transform and moved back afterwards. This is the same patternelastic_deformationuses.matrixandoffsetare always interpreted in HWC order, independent ofchannel_axis, so one transform can be applied to either layout. The docstring now says this.channel_axis: int = -1torotate. It computes the rotation centre from the HWC-ordered shape and forwardschannel_axistoaffine_transform.-1keeps the existing behaviour, so current callers are unaffected.Tests
Added to
TestCustom:test_affine_transform_channel_axis: fornearest/0,nearest/1,mirror/1 andconstant/1, withchannel_axis0 and -3, the CHW result equals the HWC result moved to channels-first.test_rotate_channel_axis: the same check for two angles, run underjax.jit.Validation
pytest dm_pix/_src/augment_test.py: 886 passedpytest dm_pix/_src/api_test.py: 80 passedchannel_axis=0, CHW output matches HWC exactly (max diff 0.0) for both functions. Without it, the difference was 0.99997 before and after the change.Tested on CPU with Python 3.12.2, JAX/jaxlib 0.12.0, NumPy 2.5.4, SciPy 1.18.1 and TensorFlow 2.21.0. GPU/TPU not tested.