eliminate alpha image double-decode#2847
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the image loading and resizing pipeline to avoid redundant decoding/work, aiming to improve performance and determinism by reusing decoded arrays and calling trainingsample utilities directly.
Changes:
- Reuses a single
IMREAD_UNCHANGEDdecode inload_imageand centralizes array→RGB conversion via_trainingsample_array_to_rgb_image. - Standardizes
TrainingSample.resizeto calltrainingsample.batch_resize_imagesdirectly (instead of delegating throughBatchedTrainingSamplesfor image resizing). - Adds focused unit tests to guard the “no double-decode” behavior and the direct
trainingsampleresize integration.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
simpletuner/helpers/image_manipulation/load.py |
Reuses the unchanged-channel decode and consolidates array→RGB conversions to prevent redundant decoding. |
simpletuner/helpers/image_manipulation/training_sample.py |
Switches image resizing to a direct tsr.batch_resize_images call to reduce indirection and standardize behavior. |
tests/test_image_load.py |
Adds a unit test ensuring load_image does not perform a second decode after a successful unchanged decode. |
tests/test_training_sample.py |
Adds a unit test asserting intermediary resizing uses the direct trainingsample call (not the batch processor). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request refactors image loading and resizing logic to improve efficiency and reliability by reusing decoded image arrays and standardizing on direct calls to
trainingsampleutilities. It also updates the test suite to verify these optimizations and ensure correct integration.Image loading and decoding improvements:
load_imageand related helpers inload.pyto decode image bytes only once (with unchanged channels), then reuse the resulting array for RGB conversion, reducing redundant decoding and improving performance. (simpletuner/helpers/image_manipulation/load.py) [1] [2]_trainingsample_array_to_rgb_imageto encapsulate optimized format conversions from array to RGB image, including handling of grayscale and RGBA inputs. (simpletuner/helpers/image_manipulation/load.py)Resizing logic standardization:
TrainingSample.resizeto calltsr.batch_resize_imagesdirectly for resizing, bypassing thebatch_processorindirection for improved clarity and reliability. (simpletuner/helpers/image_manipulation/training_sample.py) [1] [2]trainingsampleis imported astsrwhere needed. (simpletuner/helpers/image_manipulation/training_sample.py)Testing enhancements:
load_imagereuses the unchanged-channel decode and does not redundantly decode RGB, ensuring the optimization is effective. (tests/test_image_load.py)TrainingSampleuses the directtrainingsamplecall and not the batch processor, verifying correct integration of the new resizing logic. (tests/test_training_sample.py)These changes streamline image handling, reduce unnecessary computation, and add tests to prevent regressions.