From: 오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Wed, 8 Aug 2018 02:19:34 +0000 (+0900) Subject: [neurun] Handle more operand type (#2190) X-Git-Tag: 0.2~335 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3aebc06ad0d77e7dd393ec474233c38ff21ecd7d;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Handle more operand type (#2190) - Handle more operand type: ANEURALNETWORKS_TENSOR_INT32, ANEURALNETWORKS_TENSOR_QUANT8_ASYMM - Handle exception case related with type - Update unittest skiplist Signed-off-by: Hyeongseok Oh --- diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index 9f0ac0d..ea51559 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -39,9 +39,40 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model, return ANEURALNETWORKS_BAD_STATE; } - // ASSUME A tensor operand always consists of fp32 values - // NOTE We do not care about scala operands. - assert(!(type->dimensionCount > 1) || (type->type == 3 /* ANEURALNETWORKS_TENSOR_FLOAT32 */)); + // ASSUME A tensor operand should consists of fp32 or int32 values. + // NOTE We do not care about scalar operands. + assert((type->dimensionCount == 0) || (type->type == ANEURALNETWORKS_TENSOR_FLOAT32 || + type->type == ANEURALNETWORKS_TENSOR_INT32 || + type->type == ANEURALNETWORKS_TENSOR_QUANT8_ASYMM)); + + // scale and zeroPoint should be zero for scalars and non-fixed point tensors + // Quantized: + // scale: a 32 bit floating point value greater than zero + // zeroPoint: a 32 bit integer, in range [0, 255] + if (type->type == ANEURALNETWORKS_TENSOR_QUANT8_ASYMM) + { + if (!(type->scale > 0.0f)) + { + return ANEURALNETWORKS_BAD_DATA; + } + + if ((type->zeroPoint < 0) || (type->zeroPoint > 255)) + { + return ANEURALNETWORKS_BAD_DATA; + } + } + else if ((type->scale != 0.0f) || (type->zeroPoint != 0)) + { + return ANEURALNETWORKS_BAD_DATA; + } + + // dimensionCount should be zero for scalars + if ((type->dimensionCount != 0) && + ((type->type == ANEURALNETWORKS_FLOAT32) | (type->type == ANEURALNETWORKS_INT32) || + (type->type == ANEURALNETWORKS_UINT32))) + { + return ANEURALNETWORKS_BAD_DATA; + } internal::tflite::operand::Shape shape(type->dimensionCount); diff --git a/runtimes/tests/neural_networks_test/runtime_run_android_nn_test.skip.armv7l-linux.neurun b/runtimes/tests/neural_networks_test/runtime_run_android_nn_test.skip.armv7l-linux.neurun index eb97697..6ac1b4b 100644 --- a/runtimes/tests/neural_networks_test/runtime_run_android_nn_test.skip.armv7l-linux.neurun +++ b/runtimes/tests/neural_networks_test/runtime_run_android_nn_test.skip.armv7l-linux.neurun @@ -2,7 +2,6 @@ # Following tests will be skipped on armv7l-linux # # Segmentation fault -ValidationTestModel.AddOperand ValidationTestModel.SetOptionalOperand ValidationTestModel.SetOperandValue ValidationTestModel.SetOperandValueFromMemory