From f6ad98a95cc4a638e133538ae682185032c16201 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Fri, 21 Jul 2017 17:19:58 +0100 Subject: COMPMID-415: Move SoftmaxLayer to new validation Change-Id: I68bb359021256e67892e4fc00d436f9027a3bd07 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80942 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/validation/TensorOperations.h | 79 ------------------------------------- 1 file changed, 79 deletions(-) (limited to 'tests/validation/TensorOperations.h') diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index 359dfe8d03..5018bfdb2b 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -1606,85 +1606,6 @@ void roi_pooling_layer(const Tensor &in, Tensor &out, const std::vector::value, int>::type * = nullptr> -void softmax_layer(const Tensor &in, Tensor &out) -{ - const int cols = static_cast(in.shape()[0]); - const int upper_dims = in.shape().total_size() / cols; - for(int r = 0; r < upper_dims; ++r) - { - // Find max - T max = std::numeric_limits::lowest(); - for(int c = 0; c < cols; ++c) - { - const T x = in[r * cols + c]; - if(x > max) - { - max = x; - } - } - - // Regularize - T sum(0); - for(int c = 0; c < cols; ++c) - { - const T res = exp(in[r * cols + c] - max); - out[r * cols + c] = res; - sum += res; - } - - // Normalize - const T norm_val = static_cast(1) / sum; - for(int c = 0; c < cols; ++c) - { - out[r * cols + c] *= norm_val; - } - } -} -template ::value, int>::type * = nullptr> -void softmax_layer(const Tensor &in, Tensor &out) -{ - using namespace fixed_point_arithmetic; - using promoted_T = typename test::traits::promote::type; - - const int fixed_point_position = in.fixed_point_position(); - const int cols = static_cast(in.shape()[0]); - const int upper_dims = in.shape().total_size() / cols; - - for(int r = 0; r < upper_dims; ++r) - { - // Find max - fixed_point max(std::numeric_limits::lowest(), fixed_point_position, true); - for(int c = 0; c < cols; ++c) - { - const fixed_point x(in[r * cols + c], fixed_point_position, true); - if(x > max) - { - max = x; - } - } - - // Regularize - fixed_point sum(0, fixed_point_position); - for(int c = 0; c < cols; ++c) - { - const fixed_point x(in[r * cols + c], fixed_point_position, true); - fixed_point res = exp(x - max); - out[r * cols + c] = res.raw(); - sum = add(sum, static_cast>(res)); - } - - // Normalize - fixed_point sat_sum(sum); - for(int c = 0; c < cols; ++c) - { - const fixed_point x(out[r * cols + c], fixed_point_position, true); - out[r * cols + c] = div(x, sat_sum).raw(); - } - } -} - // Fixed point operations template void fixed_point_operation(const Tensor &in, Tensor &out, FixedPointOp op) -- cgit v1.2.1