diff options
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/CL/PoolingLayer.cpp | 2 | ||||
-rw-r--r-- | tests/validation/CPP/PoolingLayer.cpp | 54 | ||||
-rw-r--r-- | tests/validation/NEON/PoolingLayer.cpp | 2 |
3 files changed, 45 insertions, 13 deletions
diff --git a/tests/validation/CL/PoolingLayer.cpp b/tests/validation/CL/PoolingLayer.cpp index e82df07a91..44617f624c 100644 --- a/tests/validation/CL/PoolingLayer.cpp +++ b/tests/validation/CL/PoolingLayer.cpp @@ -48,7 +48,7 @@ const auto PoolingLayerDatasetFP = combine(combine(datasets::PoolingTypes(), fra framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); /** Input data set for quantized data types */ -const auto PoolingLayerDatasetQS = combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3 })), +const auto PoolingLayerDatasetQS = combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { 2, 3 })), framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ diff --git a/tests/validation/CPP/PoolingLayer.cpp b/tests/validation/CPP/PoolingLayer.cpp index f7273f073f..85a8343d87 100644 --- a/tests/validation/CPP/PoolingLayer.cpp +++ b/tests/validation/CPP/PoolingLayer.cpp @@ -104,7 +104,7 @@ SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, PoolingLayerInfo info) } } } - else // Average pooling + else // Average or l2 pooling { for(int r = 0; r < upper_dims; ++r) { @@ -123,14 +123,29 @@ SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, PoolingLayerInfo info) wend = std::min(wend, w_src); hend = std::min(hend, h_src); - for(int y = hstart; y < hend; ++y) + if(type == PoolingType::AVG) { - for(int x = wstart; x < wend; ++x) + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + avg_val += src[r * h_src * w_src + y * w_src + x]; + } + } + dst[r * h_dst * w_dst + h * w_dst + w] = avg_val / pool; + } + else + { + for(int y = hstart; y < hend; ++y) { - avg_val += src[r * h_src * w_src + y * w_src + x]; + for(int x = wstart; x < wend; ++x) + { + const T val = src[r * h_src * w_src + y * w_src + x]; + avg_val += val * val; + } } + dst[r * h_dst * w_dst + h * w_dst + w] = std::sqrt(avg_val / pool); } - dst[r * h_dst * w_dst + h * w_dst + w] = avg_val / pool; } } } @@ -192,7 +207,7 @@ SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, PoolingLayerInfo info) } } } - else // Average pooling + else // Average or l2 pooling { for(int r = 0; r < upper_dims; ++r) { @@ -213,18 +228,35 @@ SimpleTensor<T> pooling_layer(const SimpleTensor<T> &src, PoolingLayerInfo info) using namespace fixed_point_arithmetic; const int fixed_point_position = src.fixed_point_position(); + const fixed_point<T> const_1(1, fixed_point_position); const fixed_point<T> invpool_fp(1.f / static_cast<float>(pool), fixed_point_position); fixed_point<T> avg_val(0, fixed_point_position, true); - for(int y = hstart; y < hend; ++y) + if(type == PoolingType::AVG) { - for(int x = wstart; x < wend; ++x) + for(int y = hstart; y < hend; ++y) + { + for(int x = wstart; x < wend; ++x) + { + const fixed_point<T> in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); + avg_val = add(avg_val, in_fp); + } + } + dst[r * h_dst * w_dst + h * w_dst + w] = mul(avg_val, invpool_fp).raw(); + } + else + { + for(int y = hstart; y < hend; ++y) { - const fixed_point<T> in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); - avg_val = add(avg_val, in_fp); + for(int x = wstart; x < wend; ++x) + { + const fixed_point<T> in_fp(src[r * h_src * w_src + y * w_src + x], fixed_point_position, true); + avg_val = add(avg_val, mul(in_fp, in_fp)); + } } + auto res = div(const_1, (inv_sqrt(mul(avg_val, invpool_fp)))); + dst[r * h_dst * w_dst + h * w_dst + w] = res.raw(); } - dst[r * h_dst * w_dst + h * w_dst + w] = mul(avg_val, invpool_fp).raw(); } } } diff --git a/tests/validation/NEON/PoolingLayer.cpp b/tests/validation/NEON/PoolingLayer.cpp index 98ec478267..5ebbc1bc96 100644 --- a/tests/validation/NEON/PoolingLayer.cpp +++ b/tests/validation/NEON/PoolingLayer.cpp @@ -48,7 +48,7 @@ const auto PoolingLayerDatasetFP = combine(combine(datasets::PoolingTypes(), fra framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); /** Input data set for quantized data types */ -const auto PoolingLayerDatasetQS = combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3 })), +const auto PoolingLayerDatasetQS = combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { 2, 3 })), framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |