From 7ee5d2c3b3cee5a924ed6347fef613ee07b5aca7 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Fri, 27 Mar 2020 11:11:50 +0000 Subject: IVGCVSW-3753 Add Clip support to the onnx parser Change-Id: I68c842c5906f03b8f5a6131537fea3a1a0db980a Signed-off-by: Finn Williams --- src/armnnOnnxParser/test/Clip.cpp | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/armnnOnnxParser/test/Clip.cpp (limited to 'src/armnnOnnxParser/test') diff --git a/src/armnnOnnxParser/test/Clip.cpp b/src/armnnOnnxParser/test/Clip.cpp new file mode 100644 index 0000000000..6420304291 --- /dev/null +++ b/src/armnnOnnxParser/test/Clip.cpp @@ -0,0 +1,112 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include +#include "armnnOnnxParser/IOnnxParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(OnnxParser) + +struct ClipMainFixture : public armnnUtils::ParserPrototxtFixture +{ + ClipMainFixture(std::string min, std::string max) + { + m_Prototext = R"( + ir_version: 3 + producer_name: "CNTK" + producer_version: "2.5.1" + domain: "ai.cntk" + model_version: 1 + graph { + name: "CNTKGraph" + input { + name: "Input" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 5 + } + } + } + } + } + node { + input: "Input" + input:")" + min + R"(" + input:")" + max + R"(" + output: "Output" + name: "ActivationLayer" + op_type: "Clip" + } + output { + name: "Output" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 5 + } + } + } + } + } + } + opset_import { + version: 7 + })"; + Setup(); + } +}; + +struct ClipFixture : ClipMainFixture +{ + ClipFixture() : ClipMainFixture("2", "3.5") {} +}; + +BOOST_FIXTURE_TEST_CASE(ValidClipTest, ClipFixture) +{ + RunTest<1>({{"Input", { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}}, + {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}}); +} + +struct ClipNoMaxInputFixture : ClipMainFixture +{ + ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {} +}; + +BOOST_FIXTURE_TEST_CASE(ValidNoMaxInputClipTest, ClipNoMaxInputFixture) +{ + RunTest<1>({{"Input", { -1.5f, -5.25f, -0.5f, 8.0f, std::numeric_limits::max() }}}, + {{ "Output", { 0.0f, 0.0f, 0.0f, 8.0f, std::numeric_limits::max() }}}); +} + +struct ClipNoMinInputFixture : ClipMainFixture +{ + ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {} +}; + +BOOST_FIXTURE_TEST_CASE(ValidNoMinInputClipTest, ClipNoMinInputFixture) +{ + RunTest<1>({{"Input", { std::numeric_limits::lowest(), -5.25f, -0.5f, 8.0f, 200.0f }}}, + {{ "Output", { std::numeric_limits::lowest(), -5.25f, -0.5f, 6.0f, 6.0f }}}); +} + +struct ClipNoInputFixture : ClipMainFixture +{ + ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {} +}; + +BOOST_FIXTURE_TEST_CASE(ValidNoInputClipTest, ClipNoInputFixture) +{ + RunTest<1>({{"Input", { std::numeric_limits::lowest(), -1.25f, 3.5f, 8.0f, + std::numeric_limits::max()}}}, + {{ "Output", { std::numeric_limits::lowest(), -1.25f, 3.5f, 8.0f, + std::numeric_limits::max()}}}); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1