"...git@developer.sourcefind.cn:OpenDAS/megatron-lm.git" did not exist on "2c63b5cd2eeaf66c3a45e7c65da41d16fb8838ca"
Commit 63ef92aa authored by Sachin Joglekar's avatar Sachin Joglekar Committed by TF Object Detection Team
Browse files

Improve post-training quant documentation for TF2 ODAPI. Also added note about TF version.

PiperOrigin-RevId: 331557693
parent 33a4c207
# Running TF2 Detection API Models on mobile # Running TF2 Detection API Models on mobile
[![TensorFlow 2.2](https://img.shields.io/badge/TensorFlow-2.2-FF6F00?logo=tensorflow)](https://github.com/tensorflow/tensorflow/releases/tag/v2.2.0) [![TensorFlow 2.3](https://img.shields.io/badge/TensorFlow-2.3-FF6F00?logo=tensorflow)](https://github.com/tensorflow/tensorflow/releases/tag/v2.3.0)
[![Python 3.6](https://img.shields.io/badge/Python-3.6-3776AB)](https://www.python.org/downloads/release/python-360/) [![Python 3.6](https://img.shields.io/badge/Python-3.6-3776AB)](https://www.python.org/downloads/release/python-360/)
**NOTE:** This support was added *after* TF2.3, so please use the latest nightly
for the TensorFlow Lite Converter for this to work.
[TensorFlow Lite](https://www.tensorflow.org/mobile/tflite/)(TFLite) is [TensorFlow Lite](https://www.tensorflow.org/mobile/tflite/)(TFLite) is
TensorFlow’s lightweight solution for mobile and embedded devices. It enables TensorFlow’s lightweight solution for mobile and embedded devices. It enables
on-device machine learning inference with low latency and a small binary size. on-device machine learning inference with low latency and a small binary size.
...@@ -54,17 +57,30 @@ python object_detection/export_tflite_graph_tf2.py \ ...@@ -54,17 +57,30 @@ python object_detection/export_tflite_graph_tf2.py \
--output_directory path/to/exported_model_directory --output_directory path/to/exported_model_directory
``` ```
Use `--help` with the aboev script to get the full list of supported parameters. Use `--help` with the above script to get the full list of supported parameters.
These can fine-tune accuracy and speed for your model.
### Step 2: Convert to TFLite ### Step 2: Convert to TFLite
Use the [TensorFlow Lite Converter](https://www.tensorflow.org/lite/convert) to Use the [TensorFlow Lite Converter](https://www.tensorflow.org/lite/convert) to
convert the `SavedModel` to TFLite. You can also leverage convert the `SavedModel` to TFLite. Note that you need to use `from_saved_model`
for TFLite conversion with the Python API.
You can also leverage
[Post-training Quantization](https://www.tensorflow.org/lite/performance/post_training_quantization) [Post-training Quantization](https://www.tensorflow.org/lite/performance/post_training_quantization)
to to
[optimize performance](https://www.tensorflow.org/lite/performance/model_optimization) [optimize performance](https://www.tensorflow.org/lite/performance/model_optimization)
and obtain a smaller model. Note that you need to use `from_saved_model` for and obtain a smaller model. Note that this is only possible from the *Python
TFLite conversion with the Python API. API*. Be sure to use a
[representative dataset](https://www.tensorflow.org/lite/performance/post_training_quantization#full_integer_quantization)
and set the following options on the converter:
```
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
tf.lite.OpsSet.TFLITE_BUILTINS]
converter.representative_dataset = <...>
```
## Running our model on Android ## Running our model on Android
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment