From acb6e5bc28820b724f62c5aae5975df178cd0e15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=A5=EC=A7=80=EC=84=AD/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Thu, 14 Jun 2018 16:40:26 +0900 Subject: [PATCH] Change quantization of test codes to default value. (#1655) In case of the scalars and non-fixed point tensors, scale value is changed to 0.0f by TFLite because it is not used. However in TFLITE, scale value of TENSOR_INT32 is passed on to the runtime and may be used depending on each operation. So This commit set scale value to default value(0.0f) in order to clarify the value is not used. Signed-off-by: jiseob.jang --- include/support/tflite/Quantization.h | 24 +++++++++++++++++++++++ tools/nnapi_unittests/tests/add_1.cpp | 6 ++---- tools/nnapi_unittests/tests/add_2.cpp | 6 ++---- tools/nnapi_unittests/tests/avg_pool_1.cpp | 3 ++- tools/nnapi_unittests/tests/concat_1.cpp | 6 ++---- tools/nnapi_unittests/tests/conv_1.cpp | 6 ++---- tools/nnapi_unittests/tests/dconv_1.cpp | 6 ++---- tools/nnapi_unittests/tests/div_1.cpp | 6 ++---- tools/nnapi_unittests/tests/div_2.cpp | 6 ++---- tools/nnapi_unittests/tests/fully_connected_1.cpp | 6 ++---- tools/nnapi_unittests/tests/max_pool_1.cpp | 6 ++---- tools/nnapi_unittests/tests/reshape_1.cpp | 8 ++++---- tools/nnapi_unittests/tests/resize_bilinear_1.cpp | 8 ++++---- tools/nnapi_unittests/tests/softmax_1.cpp | 6 ++---- tools/nnapi_unittests/tests/sub_1.cpp | 6 ++---- tools/nnapi_unittests/tests/sub_2.cpp | 6 ++---- tools/nnapi_unittests/tests/topk_v2_1.cpp | 8 ++++---- 17 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 include/support/tflite/Quantization.h diff --git a/include/support/tflite/Quantization.h b/include/support/tflite/Quantization.h new file mode 100644 index 0000000..734ef8c --- /dev/null +++ b/include/support/tflite/Quantization.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NNFW_SUPPORT_TFLITE_QUANTIZATION_H__ +#define __NNFW_SUPPORT_TFLITE_QUANTIZATION_H__ + +#include "tensorflow/contrib/lite/context.h" + +TfLiteQuantizationParams make_default_quantization(void) { return TfLiteQuantizationParams { 0.0f, 0 }; } + +#endif // __NNFW_SUPPORT_TFLITE_QUANTIZATION_H__ diff --git a/tools/nnapi_unittests/tests/add_1.cpp b/tools/nnapi_unittests/tests/add_1.cpp index f778cdf..91e84f6 100644 --- a/tools/nnapi_unittests/tests/add_1.cpp +++ b/tools/nnapi_unittests/tests/add_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -108,10 +109,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/add_2.cpp b/tools/nnapi_unittests/tests/add_2.cpp index a9acbba..6780842 100644 --- a/tools/nnapi_unittests/tests/add_2.cpp +++ b/tools/nnapi_unittests/tests/add_2.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -124,10 +125,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/avg_pool_1.cpp b/tools/nnapi_unittests/tests/avg_pool_1.cpp index edb21a8..75835bb 100644 --- a/tools/nnapi_unittests/tests/avg_pool_1.cpp +++ b/tools/nnapi_unittests/tests/avg_pool_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -95,7 +96,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; + TfLiteQuantizationParams quantization = make_default_quantization(); quantization.scale = 1; quantization.zero_point = 0; diff --git a/tools/nnapi_unittests/tests/concat_1.cpp b/tools/nnapi_unittests/tests/concat_1.cpp index dd886b7..a8fafc9 100644 --- a/tools/nnapi_unittests/tests/concat_1.cpp +++ b/tools/nnapi_unittests/tests/concat_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -103,10 +104,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(depths.size() + 1); diff --git a/tools/nnapi_unittests/tests/conv_1.cpp b/tools/nnapi_unittests/tests/conv_1.cpp index e447235..d5a3fd4 100644 --- a/tools/nnapi_unittests/tests/conv_1.cpp +++ b/tools/nnapi_unittests/tests/conv_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -146,10 +147,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(5); diff --git a/tools/nnapi_unittests/tests/dconv_1.cpp b/tools/nnapi_unittests/tests/dconv_1.cpp index fef41cf..27808c0 100644 --- a/tools/nnapi_unittests/tests/dconv_1.cpp +++ b/tools/nnapi_unittests/tests/dconv_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -143,10 +144,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(4); diff --git a/tools/nnapi_unittests/tests/div_1.cpp b/tools/nnapi_unittests/tests/div_1.cpp index 6bdbb0c..51ae3a7 100644 --- a/tools/nnapi_unittests/tests/div_1.cpp +++ b/tools/nnapi_unittests/tests/div_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -108,10 +109,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/div_2.cpp b/tools/nnapi_unittests/tests/div_2.cpp index d31179b..9b9e8d3 100644 --- a/tools/nnapi_unittests/tests/div_2.cpp +++ b/tools/nnapi_unittests/tests/div_2.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -102,10 +103,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/fully_connected_1.cpp b/tools/nnapi_unittests/tests/fully_connected_1.cpp index 16c5062..c432fae 100644 --- a/tools/nnapi_unittests/tests/fully_connected_1.cpp +++ b/tools/nnapi_unittests/tests/fully_connected_1.cpp @@ -22,6 +22,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -129,10 +130,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(4); diff --git a/tools/nnapi_unittests/tests/max_pool_1.cpp b/tools/nnapi_unittests/tests/max_pool_1.cpp index 38a22de..ae11133 100644 --- a/tools/nnapi_unittests/tests/max_pool_1.cpp +++ b/tools/nnapi_unittests/tests/max_pool_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -104,10 +105,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(2); diff --git a/tools/nnapi_unittests/tests/reshape_1.cpp b/tools/nnapi_unittests/tests/reshape_1.cpp index 780abf8..563eed9 100644 --- a/tools/nnapi_unittests/tests/reshape_1.cpp +++ b/tools/nnapi_unittests/tests/reshape_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -86,10 +87,9 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + // A: This may be necessary, because quantization values(scale, zero_point) of TENSOR_INT32 and + // TENSOR_QUANT8_ASYMM are passed on to the runtime. + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/resize_bilinear_1.cpp b/tools/nnapi_unittests/tests/resize_bilinear_1.cpp index cf3395a..59fc315 100644 --- a/tools/nnapi_unittests/tests/resize_bilinear_1.cpp +++ b/tools/nnapi_unittests/tests/resize_bilinear_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -90,10 +91,9 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + // A: This may be necessary, because quantization values(scale, zero_point) of TENSOR_INT32 and + // TENSOR_QUANT8_ASYMM are passed on to the runtime. + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/softmax_1.cpp b/tools/nnapi_unittests/tests/softmax_1.cpp index bb22483..f80700f 100644 --- a/tools/nnapi_unittests/tests/softmax_1.cpp +++ b/tools/nnapi_unittests/tests/softmax_1.cpp @@ -24,6 +24,7 @@ #include "util/feature/Shape.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -72,10 +73,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(2); diff --git a/tools/nnapi_unittests/tests/sub_1.cpp b/tools/nnapi_unittests/tests/sub_1.cpp index 13a408a..ea4a34d 100644 --- a/tools/nnapi_unittests/tests/sub_1.cpp +++ b/tools/nnapi_unittests/tests/sub_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -108,10 +109,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/sub_2.cpp b/tools/nnapi_unittests/tests/sub_2.cpp index 772621a..732ce0e 100644 --- a/tools/nnapi_unittests/tests/sub_2.cpp +++ b/tools/nnapi_unittests/tests/sub_2.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -102,10 +103,7 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(3); diff --git a/tools/nnapi_unittests/tests/topk_v2_1.cpp b/tools/nnapi_unittests/tests/topk_v2_1.cpp index 1b5a0de..146c9c7 100644 --- a/tools/nnapi_unittests/tests/topk_v2_1.cpp +++ b/tools/nnapi_unittests/tests/topk_v2_1.cpp @@ -23,6 +23,7 @@ #include "util/environment.h" #include "support/tflite/Diff.h" +#include "support/tflite/Quantization.h" #include "support/tflite/interp/FunctionBuilder.h" #include @@ -87,10 +88,9 @@ int main(int argc, char **argv) // real_value = scale * (quantized_value - zero_point); // // Q: Is this necessary? - TfLiteQuantizationParams quantization; - - quantization.scale = 1; - quantization.zero_point = 0; + // A: This may be necessary, because quantization values(scale, zero_point) of TENSOR_INT32 and + // TENSOR_QUANT8_ASYMM are passed on to the runtime. + TfLiteQuantizationParams quantization = make_default_quantization(); // On AddTensors(N) call, T/F Lite interpreter creates N tensors whose index is [0 ~ N) interp.AddTensors(4); -- 2.7.4