Nano: update tensorflow examples (#6935)

This commit is contained in:
Yishuo Wang 2022-12-12 13:56:05 +08:00 committed by GitHub
parent 56a2d8f1cd
commit 7e180d028e

View file

@ -19,10 +19,10 @@ By default, [Intel Neural Compressor](https://github.com/intel/neural-compressor
pip install neural-compressor==1.11.0 pip install neural-compressor==1.11.0
``` ```
BigDL-Nano provides several APIs which can help users easily apply optimizations on inference pipelines to improve latency and throughput. The Keras Model(`bigdl.nano.tf.keras.Model`) and Sequential(`bigdl.nano.tf.keras.Sequential`) provides the APIs for all optimizations you need for inference. BigDL-Nano provides several APIs which can help users easily apply optimizations on inference pipelines to improve latency and throughput. The Keras Model(`bigdl.nano.tf.keras.Model`) and InferenceOptimizer(`bigdl.nano.tf.keras.InferenceOptimizer`) provides the APIs for all optimizations you need for inference.
```python ```python
from bigdl.nano.tf.keras import Model, Sequential from bigdl.nano.tf.keras import Model, InferenceOptimizer
``` ```
### Step 1: Loading Data ### Step 1: Loading Data
@ -71,11 +71,12 @@ model.fit(train_ds, epochs=1)
``` ```
### Step 3: Quantization with Intel Neural Compressor ### Step 3: Quantization with Intel Neural Compressor
[`Model.quantize()`](https://bigdl.readthedocs.io/en/latest/doc/PythonAPI/Nano/tensorflow.html#bigdl.nano.tf.keras.Model) return a Keras module with desired precision and accuracy. Taking Resnet50 as an example, you can add quantization as below. [`InferenceOptimizer.quantize()`](https://bigdl.readthedocs.io/en/latest/doc/PythonAPI/Nano/tensorflow.html#bigdl.nano.tf.keras.InferenceOptimizer.quantize) return a Keras module with desired precision and accuracy. Taking Resnet50 as an example, you can add quantization as below.
```python ```python
from tensorflow.keras.metrics import CategoricalAccuracy from tensorflow.keras.metrics import CategoricalAccuracy
q_model = model.quantize(calib_dataset=dataset, q_model = InferenceOptimizer.quantize(model,
calib_dataset=dataset,
metric=CategoricalAccuracy(), metric=CategoricalAccuracy(),
tuning_strategy='basic' tuning_strategy='basic'
) )