[neurun] Handle more operand type (#2190)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 8 Aug 2018 02:19:34 +0000 (11:19 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 8 Aug 2018 02:19:34 +0000 (11:19 +0900)
- 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 <hseok82.oh@samsung.com>
runtimes/neurun/src/frontend/model.cc
runtimes/tests/neural_networks_test/runtime_run_android_nn_test.skip.armv7l-linux.neurun

index 9f0ac0d..ea51559 100644 (file)
@@ -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);
 
index eb97697..6ac1b4b 100644 (file)
@@ -2,7 +2,6 @@
 # Following tests will be skipped on armv7l-linux
 #
 # Segmentation fault
-ValidationTestModel.AddOperand
 ValidationTestModel.SetOptionalOperand
 ValidationTestModel.SetOperandValue
 ValidationTestModel.SetOperandValueFromMemory