Skip to content

feat(cli): add rfdetr export subcommand for ONNX/TFLite export - #1067

Draft
omkar-334 wants to merge 5 commits into
roboflow:developfrom
omkar-334:feat-tflite-cli
Draft

feat(cli): add rfdetr export subcommand for ONNX/TFLite export#1067
omkar-334 wants to merge 5 commits into
roboflow:developfrom
omkar-334:feat-tflite-cli

Conversation

@omkar-334

Copy link
Copy Markdown
Contributor

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.py to expose TFLite export (and its quantization / calibration options) from the shell. Until now, export was reachable only from Python via RFDETR.export(format=...).

Rather than extend the legacy argparser, this adds a proper rfdetr export subcommand that wraps RFDETR.export (TFLite already worked in Python; this surfaces it to the CLI).

Related to #1024

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:
I verified the training and export end to end -> Train a checkpoint, run rfdetr export --checkpoint <ckpt> --format onnx, and the exported rfdetr-nano.onnx loads and runs in onnxruntime (dets / labels outputs).

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have updated the documentation accordingly (if applicable)

Additional Context

export (jsonargparse) and fit/validate/test/predict (LightningCLI) are two different parsers, so a single rfdetr command 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-command rfdetr <command> --help backend-native.

Usage

# install (no [train] / PyTorch Lightning needed for export)
pip install "rfdetr[cli,onnx]"          # ONNX
pip install "rfdetr[cli,onnx,tflite]"   # TFLite

# discover
rfdetr --help            # lists fit/validate/test/predict + the export subcommand
rfdetr export --help     # all flags, derived from RFDETR.export

# ONNX
rfdetr export --checkpoint output/checkpoint_best_total.pth --format onnx --output_dir output

# TFLite (FP32 + FP16)
rfdetr export --checkpoint output/checkpoint_best_total.pth --format tflite --output_dir output

# TFLite INT8 with calibration images
rfdetr export --checkpoint output/checkpoint_best_total.pth --format tflite --quantization int8 --calibration_data path/to/val_images/ --max_images 100 --output_dir output

# flags from a YAML file
rfdetr export --config export.yaml

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79%. Comparing base (779e552) to head (fc750ae).
⚠️ Report is 34 commits behind head on develop.

❌ 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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda

Borda commented May 26, 2026

Copy link
Copy Markdown
Member

Lte's do not add it until it is stable, so far I tested TFlite, the predictions were quite questionable...

@Borda
Borda marked this pull request as draft May 26, 2026 14:58
@Borda Borda added the enhancement New feature or request label Jun 22, 2026
@Borda

Borda commented Jul 22, 2026

Copy link
Copy Markdown
Member

FYI, we have moved the TensorRT export from subcomand to native package use in #853...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.py and updates imports/tests/docs accordingly; adds a lazy re-export for RFDETRCli from rfdetr.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.

Comment thread src/rfdetr/cli/export.py
Comment on lines +38 to +41
patch_size: Optional[int] = None,
infer_dir: Optional[str] = None,
notes: Optional[str] = None,
verbose: bool = True,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request has conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants