From 217c4071cc00d4e18171ccdb992ee37d006eb48d Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Tue, 13 Nov 2018 15:42:36 +0000 Subject: [PATCH] Replace TENSOR_QUANT16_ASYMM with TENSOR_QUANT16_SYMM * Update doc string * Update zero point mutation to check for symmetric quantization Fix: 118671831 Test: VtsHalNeuralnetworksV1_2TargetTest Change-Id: Id1999c793c839b892cfe45cbb245611b12db2a72 Merged-In: Id1999c793c839b892cfe45cbb245611b12db2a72 (cherry picked from commit 48c8820bac243e7eaff680056f2145f1b3b1ab2a) --- neuralnetworks/1.2/types.hal | 12 +++++------- neuralnetworks/1.2/vts/functional/ValidateModel.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/neuralnetworks/1.2/types.hal b/neuralnetworks/1.2/types.hal index 366e626578..fe9b312c2b 100644 --- a/neuralnetworks/1.2/types.hal +++ b/neuralnetworks/1.2/types.hal @@ -33,15 +33,13 @@ enum OperandType : @1.0::OperandType { /** * A tensor of 16 bit signed integers that represent real numbers. * - * Attached to this tensor are two numbers that are used to convert the 16 - * bit integer to the real value and vice versa. These two numbers are: - * - scale: a 32 bit floating point value greater than zero. - * - zeroPoint: a 32 bit integer, in range [-32768, 32767]. + * Attached to this tensor is a number representing real value scale that is + * used to convert the 16 bit number to a real value in the following way: + * realValue = integerValue * scale. * - * The formula is: - * realValue = (integerValue - zeroPoint) * scale. + * scale is a 32 bit floating point with value greater then zero. */ - TENSOR_QUANT16_ASYMM = 7, + TENSOR_QUANT16_SYMM = 7, /** A tensor of 16 bit floating point values. */ TENSOR_FLOAT16 = 8, }; diff --git a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp index e3096426da..c4f1b5e724 100644 --- a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp +++ b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp @@ -161,7 +161,7 @@ static uint32_t getInvalidRank(OperandType type) { case OperandType::TENSOR_FLOAT32: case OperandType::TENSOR_INT32: case OperandType::TENSOR_QUANT8_ASYMM: - case OperandType::TENSOR_QUANT16_ASYMM: + case OperandType::TENSOR_QUANT16_SYMM: return 0; default: return 0; @@ -193,7 +193,7 @@ static float getInvalidScale(OperandType type) { case OperandType::TENSOR_INT32: return -1.0f; case OperandType::TENSOR_QUANT8_ASYMM: - case OperandType::TENSOR_QUANT16_ASYMM: + case OperandType::TENSOR_QUANT16_SYMM: return 0.0f; default: return 0.0f; @@ -225,8 +225,8 @@ static std::vector getInvalidZeroPoints(OperandType type) { return {1}; case OperandType::TENSOR_QUANT8_ASYMM: return {-1, 256}; - case OperandType::TENSOR_QUANT16_ASYMM: - return {-32769, 32768}; + case OperandType::TENSOR_QUANT16_SYMM: + return {-32769, -1, 1, 32768}; default: return {}; } @@ -279,7 +279,7 @@ static void mutateOperand(Operand* operand, OperandType type) { newOperand.zeroPoint = 0; break; case OperandType::TENSOR_QUANT8_ASYMM: - case OperandType::TENSOR_QUANT16_ASYMM: + case OperandType::TENSOR_QUANT16_SYMM: newOperand.dimensions = operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec({1}); newOperand.scale = operand->scale != 0.0f ? operand->scale : 1.0f;