-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
Add TensorFlow formats to export.py
#4479
Conversation
@zldrobit this PR is almost done! I'm understanding a lot more about TF export after doing all of this, and I had a few quick questions:
|
@glenn-jocher I did some tests to verify the solutions for the following questions:
in For convenience, I'll send an PR to address these issues. |
@zldrobit wow thanks for the investigation! That's awesome you found a fuse solution. I'll take a deeper look later but to give you a quick update, tflite export (and tfjs exports seem to be working well now via export.py, usage is like this:) python export.py --weights yolov5s.pt --include tflite # produces yolov5s.tflite which was previously labelled as fp16
python export.py --weights yolov5s.pt --include tflite --int8 # produces yolov5s-int8.tflite using dataset generator
python export.py --weights yolov5s.pt --include tfjs # produces yolov5s_web_model EDIT: BTW I was not able to pass all parameters to all places in the TF model, agnostic NMS for example now uses hard coded NMS parameters, but I plan to try to fix this in the future. Previously these parameters were global variables from |
@glenn-jocher I found a solution to pass all parameters to the TF NMS operation in #4905. That PR also addresses the |
* Initial commit * Remove unused export_torchscript return * ROOT variable * Add prefix to fcn arg * fix ROOT * check_yaml into run() * interim fixes * imgsz=(320, 320) * Hardcode tf_raw_resize False * Finish opt elimination * Update representative_dataset_gen() * Update export.py with TF methods * SiLU and GraphDef fixes * file_size() directory handling feature * export fixes * add lambda: to representative_dataset * Detect training False default * Fuse false for TF models * Embed agnostic NMS arguments * Remove lambda * TensorFlow.js export success * Add pb to Usage * Add *_tfjs_model/ to ignore files * prepend YOLOv5 to function headers * Remove end --- comments * parameterize tfjs export pb file * update run() data default /ROOT * update --include help * update imports * return ct_model * Consolidate TFLite export * pb prerequisite to tfjs * TF modules CamelCase * Remove exports from tf.py and cleanup * pass agnostic NMS arguments * CI * CI * ignore *_web_model/ * Add tensorflow to CI dependencies * CI tensorflow-cpu * Update requirements.txt * Remove tensorflow check_requirement * CI coreml tfjs * export only onnx torchscript * reorder exports torchscript first
* Initial commit * Remove unused export_torchscript return * ROOT variable * Add prefix to fcn arg * fix ROOT * check_yaml into run() * interim fixes * imgsz=(320, 320) * Hardcode tf_raw_resize False * Finish opt elimination * Update representative_dataset_gen() * Update export.py with TF methods * SiLU and GraphDef fixes * file_size() directory handling feature * export fixes * add lambda: to representative_dataset * Detect training False default * Fuse false for TF models * Embed agnostic NMS arguments * Remove lambda * TensorFlow.js export success * Add pb to Usage * Add *_tfjs_model/ to ignore files * prepend YOLOv5 to function headers * Remove end --- comments * parameterize tfjs export pb file * update run() data default /ROOT * update --include help * update imports * return ct_model * Consolidate TFLite export * pb prerequisite to tfjs * TF modules CamelCase * Remove exports from tf.py and cleanup * pass agnostic NMS arguments * CI * CI * ignore *_web_model/ * Add tensorflow to CI dependencies * CI tensorflow-cpu * Update requirements.txt * Remove tensorflow check_requirement * CI coreml tfjs * export only onnx torchscript * reorder exports torchscript first
@zldrobit this my main PR for migrating TensorFlow export support to export.py following #1127, while retaining the Keras model-building functionality you created in tf.py.
Export a YOLOv5 PyTorch model to TorchScript, ONNX, CoreML, TensorFlow (saved_model, pb, TFLite, TF.js,) formats
TensorFlow exports authored by https://github.com/zldrobit
Usage:
Inference:
$ python path/to/detect.py --weights yolov5s.pt yolov5s.onnx (must export with --dynamic) yolov5s_saved_model yolov5s.pb yolov5s.tflite
TensorFlow.js:
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
This PR updates the Ultralytics YOLOv5 repository with new export capabilities and various adjustments.
📊 Key Changes
*_web_model/
to.dockerignore
and.gitignore
, suggesting new support for web models.onnx-simplifier
andcoremltools
withtensorflow-cpu
.detect.py
andexport.py
for stronger TensorFlow integration and simplifications within the export process.tf.py
TensorFlow model script with new functionalities for exporting models, removing redundant code, and introducing TF.js export support.TFBN
,TFConv
, etc.) that seem to correspond to TensorFlow/Keras equivalents of existing YOLOv5 layers.requirements.txt
, highlighting the shift towards TensorFlow-based operations.🎯 Purpose & Impact
.github/workflows/ci-testing.yml
imply that CI now includes tests for TensorFlow export functionality, which ensures reliability for cloud-based applications.onnx-simplifier
andcoremltools
may lower the barrier to entry for some users and streamline the model export process, focusing more on TensorFlow-centric workflows.