From 06c2ded39210a0c1ec86053148ed0b69589262a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=82=A8=EA=B6=81=EC=84=9D/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 30 Aug 2019 14:02:07 +0900 Subject: [PATCH] [neurun] Resolve Division by zero in Softmax layer (#7055) This commit will resolve division by zero in Softmax layer Signed-off-by: Seok NamKoong --- runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc b/runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc index ffeba11..f71a779 100644 --- a/runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc +++ b/runtimes/neurun/backend/cpu/kernel/SoftMaxLayer.cc @@ -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}; } -- 2.7.4