Skip to content

Infer image shape from model for onnx export#307

Merged
simonschoelly merged 19 commits intomainfrom
simon-onnx-infer-shape-value-from-transfomer-parameters
Oct 15, 2025
Merged

Infer image shape from model for onnx export#307
simonschoelly merged 19 commits intomainfrom
simon-onnx-infer-shape-value-from-transfomer-parameters

Conversation

@simonschoelly
Copy link
Copy Markdown
Contributor

@simonschoelly simonschoelly commented Sep 22, 2025

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?

  • Yes
  • Not needed (internal change)

Probably not necessary

Did you update the documentation?

  • Yes
  • Not needed (internal change without effects for user)

Copilot AI review requested due to automatic review settings September 22, 2025 08:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_channels parameter and infers channel count from the model's normalization configuration
  • Makes height and width parameters 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

@simonschoelly simonschoelly force-pushed the simon-onnx-infer-shape-value-from-transfomer-parameters branch from e63a74a to d34c669 Compare September 22, 2025 16:20
@simonschoelly simonschoelly force-pushed the simon-onnx-infer-shape-value-from-transfomer-parameters branch from d34c669 to aa554f3 Compare October 1, 2025 08:03
@simonschoelly simonschoelly force-pushed the simon-onnx-infer-shape-value-from-transfomer-parameters branch from aa554f3 to 5d318e7 Compare October 12, 2025 18:15
@simonschoelly simonschoelly force-pushed the simon-onnx-infer-shape-value-from-transfomer-parameters branch 2 times, most recently from fe5e870 to 6e0c9ea Compare October 15, 2025 07:53
Copy link
Copy Markdown
Contributor

@yutong-xiang-97 yutong-xiang-97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@simonschoelly simonschoelly force-pushed the simon-onnx-infer-shape-value-from-transfomer-parameters branch from 6e0c9ea to 2717402 Compare October 15, 2025 11:02
@simonschoelly simonschoelly merged commit b21ed5c into main Oct 15, 2025
16 checks passed
@simonschoelly simonschoelly deleted the simon-onnx-infer-shape-value-from-transfomer-parameters branch October 15, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants