Skip to content

feat: include variant name in ONNX export filename#910

Open
farukalamai wants to merge 2 commits intoroboflow:developfrom
farukalamai:feat/onnx-export-naming
Open

feat: include variant name in ONNX export filename#910
farukalamai wants to merge 2 commits intoroboflow:developfrom
farukalamai:feat/onnx-export-naming

Conversation

@farukalamai
Copy link
Copy Markdown
Contributor

What does this PR do?

ONNX export now names the output file after the model variant (e.g. rfdetr-medium.onnx) instead of the generic inference_model.onnx. Exporting multiple variants to the same directory no longer overwrites previous exports.

Related Issue(s): Part of #905

Type of Change

  • New feature (non-breaking change that adds functionality)

Testing

  • I have tested this change locally
  • I have added/updated tests for this change

Test details:
Added TestExportOnnxVariantNaming with 6 tests covering variant naming, backbone suffix, default fallback, and RFDETR.export() integration.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings or errors

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78%. Comparing base (ab5e7c7) to head (abcc34b).
⚠️ Report is 3 commits behind head on develop.

❌ Your project check has failed because the head coverage (78%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@          Coverage Diff           @@
##           develop   #910   +/-   ##
======================================
  Coverage       78%    78%           
======================================
  Files           97     97           
  Lines         7706   7708    +2     
======================================
+ Hits          6014   6016    +2     
  Misses        1692   1692           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the enhancement New feature or request label Apr 2, 2026
@Borda Borda requested a review from Copilot April 2, 2026 18:12
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

Updates the ONNX export pipeline to incorporate the model variant name into the exported filename (e.g. rfdetr-medium.onnx), preventing accidental overwrites when exporting multiple variants to the same directory.

Changes:

  • Add optional variant_name parameter to ONNX exporter and use it to derive the output filename (with -backbone suffix for backbone-only exports).
  • Pass the model’s variant identifier (self.size) through RFDETR.export() into the ONNX exporter.
  • Add tests covering variant-based naming, backbone suffix behavior, fallback naming, and RFDETR.export() integration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/rfdetr/export/_onnx/exporter.py Introduces variant_name and uses it to build the ONNX output filename.
src/rfdetr/detr.py Forwards self.size into export_onnx() so high-level RFDETR.export() produces variant-specific filenames.
src/rfdetr/export/main.py Threads an (optional) args.variant_name through the CLI export path.
tests/models/test_export.py Adds coverage ensuring naming behavior works for variant/backbone/fallback and RFDETR integration.

Comment on lines +85 to 90
if variant_name:
export_name = f"{variant_name}-backbone" if backbone_only else variant_name
else:
export_name = "backbone_model" if backbone_only else "inference_model"
output_file = os.path.join(output_dir, f"{export_name}.onnx")

Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

variant_name is interpolated directly into the filename. If it contains path separators (e.g. "foo/bar"), an absolute path (e.g. "/tmp/x"), or a drive prefix on Windows, os.path.join(output_dir, ...) can write outside output_dir or fail due to missing intermediate directories. Consider sanitizing to a safe stem (e.g. Path(variant_name).name/.stem, stripping a trailing .onnx) and rejecting values that aren’t simple filenames.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +80
When provided, the exported file is named ``{variant_name}.onnx``
instead of the generic ``inference_model.onnx``.
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The variant_name docstring says the export will be named {variant_name}.onnx, but when backbone_only=True the actual filename becomes {variant_name}-backbone.onnx. Update the docstring to reflect the backbone-only naming behavior so callers aren’t surprised.

Suggested change
When provided, the exported file is named ``{variant_name}.onnx``
instead of the generic ``inference_model.onnx``.
When provided, the exported file is named ``{variant_name}.onnx`` or
``{variant_name}-backbone.onnx`` (when ``backbone_only=True``) instead
of the generic ``inference_model.onnx`` or ``backbone_model.onnx``.

Copilot uses AI. Check for mistakes.
Comment on lines 714 to 725
output_file = export_onnx(
output_dir=str(output_dir_path),
model=model,
input_names=input_names,
input_tensors=input_tensors,
output_names=output_names,
dynamic_axes=dynamic_axes,
backbone_only=backbone_only,
verbose=verbose,
opset_version=opset_version,
variant_name=getattr(self, "size", None),
)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

RFDETR.export() still accepts **kwargs and the docstring says they’re forwarded to export_onnx, but the export_onnx(...) call doesn’t actually pass **kwargs. With the new variant_name= argument being set explicitly, callers also can’t override it via kwargs. Either forward **kwargs into export_onnx (and decide precedence), or remove/update the **kwargs parameter/docstring to match behavior.

Copilot uses AI. Check for mistakes.


# ---------------------------------------------------------------------------
# ONNX export variant naming (#issue)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The section header comment says # ONNX export variant naming (#issue) which looks like a placeholder. Replace it with the actual issue reference (e.g. #905) or remove the parenthetical to avoid stale/incorrect references in the test file.

Suggested change
# ONNX export variant naming (#issue)
# ONNX export variant naming

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants