aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-10-02 14:52:16 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-02 15:00:22 -0700
commit664f3dde67bfa436e5216ae54ee256761c7c6962 (patch)
tree6ddafc5ff4dc42d551d6186c11ba4c27fae86899 /tensorflow/contrib/lite
parenteb3e7423661c30b9239d3a29eb789ca6e9ef4793 (diff)
Do not warn about loss of accuracy in trivial cases when all array elements
are equal to either the min or the max value, so that they are trivially exactly quantized. This case does not normally occur for true learned weights, which is what this warning is intended for. PiperOrigin-RevId: 215463096
Diffstat (limited to 'tensorflow/contrib/lite')
-rw-r--r--tensorflow/contrib/lite/toco/graph_transformations/quantize.cc30
1 files changed, 21 insertions, 9 deletions
diff --git a/tensorflow/contrib/lite/toco/graph_transformations/quantize.cc b/tensorflow/contrib/lite/toco/graph_transformations/quantize.cc
index 1bc366f555..fb299c31b7 100644
--- a/tensorflow/contrib/lite/toco/graph_transformations/quantize.cc
+++ b/tensorflow/contrib/lite/toco/graph_transformations/quantize.cc
@@ -97,15 +97,6 @@ const MinMax& GetOrComputeMinMax(Model* model, const string& array_name) {
// to allow easily trying out quantization even if the graph
// lacks some minmax information.
if (array.buffer != nullptr) {
- LOG(WARNING)
- << "Constant array " << array_name
- << " lacks MinMax information. To make up for that, we will now compute"
- << " the MinMax from actual array elements. That will result in"
- << " quantization parameters that probably do not match whichever "
- "arithmetic"
- << " was used during training, and thus will probably be a cause of "
- "poor"
- << " inference accuracy.";
CHECK(array.buffer->type == ArrayDataType::kFloat);
const auto& data = array.GetBuffer<ArrayDataType::kFloat>().data;
// We always want [min, max] to contain 0.
@@ -120,6 +111,27 @@ const MinMax& GetOrComputeMinMax(Model* model, const string& array_name) {
// to not be equal.
max = 1.f;
}
+ // No need to warn about accuracy if all array values are equal to either
+ // min or max:
+ // in that case, quantization is exact, and such arrays are not learned
+ // weights arrays for which fake-quantization would make sense, rather
+ // they tend to be hardcoded arrays of zeros or ones used in some graphs.
+ bool is_quantization_trivially_exact = true;
+ for (auto val : data) {
+ is_quantization_trivially_exact &= (val == min || val == max);
+ }
+ if (!is_quantization_trivially_exact) {
+ LOG(WARNING)
+ << "Constant array " << array_name
+ << " lacks MinMax information. To make up for that, we will now "
+ "compute"
+ << " the MinMax from actual array elements. That will result in"
+ << " quantization parameters that probably do not match whichever "
+ "arithmetic"
+ << " was used during training, and thus will probably be a cause of "
+ "poor"
+ << " inference accuracy.";
+ }
auto& minmax = array.GetOrCreateMinMax();
minmax.min = min;
minmax.max = max;