feat(cli): add rfdetr export subcommand for ONNX/TFLite export - #1067
feat(cli): add rfdetr export subcommand for ONNX/TFLite export#1067omkar-334 wants to merge 5 commits into
rfdetr export subcommand for ONNX/TFLite export#1067Conversation
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (79%) 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 #1067 +/- ##
========================================
- Coverage 81% 79% -2%
========================================
Files 108 109 +1
Lines 11215 11264 +49
========================================
- Hits 9120 8906 -214
- Misses 2095 2358 +263 🚀 New features to boost your workflow:
|
|
Lte's do not add it until it is stable, so far I tested TFlite, the predictions were quite questionable... |
7e70ea9 to
abcfd69
Compare
|
FYI, we have moved the TensorRT export from subcomand to native package use in #853... |
There was a problem hiding this comment.
Pull request overview
This PR adds a unified rfdetr root CLI that lazily dispatches to either the training/eval LightningCLI backend or a new rfdetr export subcommand (jsonargparse) that wraps RFDETR.export, enabling ONNX/TFLite export (including TFLite quantization/calibration flags) from the shell without requiring the [train] extra.
Changes:
- Introduces
rfdetr export(src/rfdetr/cli/export.py) and a root dispatcher (src/rfdetr/cli/__init__.py) to route commands without eagerly importing the training stack. - Moves the LightningCLI backend to
src/rfdetr/cli/train.pyand updates imports/tests/docs accordingly; adds a lazy re-export forRFDETRClifromrfdetr.training. - Updates documentation and configuration to reflect the new CLI structure and adds CLI routing/forwarding tests.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/cli/test_train.py | Updates CLI import-path expectations to rfdetr.cli.train. |
| tests/cli/test_smoke.py | Updates smoke helper to import RFDETRCli from rfdetr.cli.train. |
| tests/cli/test_export.py | Adds tests for rfdetr export forwarding and root-dispatch behavior (argv handling, help, invalid command). |
| src/rfdetr/training/init.py | Lazily re-exports RFDETRCli to avoid circular imports while preserving rfdetr.training.RFDETRCli. |
| src/rfdetr/export/main.py | Updates comments to point users to the new rfdetr export --format tflite path for TFLite export. |
| src/rfdetr/cli/train.py | Adds the LightningCLI backend module (fit/validate/test/predict). |
| src/rfdetr/cli/export.py | Adds rfdetr export jsonargparse wrapper over from_checkpoint(...).export(...). |
| src/rfdetr/cli/init.py | Implements the root CLI help + lazy dispatch to training backend or standalone commands. |
| pyproject.toml | Ensures rfdetr console script points to rfdetr.cli:main and updates tooling overrides for moved modules. |
| docs/reference/training.md | Updates mkdocstrings reference to rfdetr.cli.train.RFDETRCli. |
| docs/learn/export.md | Documents the new command-line export workflow and examples. |
| patch_size: Optional[int] = None, | ||
| infer_dir: Optional[str] = None, | ||
| notes: Optional[str] = None, | ||
| verbose: bool = True, |
What does this PR do?
Adds a command-line path for exporting trained RF-DETR checkpoints, resolving the long-standing TODO in
rfdetr/export/main.pyto expose TFLite export (and its quantization / calibration options) from the shell. Until now, export was reachable only from Python viaRFDETR.export(format=...).Rather than extend the legacy argparser, this adds a proper
rfdetr exportsubcommand that wrapsRFDETR.export(TFLite already worked in Python; this surfaces it to the CLI).Related to #1024
Type of Change
Testing
Test details:
I verified the training and export end to end -> Train a checkpoint, run
rfdetr export --checkpoint <ckpt> --format onnx, and the exportedrfdetr-nano.onnxloads and runs in onnxruntime (dets/labelsoutputs).Checklist
Additional Context
export(jsonargparse) andfit/validate/test/predict(LightningCLI) are two different parsers, so a singlerfdetrcommand needs a thin root to choose between them. Treating LightningCLI as the root would force the[train]extra on export-only users and produce a stitched, two-part top-level--help. The root therefore owns top-level help and dispatch and delegates to each backend, which leaves LightningCLI's training semantics untouched and keeps per-commandrfdetr <command> --helpbackend-native.Usage