blob: 2b43574d6c5cf0654efe67d22d2ccf904abec690 [file] [log] [blame]
Finn Williams7ee5d2c2020-03-27 11:11:50 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Finn Williams7ee5d2c2020-03-27 11:11:50 +00006#include "armnnOnnxParser/IOnnxParser.hpp"
7#include "ParserPrototxtFixture.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("OnnxParser_Clip")
10{
Finn Williams7ee5d2c2020-03-27 11:11:50 +000011struct ClipMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
12{
13 ClipMainFixture(std::string min, std::string max)
14 {
15 m_Prototext = R"(
16 ir_version: 3
17 producer_name: "CNTK"
18 producer_version: "2.5.1"
19 domain: "ai.cntk"
20 model_version: 1
21 graph {
22 name: "CNTKGraph"
23 input {
24 name: "Input"
25 type {
26 tensor_type {
27 elem_type: 1
28 shape {
29 dim {
30 dim_value: 5
31 }
32 }
33 }
34 }
35 }
36 node {
37 input: "Input"
38 input:")" + min + R"("
39 input:")" + max + R"("
40 output: "Output"
41 name: "ActivationLayer"
42 op_type: "Clip"
43 }
44 output {
45 name: "Output"
46 type {
47 tensor_type {
48 elem_type: 1
49 shape {
50 dim {
51 dim_value: 5
52 }
53 }
54 }
55 }
56 }
57 }
58 opset_import {
59 version: 7
60 })";
61 Setup();
62 }
63};
64
Narumol Prangnawaratf106ab72021-09-15 17:30:37 +010065struct ClipAttributeFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
66{
67 ClipAttributeFixture(std::string min, std::string max)
68 {
69 m_Prototext = R"(
70 ir_version: 3
71 producer_name: "CNTK"
72 producer_version: "2.5.1"
73 domain: "ai.cntk"
74 model_version: 1
75 graph {
76 name: "CNTKGraph"
77 input {
78 name: "Input"
79 type {
80 tensor_type {
81 elem_type: 1
82 shape {
83 dim {
84 dim_value: 5
85 }
86 }
87 }
88 }
89 }
90 node {
91 input: "Input"
92 output: "Output"
93 name: "ActivationLayer"
94 op_type: "Clip"
95 attribute {
96 name: "min"
97 f: )" + min + R"(
98 type: FLOAT
99 }
100 attribute {
101 name: "max"
102 f: )" + max + R"(
103 type: FLOAT
104 }
105 }
106 output {
107 name: "Output"
108 type {
109 tensor_type {
110 elem_type: 1
111 shape {
112 dim {
113 dim_value: 5
114 }
115 }
116 }
117 }
118 }
119 }
120 opset_import {
121 version: 7
122 })";
123 Setup();
124 }
125};
126
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000127struct ClipFixture : ClipMainFixture
128{
129 ClipFixture() : ClipMainFixture("2", "3.5") {}
130};
131
Sadik Armagan1625efc2021-06-10 18:24:34 +0100132TEST_CASE_FIXTURE(ClipFixture, "ValidClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000133{
134 RunTest<1>({{"Input", { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}},
135 {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}});
136}
137
138struct ClipNoMaxInputFixture : ClipMainFixture
139{
140 ClipNoMaxInputFixture() : ClipMainFixture("0", std::string()) {}
141};
142
Sadik Armagan1625efc2021-06-10 18:24:34 +0100143TEST_CASE_FIXTURE(ClipNoMaxInputFixture, "ValidNoMaxInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000144{
145 RunTest<1>({{"Input", { -1.5f, -5.25f, -0.5f, 8.0f, std::numeric_limits<float>::max() }}},
146 {{ "Output", { 0.0f, 0.0f, 0.0f, 8.0f, std::numeric_limits<float>::max() }}});
147}
148
149struct ClipNoMinInputFixture : ClipMainFixture
150{
151 ClipNoMinInputFixture() : ClipMainFixture(std::string(), "6") {}
152};
153
Sadik Armagan1625efc2021-06-10 18:24:34 +0100154TEST_CASE_FIXTURE(ClipNoMinInputFixture, "ValidNoMinInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000155{
156 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 8.0f, 200.0f }}},
157 {{ "Output", { std::numeric_limits<float>::lowest(), -5.25f, -0.5f, 6.0f, 6.0f }}});
158}
159
160struct ClipNoInputFixture : ClipMainFixture
161{
162 ClipNoInputFixture() : ClipMainFixture(std::string(), std::string()) {}
163};
164
Sadik Armagan1625efc2021-06-10 18:24:34 +0100165TEST_CASE_FIXTURE(ClipNoInputFixture, "ValidNoInputClipTest")
Finn Williams7ee5d2c2020-03-27 11:11:50 +0000166{
167 RunTest<1>({{"Input", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
168 std::numeric_limits<float>::max()}}},
169 {{ "Output", { std::numeric_limits<float>::lowest(), -1.25f, 3.5f, 8.0f,
170 std::numeric_limits<float>::max()}}});
171}
172
Narumol Prangnawaratf106ab72021-09-15 17:30:37 +0100173struct ClipMinMaxAttributeFixture : ClipAttributeFixture
174{
175 ClipMinMaxAttributeFixture() : ClipAttributeFixture("2", "3.5") {}
176};
177
178TEST_CASE_FIXTURE(ClipMinMaxAttributeFixture, "ValidClipAttributeTest")
179{
180 RunTest<1>({{ "Input", { -1.5f, 1.25f, 3.5f, 8.0, 2.5}}},
181 {{ "Output", { 2.0f, 2.0f, 3.5f, 3.5, 2.5}}});
182}
183
Sadik Armagan1625efc2021-06-10 18:24:34 +0100184}