From 0fb6cf5b6f41a3734ab439f970ba94b96be06c5d Mon Sep 17 00:00:00 2001 From: zhenglin Date: Tue, 12 Dec 2017 15:56:09 +0800 Subject: APPBROWSER-340: Implement NormalizePlanarYUV operator Change-Id: I943fe27ed83e6c499d8f9919c7083f39f6f25acc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/113211 Tested-by: Jenkins Reviewed-by: Stephen Li Reviewed-by: Anthony Barbier --- .../GLES_COMPUTE/NormalizePlanarYUVLayer.cpp | 56 +++++++++ .../fixtures/NormalizePlanarYUVLayerFixture.h | 103 +++++++++++++++ tests/datasets/NormalizePlanarYUVLayerDataset.h | 107 ++++++++++++++++ .../RandomNormalizePlanarYUVLayerDataset.h | 54 ++++++++ ...eNetInceptionV4NormalizePlanarYUVLayerDataset.h | 94 ++++++++++++++ .../GLES_COMPUTE/NormalizePlanarYUVLayer.cpp | 88 +++++++++++++ tests/validation/Helpers.h | 14 +++ .../fixtures/NormalizePlanarYUVLayerFixture.h | 140 +++++++++++++++++++++ .../reference/NormalizePlanarYUVLayer.cpp | 69 ++++++++++ .../validation/reference/NormalizePlanarYUVLayer.h | 44 +++++++ 10 files changed, 769 insertions(+) create mode 100644 tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp create mode 100644 tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h create mode 100644 tests/datasets/NormalizePlanarYUVLayerDataset.h create mode 100644 tests/datasets/RandomNormalizePlanarYUVLayerDataset.h create mode 100644 tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h create mode 100644 tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp mode change 100644 => 100755 tests/validation/Helpers.h create mode 100644 tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h create mode 100644 tests/validation/reference/NormalizePlanarYUVLayer.cpp create mode 100644 tests/validation/reference/NormalizePlanarYUVLayer.h (limited to 'tests') diff --git a/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp b/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..332418015d --- /dev/null +++ b/tests/benchmark/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,56 @@ +/* + * 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, + * FITCLSS 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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" +#include "tests/GLES_COMPUTE/GCAccessor.h" +#include "tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h" +#include "tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace +{ +const auto data_types = framework::dataset::make("DataType", { DataType::F16 }); +} // namespace + +using GCNormalizePlanarYUVLayerFixture = NormalizePlanarYUVLayerFixture; + +TEST_SUITE(GC) + +REGISTER_FIXTURE_DATA_TEST_CASE(GoogLeNetInceptionV4NormalizePlanarYUVLayer, GCNormalizePlanarYUVLayerFixture, framework::DatasetMode::ALL, + framework::dataset::combine(framework::dataset::combine(datasets::GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset(), + data_types), + framework::dataset::make("Batches", 1))); + +TEST_SUITE_END() +} // namespace test +} // namespace arm_compute diff --git a/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h new file mode 100644 index 0000000000..92343534dc --- /dev/null +++ b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h @@ -0,0 +1,103 @@ +/* + * 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_NORMALIZEPLANARYUVLAYERFIXTURE +#define ARM_COMPUTE_TEST_NORMALIZEPLANARYUVLAYERFIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "tests/framework/Fixture.h" +#ifdef ARM_COMPUTE_GC +#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" +#include "tests/GLES_COMPUTE/Helper.h" + +using namespace arm_compute::test::gles_compute; +#endif /* ARM_COMPUTE_GC */ + +namespace arm_compute +{ +namespace test +{ +/** Fixture that can be used for NEON and CL */ +template +class NormalizePlanarYUVLayerFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape tensor_shape, TensorShape param_shape, DataType data_type, int batches) + { + // Set batched in source and destination shapes + tensor_shape.set(tensor_shape.num_dimensions(), batches); + + // Create tensors + src = create_tensor(tensor_shape, data_type, 1); + dst = create_tensor(tensor_shape, data_type, 1); + mean = create_tensor(param_shape, data_type, 1); + sd = create_tensor(param_shape, data_type, 1); + + // Create and configure function + normalize_planar_yuv_layer.configure(&src, &dst, &mean, &sd); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + mean.allocator()->allocate(); + sd.allocator()->allocate(); + + // Fill tensors + library->fill_tensor_uniform(Accessor(src), 0); + library->fill_tensor_uniform(Accessor(mean), 1); + library->fill_tensor_uniform(Accessor(sd), 2); + } + + void run() + { + normalize_planar_yuv_layer.run(); +#ifdef ARM_COMPUTE_GC + if(opengles31_is_available() && std::is_same::type, arm_compute::GCTensor>::value) + { + force_sync_tensor(dst); + } +#endif /* ARM_COMPUTE_GC */ + } + + void teardown() + { + src.allocator()->free(); + dst.allocator()->free(); + mean.allocator()->free(); + sd.allocator()->free(); + } + +private: + TensorType src{}; + TensorType dst{}; + TensorType mean{}; + TensorType sd{}; + Function normalize_planar_yuv_layer{}; +}; +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZEPLANARYUVLAYERFIXTURE */ diff --git a/tests/datasets/NormalizePlanarYUVLayerDataset.h b/tests/datasets/NormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..2d71a56a30 --- /dev/null +++ b/tests/datasets/NormalizePlanarYUVLayerDataset.h @@ -0,0 +1,107 @@ +/* + * 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_NORMALIZE_PLANAR_YUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_DATASET + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class NormalizePlanarYUVLayerDataset +{ +public: + using type = std::tuple; + + struct iterator + { + iterator(std::vector::const_iterator tensor_it, + std::vector::const_iterator param_it) + : _tensor_it{ std::move(tensor_it) }, + _param_it{ std::move(param_it) } + { + } + + std::string description() const + { + std::stringstream description; + description << "In=" << *_tensor_it << ":"; + description << "Out=" << *_tensor_it << ":"; + description << "Mean=" << *_param_it << ":"; + description << "Sd=" << *_param_it << ":"; + return description.str(); + } + + NormalizePlanarYUVLayerDataset::type operator*() const + { + return std::make_tuple(*_tensor_it, *_param_it); + } + + iterator &operator++() + { + ++_tensor_it; + ++_param_it; + + return *this; + } + + private: + std::vector::const_iterator _tensor_it; + std::vector::const_iterator _param_it; + }; + + iterator begin() const + { + return iterator(_tensor_shapes.begin(), _param_shapes.begin()); + } + + int size() const + { + return std::min(_tensor_shapes.size(), _param_shapes.size()); + } + + void add_config(TensorShape tensor, TensorShape param) + { + _tensor_shapes.emplace_back(std::move(tensor)); + _param_shapes.emplace_back(std::move(param)); + } + +protected: + NormalizePlanarYUVLayerDataset() = default; + NormalizePlanarYUVLayerDataset(NormalizePlanarYUVLayerDataset &&) = default; + +private: + std::vector _tensor_shapes{}; + std::vector _param_shapes{}; +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_DATASET */ diff --git a/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h b/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..5693004070 --- /dev/null +++ b/tests/datasets/RandomNormalizePlanarYUVLayerDataset.h @@ -0,0 +1,54 @@ +/* + * 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_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET + +#include "tests/datasets/NormalizePlanarYUVLayerDataset.h" + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class RandomNormalizePlanarYUVLayerDataset final : public NormalizePlanarYUVLayerDataset +{ +public: + RandomNormalizePlanarYUVLayerDataset() + { + add_config(TensorShape(15U, 4U, 4U, 1U), TensorShape(4U)); + add_config(TensorShape(21U, 11U, 12U, 1U), TensorShape(12U)); + add_config(TensorShape(7U, 3U, 6U, 1U), TensorShape(6U)); + add_config(TensorShape(7U, 2U, 3U, 1U), TensorShape(3U)); + } +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_RANDOM_NORMALIZE_PLANAR_YUV_LAYER_DATASET */ diff --git a/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h new file mode 100644 index 0000000000..e0da484b7d --- /dev/null +++ b/tests/datasets/system_tests/googlenet/inceptionv4/GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset.h @@ -0,0 +1,94 @@ +/* + * 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_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET +#define ARM_COMPUTE_TEST_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET + +#include "tests/datasets/NormalizePlanarYUVLayerDataset.h" + +#include "utils/TypePrinter.h" + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset final : public NormalizePlanarYUVLayerDataset +{ +public: + GoogLeNetInceptionV4NormalizePlanarYUVLayerDataset() + { + // conv1_3x3_s2_bn + add_config(TensorShape(149U, 149U, 32U), TensorShape(32U)); + // conv2_3x3_s1_bn + add_config(TensorShape(147U, 147U, 32U), TensorShape(32U)); + // conv3_3x3_s1_bn + add_config(TensorShape(147U, 147U, 64U), TensorShape(64U)); + // inception_stem1_3x3_s2_bn + add_config(TensorShape(73U, 73U, 96U), TensorShape(96U)); + // inception_stem2_3x3_reduce_bn, inception_stem2_1x7_reduce_bn, inception_stem2_1x7_bn, inception_stem2_7x1_bn + add_config(TensorShape(73U, 73U, 64U), TensorShape(64U)); + // inception_stem2_3x3_bn, inception_stem2_3x3_2_bn + add_config(TensorShape(71U, 71U, 96U), TensorShape(96U)); + // inception_stem3_3x3_s2_bn, reduction_a_3x3_2_reduce_bn + add_config(TensorShape(35U, 35U, 192U), TensorShape(192U)); + // inception_a1_1x1_2_bn, inception_a1_3x3_bn, inception_a1_3x3_2_bn, inception_a1_3x3_3_bn, inception_a1_1x1_bn, inception_a2_1x1_2_bn, inception_a2_3x3_bn, inception_a2_3x3_2_bn, inception_a2_3x3_3_bn, inception_a2_1x1_bn, inception_a3_1x1_2_bn, inception_a3_3x3_bn, inception_a3_3x3_2_bn, inception_a3_3x3_3_bn, inception_a3_1x1_bn, inception_a4_1x1_2_bn, inception_a4_3x3_bn, inception_a4_3x3_2_bn, inception_a4_3x3_3_bn, inception_a4_1x1_bn + add_config(TensorShape(35U, 35U, 96U), TensorShape(96U)); + // inception_a1_3x3_reduce_bn, inception_a1_3x3_2_reduce_bn, inception_a2_3x3_reduce_bn, inception_a2_3x3_2_reduce_bn, inception_a3_3x3_reduce_bn, inception_a3_3x3_2_reduce_bn, inception_a4_3x3_reduce_bn, inception_a4_3x3_2_reduce_bn + add_config(TensorShape(35U, 35U, 64U), TensorShape(64U)); + // reduction_a_3x3_bn, inception_b1_1x1_2_bn, inception_b2_1x1_2_bn, inception_b3_1x1_2_bn, inception_b4_1x1_2_bn, inception_b5_1x1_2_bn, inception_b6_1x1_2_bn, inception_b7_1x1_2_bn + add_config(TensorShape(17U, 17U, 384U), TensorShape(384U)); + // reduction_a_3x3_2_bn + add_config(TensorShape(35U, 35U, 224U), TensorShape(224U)); + // reduction_a_3x3_3_bn, inception_b1_7x1_bn, inception_b1_1x7_3_bn, inception_b2_7x1_bn, inception_b2_1x7_3_bn, inception_b3_7x1_bn, inception_b3_1x7_3_bn, inception_b4_7x1_bn, inception_b4_1x7_3_bn, inception_b5_7x1_bn, inception_b5_1x7_3_bn, inception_b6_7x1_bn, inception_b6_1x7_3_bn, inception_b7_7x1_bn, inception_b7_1x7_3_bn, reduction_b_1x7_reduce_bn, reduction_b_1x7_bn + add_config(TensorShape(17U, 17U, 256U), TensorShape(256U)); + // inception_b1_1x7_reduce_bn, inception_b1_7x1_2_reduce_bn, inception_b1_7x1_2_bn, inception_b2_1x7_reduce_bn, inception_b2_7x1_2_reduce_bn, inception_b2_7x1_2_bn, inception_b3_1x7_reduce_bn, inception_b3_7x1_2_reduce_bn, inception_b3_7x1_2_bn, inception_b4_1x7_reduce_bn, inception_b4_7x1_2_reduce_bn, inception_b4_7x1_2_bn, inception_b5_1x7_reduce_bn, inception_b5_7x1_2_reduce_bn, inception_b5_7x1_2_bn, inception_b6_1x7_reduce_bn, inception_b6_7x1_2_reduce_bn, inception_b6_7x1_2_bn, inception_b7_1x7_reduce_bn, inception_b7_7x1_2_reduce_bn, inception_b7_7x1_2_bn, reduction_b_3x3_reduce_bn + add_config(TensorShape(17U, 17U, 192U), TensorShape(192U)); + // inception_b1_1x7_bn, inception_b1_1x7_2_bn, inception_b1_7x1_3_bn, inception_b2_1x7_bn, inception_b2_1x7_2_bn, inception_b2_7x1_3_bn, inception_b3_1x7_bn, inception_b3_1x7_2_bn, inception_b3_7x1_3_bn, inception_b4_1x7_bn, inception_b4_1x7_2_bn, inception_b4_7x1_3_bn, inception_b5_1x7_bn, inception_b5_1x7_2_bn, inception_b5_7x1_3_bn, inception_b6_1x7_bn, inception_b6_1x7_2_bn, inception_b6_7x1_3_bn, inception_b7_1x7_bn, inception_b7_1x7_2_bn, inception_b7_7x1_3_bn + add_config(TensorShape(17U, 17U, 224U), TensorShape(224U)); + // inception_b1_1x1_bn, inception_b2_1x1_bn, inception_b3_1x1_bn, inception_b4_1x1_bn, inception_b5_1x1_bn, inception_b6_1x1_bn, inception_b7_1x1_bn + add_config(TensorShape(17U, 17U, 128U), TensorShape(128U)); + // reduction_b_3x3_bn + add_config(TensorShape(8U, 8U, 192U), TensorShape(192U)); + // reduction_b_7x1_bn + add_config(TensorShape(17U, 17U, 320U), TensorShape(320U)); + // reduction_b_3x3_2_bn + add_config(TensorShape(8U, 8U, 320U), TensorShape(320U)); + // inception_c1_1x1_2_bn, inception_c1_1x3_bn, inception_c1_3x1_bn, inception_c1_1x3_3_bn, inception_c1_3x1_3_bn, inception_c1_1x1_bn, inception_c2_1x1_2_bn, inception_c2_1x3_bn, inception_c2_3x1_bn, inception_c2_1x3_3_bn, inception_c2_3x1_3_bn, inception_c2_1x1_bn, inception_c3_1x1_2_bn, inception_c3_1x3_bn, inception_c3_3x1_bn, inception_c3_1x3_3_bn, inception_c3_3x1_3_bn, inception_c3_1x1_bn + add_config(TensorShape(8U, 8U, 256U), TensorShape(256U)); + // inception_c1_1x1_3_bn, inception_c1_1x1_4_bn, inception_c2_1x1_3_bn, inception_c2_1x1_4_bn, inception_c3_1x1_3_bn, inception_c3_1x1_4_bn + add_config(TensorShape(8U, 8U, 384U), TensorShape(384U)); + // inception_c1_3x1_2_bn, inception_c2_3x1_2_bn, inception_c3_3x1_2_bn + add_config(TensorShape(8U, 8U, 448U), TensorShape(448U)); + // inception_c1_1x3_2_bn, inception_c2_1x3_2_bn, inception_c3_1x3_2_bn + add_config(TensorShape(8U, 8U, 512U), TensorShape(512U)); + } +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_GOOGLENETINCEPTIONV4_NORMALIZEPLANARYUV_LAYER_DATASET */ diff --git a/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..e06b19cfea --- /dev/null +++ b/tests/validation/GLES_COMPUTE/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" +#include "arm_compute/runtime/GLES_COMPUTE/functions/GCNormalizePlanarYUVLayer.h" +#include "tests/GLES_COMPUTE/GCAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/RandomNormalizePlanarYUVLayerDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance tolerance_f16(0.5f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ +} // namespace + +TEST_SUITE(GC) +TEST_SUITE(NormalizePlanarYUVLayer) + +template +using GCNormalizePlanarYUVLayerFixture = NormalizePlanarYUVLayerValidationFixture; + +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), framework::dataset::make("DataType", { DataType::F16 })), + shape0, shape1, dt) +{ + // Create tensors + GCTensor src = create_tensor(shape0, dt, 1); + GCTensor dst = create_tensor(shape0, dt, 1); + GCTensor mean = create_tensor(shape1, dt, 1); + GCTensor sd = create_tensor(shape1, dt, 1); + + // Create and Configure function + GCNormalizePlanarYUVLayer norm; + norm.configure(&src, &dst, &mean, &sd); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape0); + validate(dst.info()->valid_region(), valid_region); +} + +TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(Random, GCNormalizePlanarYUVLayerFixture, framework::DatasetMode::PRECOMMIT, combine(datasets::RandomNormalizePlanarYUVLayerDataset(), + framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(GCAccessor(_target), _reference, tolerance_f16, 0); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h old mode 100644 new mode 100755 index ab7dbd8a41..ba45968392 --- a/tests/validation/Helpers.h +++ b/tests/validation/Helpers.h @@ -202,6 +202,20 @@ std::pair get_batchnormalization_layer_test_bounds(int fixed_point_positio return bounds; } +/** Helper function to get the testing range for NormalizePlanarYUV layer. + * + * @return A pair containing the lower upper testing bounds. + */ +template +std::pair get_normalize_planar_yuv_layer_test_bounds() +{ + std::pair bounds; + + bounds = std::make_pair(-1.f, 1.f); + + return bounds; +} + /** Convert quantized simple tensor into float using tensor quantization information. * * @param[in] src Quantized tensor. diff --git a/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h new file mode 100644 index 0000000000..ae5c53a053 --- /dev/null +++ b/tests/validation/fixtures/NormalizePlanarYUVLayerFixture.h @@ -0,0 +1,140 @@ +/* + * 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_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE +#define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.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/Helpers.h" +#include "tests/validation/reference/NormalizePlanarYUVLayer.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class NormalizePlanarYUVLayerValidationFixedPointFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + _data_type = dt; + _target = compute_target(shape0, shape1, dt); + _reference = compute_reference(shape0, shape1, dt); + } + +protected: + template + void fill(U &&src_tensor, U &&mean_tensor, U &&sd_tensor) + { + if(is_data_type_float(_data_type)) + { + float min_bound = 0.f; + float max_bound = 0.f; + std::tie(min_bound, max_bound) = get_normalize_planar_yuv_layer_test_bounds(); + std::uniform_real_distribution<> distribution(min_bound, max_bound); + std::uniform_real_distribution<> distribution_sd(0, max_bound); + library->fill(src_tensor, distribution, 0); + library->fill(mean_tensor, distribution, 1); + library->fill(sd_tensor, distribution_sd, 2); + } + } + + TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create tensors + TensorType src = create_tensor(shape0, dt, 1); + TensorType dst = create_tensor(shape0, dt, 1); + TensorType mean = create_tensor(shape1, dt, 1); + TensorType sd = create_tensor(shape1, dt, 1); + + // Create and configure function + FunctionType norm; + norm.configure(&src, &dst, &mean, &sd); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + mean.allocator()->allocate(); + sd.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!sd.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src), AccessorType(mean), AccessorType(sd)); + + // Compute function + norm.run(); + + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt) + { + // Create reference + SimpleTensor ref_src{ shape0, dt, 1 }; + SimpleTensor ref_mean{ shape1, dt, 1 }; + SimpleTensor ref_sd{ shape1, dt, 1 }; + + // Fill reference + fill(ref_src, ref_mean, ref_sd); + + return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_sd); + } + + TensorType _target{}; + SimpleTensor _reference{}; + DataType _data_type{}; +}; + +template +class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationFixedPointFixture +{ +public: + template + void setup(TensorShape shape0, TensorShape shape1, DataType dt) + { + NormalizePlanarYUVLayerValidationFixedPointFixture::setup(shape0, shape1, dt); + } +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */ diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.cpp b/tests/validation/reference/NormalizePlanarYUVLayer.cpp new file mode 100644 index 0000000000..2442943bb4 --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.cpp @@ -0,0 +1,69 @@ +/* + * 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. + */ +#include "NormalizePlanarYUVLayer.h" + +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +// NormalizePlanarYUV Layer for floating point type +template ::value, int>::type *> +SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd) +{ + SimpleTensor result(src.shape(), src.data_type()); + + const auto cols = static_cast(src.shape()[0]); + const auto rows = static_cast(src.shape()[1]); + const auto depth = static_cast(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); + + for(int r = 0; r < upper_dims; ++r) + { + for(int i = 0; i < depth; ++i) + { + for(int k = 0; k < rows; ++k) + { + for(int l = 0; l < cols; ++l) + { + const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; + result[pos] = (src[pos] - mean[i]) / sd[i]; + } + } + } + } + return result; +} + +template SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/NormalizePlanarYUVLayer.h b/tests/validation/reference/NormalizePlanarYUVLayer.h new file mode 100644 index 0000000000..c8740a383b --- /dev/null +++ b/tests/validation/reference/NormalizePlanarYUVLayer.h @@ -0,0 +1,44 @@ +/* + * 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_NORMALIZE_PLANAR_YUV_LAYER_H__ +#define __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template ::value, int>::type * = nullptr> +SimpleTensor normalize_planar_yuv_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &sd); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_H__ */ -- cgit v1.2.1