From bf17955e2bf36c635acbac7c3bb03fbbd7732671 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Tue, 5 Sep 2017 13:51:21 +0100 Subject: COMPMID-522 - Added support for GlobalPooling in CLPoolingLayer and CLFlattening for 3D tensor Change-Id: Ifc7db1e4d4af322a4dcbfeb3e132e5c326596872 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/86618 Reviewed-by: Georgios Pinitas Tested-by: Kaizen --- tests/validation/fixtures/FlattenLayerFixture.h | 128 ++++++++++++++++++++++++ tests/validation/fixtures/PoolingLayerFixture.h | 11 ++ 2 files changed, 139 insertions(+) create mode 100644 tests/validation/fixtures/FlattenLayerFixture.h (limited to 'tests/validation/fixtures') diff --git a/tests/validation/fixtures/FlattenLayerFixture.h b/tests/validation/fixtures/FlattenLayerFixture.h new file mode 100644 index 0000000000..faf53c70a3 --- /dev/null +++ b/tests/validation/fixtures/FlattenLayerFixture.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_FLATTEN_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_FLATTEN_LAYER_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/core/Utils.h" +#include "arm_compute/runtime/Tensor.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/CPP/FlattenLayer.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class FlattenLayerValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape, DataType data_type) + { + _fractional_bits = is_data_type_fixed_point(data_type) ? 4 : 0; + _target = compute_target(shape, data_type); + _reference = compute_reference(shape, data_type); + ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(_target.info()->tensor_shape(), _reference.shape()); + } + +protected: + template + void fill(U &&tensor) + { + if(_fractional_bits == 0) + { + std::uniform_real_distribution<> distribution(-1.f, 1.f); + library->fill(tensor, distribution, 0); + } + else + { + const int one_fixed = 1 << _fractional_bits; + std::uniform_int_distribution<> distribution(-one_fixed, one_fixed); + library->fill(tensor, distribution, 0); + } + } + + TensorType compute_target(const TensorShape &shape, DataType data_type) + { + TensorShape shape_flatten(shape); + shape_flatten.set(0, shape[0] * shape[1] * shape[2]); + shape_flatten.remove_dimension(1); + shape_flatten.remove_dimension(1); + + // Create tensors + TensorType src = create_tensor(shape, data_type, 1, _fractional_bits); + TensorType dst = create_tensor(shape_flatten, data_type, 1, _fractional_bits); + + // Create and configure function + FunctionType flatten_layer; + flatten_layer.configure(&src, &dst); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src)); + + // Compute function + flatten_layer.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape, DataType data_type) + { + // Create reference + SimpleTensor src{ shape, data_type, 1, _fractional_bits }; + + // Fill reference + fill(src); + + return reference::flatten_layer(src); + } + + TensorType _target{}; + SimpleTensor _reference{}; + int _fractional_bits{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_FLATTEN_LAYER_FIXTURE */ diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index 5ce4aa6755..775c4125fc 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -128,6 +128,17 @@ public: PoolingLayerValidationFixedPointFixture::setup(shape, pool_type, pool_size, pad_stride_info, data_type, 0); } }; + +template +class GlobalPoolingLayerValidationFixture : public PoolingLayerValidationFixedPointFixture +{ +public: + template + void setup(TensorShape shape, PoolingType pool_type, DataType data_type) + { + PoolingLayerValidationFixedPointFixture::setup(shape, pool_type, shape.x(), PadStrideInfo(1, 1, 0, 0), data_type, 0); + } +}; } // namespace validation } // namespace test } // namespace arm_compute -- cgit v1.2.1