feat(export): add TFLite export support with FP32/FP16/INT8#920
Open
mfazrinizar wants to merge 3 commits intoroboflow:developfrom
Open
feat(export): add TFLite export support with FP32/FP16/INT8#920mfazrinizar wants to merge 3 commits intoroboflow:developfrom
mfazrinizar wants to merge 3 commits intoroboflow:developfrom
Conversation
- Use getattr/setattr for dynamic module attribute access instead of direct attribute assignment (attr-defined) - Add unused-ignore to type: ignore comments for numpy.load monkey-patch to handle both mypy versions (unused-ignore)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds an ONNX → TFLite conversion pipeline for RF-DETR detection and segmentation models via
onnx2tf.Users can now export any RF-DETR model to TFLite format with a single call:
Key changes
New module:
src/rfdetr/export/_tflite/converter.py: Coreexport_tflite()function — converts ONNX to TFLite via onnx2tf Python APIquantization="int8"with calibration from an image directory,.npyfile, or NumPy arraymax_imagesparameter controls calibration sample count (default: 100)output_signaturedefs=Truefix for segmentation models (onnx2tf node naming issue with leading/characters violating TF saved_model naming pattern)onnx2tf'sdownload_test_image_data()to use local calibration data instead of downloading from GitHub (which fails in CI, firewalls, air-gapped systems)allow_picklecompatibility shim for onnx2tf 1.x releasesModified files
src/rfdetr/detr.py: Addedformat="tflite"routing inexport()withquantization,calibration_data,max_images,output_dirparameterssrc/rfdetr/export/main.py/__init__.py: Wired upexport_tfliteimportpyproject.toml: Addedonnx2tf>=1.26.0andtf-keras>=2.16.0to[onnx]optional dependenciesdocs/learn/export.md: TFLite usage guide, calibration explanation, parameter reference, FP32/FP16 always-produced behavior noteRelated Issue(s): Related to #173 and this PR
Type of Change
Testing
Test details:
56 unit tests in
tests/export/test_tflite_export.py(all CPU, no GPU required):export(format="tflite")correctly dispatches toexport_tfliteNone,"fp32","fp16","int8"modes; rejects invalid values.npyfile loading, NumPy array input, and directory-based image loading with resizemax_imagesparameter forwarding: Verifiesmax_imagesflows throughdetr.py→export_tflite()→_prepare_calibration_data()→_load_calibration_images()Checklist