Infer image shape from model for onnx export#307
Merged
simonschoelly merged 19 commits intomainfrom Oct 15, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the ONNX export functionality to infer image dimensions from the trained model instead of requiring explicit specification. The key changes remove the hardcoded channel parameter and make height/width optional by inferring them from the model's configuration.
- Removes the
num_channelsparameter and infers channel count from the model's normalization configuration - Makes
heightandwidthparameters optional, defaulting to the model's trained image size - Updates test cases to cover scenarios with None values for height/width dimensions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/lightly_train/_commands/export_task.py | Modified export functions to infer image dimensions and channels from model, updated parameter types and documentation |
| tests/_commands/test_export_task.py | Added test cases with None values for height/width and logic to use model's image_size when dimensions are None |
e63a74a to
d34c669
Compare
d34c669 to
aa554f3
Compare
aa554f3 to
5d318e7
Compare
fe5e870 to
6e0c9ea
Compare
6e0c9ea to
2717402
Compare
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.
What has changed and why?
This PR infers the height and width from the model for the ONNX export if they re not specified.
I also infer the number of channels now from the model. I don't think it makes sense at all that one can specify the number of channels for the ONNX export - so I decided to remove that option at all.
I don't think we even have the ability to train with something else than RGB channels - so I did not write a test for grayscale images for example - let me know if that is actually possible.
How has it been tested?
(Delete this: Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.)
Did you update CHANGELOG.md?
Probably not necessary
Did you update the documentation?