From fba93077f77da374827db941fde31f12e76d3222 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=84=9C=EC=83=81=EB=AF=BC/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 8 Jun 2018 10:03:26 +0900 Subject: [PATCH] Add a workaround when scale for TENSOR_QUANT8_ASYMM is zero (#1605) This patch adds a workaround, which changes `scale` to one when tensor's scale is zero, because currently zero scale is passed down from TF Lite. Note that the latest NeuralNetworks.h (see https://android.googlesource.com/platform/frameworks/ml/+/master/nn/runtime/include/NeuralNetworks.h) requires `scale` to be greater than zero. Remove this workaround when the scale value is correctly passed. Signed-off-by: Sangmin Seo --- libs/support/tflite/src/nnapi_delegate.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/support/tflite/src/nnapi_delegate.cpp b/libs/support/tflite/src/nnapi_delegate.cpp index 599283d..8223529 100644 --- a/libs/support/tflite/src/nnapi_delegate.cpp +++ b/libs/support/tflite/src/nnapi_delegate.cpp @@ -93,6 +93,12 @@ uint32_t addTensorOperands(tflite::Interpreter *interpreter, ANeuralNetworksMode case kTfLiteUInt8: nn_type = ANEURALNETWORKS_TENSOR_QUANT8_ASYMM; scale = tensor->params.scale; + // FIXME The next line is a workaround because currently zero scale is passed down from TF + // Lite. Note that the latest NeuralNetworks.h (see + // https://android.googlesource.com/platform/frameworks/ml/+/master/nn/runtime/include/NeuralNetworks.h) + // requires scale to be greater than zero. Remove this workaround when the scale + // value is correctly passed. + scale = (scale == 0.0f) ? 1.0f : scale; zeroPoint = tensor->params.zero_point; break; case kTfLiteInt32: -- 2.7.4