Update the representative dataset guidance to introduce the signature-based
approach
PiperOrigin-RevId: 390329985
Change-Id: I4d65978a0a55d89e807479b204868a38886956ed
diff --git a/tensorflow/lite/g3doc/performance/post_training_quantization.md b/tensorflow/lite/g3doc/performance/post_training_quantization.md
index 691a40d..c90ec6f 100644
--- a/tensorflow/lite/g3doc/performance/post_training_quantization.md
+++ b/tensorflow/lite/g3doc/performance/post_training_quantization.md
@@ -65,12 +65,30 @@
samples) of the training or validation data. Refer to the
`representative_dataset()` function below.
+From TensorFlow 2.7 version, you can specify the representative dataset through
+a [signature](/lite/guide/signatures) as the following example:
+
+<pre>
+def representative_dataset():
+ for data in dataset:
+ yield {
+ "image": data.image,
+ "bias": data.bias,
+ }
+</pre>
+
+You can generate the representative dataset by providing an input tensor list:
+
<pre>
def representative_dataset():
for data in tf.data.Dataset.from_tensor_slices((images)).batch(1).take(100):
yield [tf.dtypes.cast(data, tf.float32)]
</pre>
+Since TensorFlow 2.7 version, we recommend using the signature-based approach
+over the input tensor list-based approach because the input tensor ordering can
+be easily flipped.
+
For testing purposes, you can use a dummy dataset as follows:
<pre>
diff --git a/tensorflow/lite/python/optimize/calibrator.py b/tensorflow/lite/python/optimize/calibrator.py
index 910adb7..259f817 100644
--- a/tensorflow/lite/python/optimize/calibrator.py
+++ b/tensorflow/lite/python/optimize/calibrator.py
@@ -96,7 +96,7 @@
input_array = sample
else:
raise ValueError("You need to provide either a dictionary with input "
- "names and values and an array with input values in "
+ "names or values and an array with input values in "
"the order of input tensors of the graph in the "
"representative_dataset function. Unsupported value "
"from dataset: {}.".format(sample))