-
Notifications
You must be signed in to change notification settings - Fork 757
feat: include variant name in ONNX export filename #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ def export_onnx( | |
| backbone_only: bool = False, | ||
| verbose: bool = True, | ||
| opset_version: int = 17, | ||
| variant_name: str | None = None, | ||
| ) -> str: | ||
| """Export a model to ONNX. | ||
|
|
||
|
|
@@ -74,11 +75,17 @@ def export_onnx( | |
| backbone_only: Whether to export backbone-only graph naming. | ||
| verbose: Whether ONNX exporter should emit verbose logs. | ||
| opset_version: ONNX opset version. | ||
| variant_name: Model variant identifier (e.g. ``"rfdetr-medium"``). | ||
| When provided, the exported file is named ``{variant_name}.onnx`` | ||
| instead of the generic ``inference_model.onnx``. | ||
|
|
||
| Returns: | ||
| Path to the exported ONNX model. | ||
| """ | ||
| export_name = "backbone_model" if backbone_only else "inference_model" | ||
| 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") | ||
|
|
||
|
Comment on lines
+85
to
90
|
||
| # Prepare model for export | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -150,6 +150,7 @@ def __call__(self, *_args, **_kwargs): | |||||
| resolution=14, | ||||||
| ), | ||||||
| model_config=types.SimpleNamespace(segmentation_head=False), | ||||||
| size=None, | ||||||
| ) | ||||||
|
|
||||||
| export_called: dict[str, bool] = {"value": False} | ||||||
|
|
@@ -208,6 +209,7 @@ def __call__(self, *_args, **_kwargs): | |||||
| model = types.SimpleNamespace( | ||||||
| model=types.SimpleNamespace(model=_DummyCoreModel(), device="cpu", resolution=14), | ||||||
| model_config=types.SimpleNamespace(segmentation_head=segmentation_head), | ||||||
| size=None, | ||||||
| ) | ||||||
|
|
||||||
| captured: dict = {} | ||||||
|
|
@@ -610,6 +612,7 @@ def __call__(self, *_a, **_kw): | |||||
| patch_size=patch_size, | ||||||
| num_windows=num_windows, | ||||||
| ), | ||||||
| size=None, | ||||||
| ) | ||||||
|
|
||||||
| def _fake_make_infer_image(*_a, **_kw): | ||||||
|
|
@@ -742,3 +745,176 @@ def test_make_infer_image_produces_correct_rectangular_shape() -> None: | |||||
| h, w, b = 112, 224, 2 | ||||||
| tensor = make_infer_image(infer_dir=None, shape=(h, w), batch_size=b, device="cpu") | ||||||
| assert tensor.shape == (b, 3, h, w), f"Expected shape ({b}, 3, {h}, {w}), got {tensor.shape}" | ||||||
|
|
||||||
|
|
||||||
| # --------------------------------------------------------------------------- | ||||||
| # ONNX export variant naming (#issue) | ||||||
|
||||||
| # ONNX export variant naming (#issue) | |
| # ONNX export variant naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
variant_namedocstring says the export will be named{variant_name}.onnx, but whenbackbone_only=Truethe actual filename becomes{variant_name}-backbone.onnx. Update the docstring to reflect the backbone-only naming behavior so callers aren’t surprised.