diff options
author | 오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com> | 2019-04-03 09:18:13 +0900 |
---|---|---|
committer | 박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com> | 2019-04-03 09:18:13 +0900 |
commit | 7498918fe7667358ec76fcfc1c5d6dbc1c4d41e3 (patch) | |
tree | a037fd70fee3bcd131ab76203418308df19b387a /libs | |
parent | 467696e917ad7a4b434b20d033af603d373eae62 (diff) | |
download | nnfw-7498918fe7667358ec76fcfc1c5d6dbc1c4d41e3.tar.gz nnfw-7498918fe7667358ec76fcfc1c5d6dbc1c4d41e3.tar.bz2 nnfw-7498918fe7667358ec76fcfc1c5d6dbc1c4d41e3.zip |
Divide by zero check in average pool (#4916)
Change count as int type
Check divide by zero in average pool calculation
Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
Diffstat (limited to 'libs')
-rw-r--r-- | libs/cker/include/cker/operation/AveragePool.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libs/cker/include/cker/operation/AveragePool.h b/libs/cker/include/cker/operation/AveragePool.h index 483c3cda2..1784c1c4a 100644 --- a/libs/cker/include/cker/operation/AveragePool.h +++ b/libs/cker/include/cker/operation/AveragePool.h @@ -74,7 +74,7 @@ inline void AveragePool(const AveragePoolParams ¶ms, const Shape &input_shap const int filter_y_start = std::max(0, -in_y_origin); const int filter_y_end = std::min(params.filter_height, input_height - in_y_origin); float total = 0.f; - float filter_count = 0; + int filter_count = 0; for (int filter_y = filter_y_start; filter_y < filter_y_end; ++filter_y) { for (int filter_x = filter_x_start; filter_x < filter_x_end; ++filter_x) @@ -85,7 +85,8 @@ inline void AveragePool(const AveragePoolParams ¶ms, const Shape &input_shap filter_count++; } } - const float average = total / filter_count; + assert(filter_count != 0); + const float average = total / (float)filter_count; output_data[Offset(output_shape, batch, out_y, out_x, channel)] = ActivationFunctionWithMinMax(average, params.float_activation_min, params.float_activation_max); @@ -137,6 +138,7 @@ inline void AveragePool(const AveragePoolParams ¶ms, const Shape &input_shap filter_count++; } } + assert(filter_count != 0); acc = (acc + filter_count / 2) / filter_count; acc = std::max(acc, params.quantized_activation_min); acc = std::min(acc, params.quantized_activation_max); |