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 77%. Comparing base (27b9d23) to head (7e70ea9).

❌ Your project check has failed because the head coverage (77%) 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       77%     77%           
=======================================
  Files          102     103    +1     
  Lines         9047    9096   +49     
=======================================
+ Hits          6979    7024   +45     
- Misses        2068    2072    +4     
🚀 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
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.

2 participants