[neurun] Resolve Division by zero in Softmax layer (#7055)
author남궁석/On-Device Lab(SR)/Engineer/삼성전자 <sk.namkoong@samsung.com>
Fri, 30 Aug 2019 05:02:07 +0000 (14:02 +0900)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Fri, 30 Aug 2019 05:02:07 +0000 (14:02 +0900)
This commit will resolve division by zero in Softmax layer

Signed-off-by: Seok NamKoong <sk.namkoong@samsung.com>
runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc

index ffeba11..f71a779 100644 (file)
@@ -81,6 +81,9 @@ void SoftMaxLayer::softmaxFloat32()
   if (getNumberOfDimensions(_inputShape) == 2)
   {
     uint32_t batch_size = getSizeOfDimension(_inputShape, 0);
+    if (batch_size == 0)
+      throw std::runtime_error("batch_size should not be 0");
+
     uint32_t input_size = getNumberOfElements(_inputShape) / batch_size;
     Softmax(_inputData.f, input_size, batch_size, _beta, _outputData.f);
   }
@@ -104,6 +107,9 @@ void SoftMaxLayer::softmaxQuant8()
   if (getNumberOfDimensions(_inputShape) == 2)
   {
     uint32_t batch_size = getSizeOfDimension(_inputShape, 0);
+    if (batch_size == 0)
+      throw std::runtime_error("batch_size should not be 0");
+
     uint32_t input_size = getNumberOfElements(_inputShape) / batch_size;
     shapeIn4D.dimensions = {batch_size, 1, 1, input_size};
   }