blob: dc3dcb4394b33022d955765d987c13b7000f005e [file] [log] [blame]
Mike Kellyaf484012019-02-20 16:53:11 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Mike Kellyaf484012019-02-20 16:53:11 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Mike Kellyaf484012019-02-20 16:53:11 +00008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009#include <doctest/doctest.h>
10
Mike Kellyaf484012019-02-20 16:53:11 +000011#include <string>
Mike Kellyaf484012019-02-20 16:53:11 +000012
Sadik Armagan1625efc2021-06-10 18:24:34 +010013TEST_SUITE("DeserializeParser_Activation")
14{
Mike Kellyaf484012019-02-20 16:53:11 +000015struct ActivationFixture : public ParserFlatbuffersSerializeFixture
16{
17 explicit ActivationFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& dataType,
20 const std::string& activationType="Sigmoid",
21 const std::string& a = "0.0",
22 const std::string& b = "0.0")
23 {
24 m_JsonString = R"(
25 {
26 inputIds: [0],
27 outputIds: [2],
28 layers: [{
29 layer_type: "InputLayer",
30 layer: {
31 base: {
32 layerBindingId: 0,
33 base: {
34 index: 0,
35 layerName: "InputLayer",
36 layerType: "Input",
37 inputSlots: [{
38 index: 0,
39 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
40 }],
41 outputSlots: [{
42 index: 0,
43 tensorInfo: {
44 dimensions: )" + inputShape + R"(,
45 dataType: )" + dataType + R"(
46 },
47 }],
48 },
49 }
50 },
51 },
52 {
53 layer_type: "ActivationLayer",
54 layer : {
55 base: {
56 index:1,
57 layerName: "ActivationLayer",
58 layerType: "Activation",
59 inputSlots: [{
60 index: 0,
61 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
62 }],
63 outputSlots: [{
64 index: 0,
65 tensorInfo: {
66 dimensions: )" + outputShape + R"(,
67 dataType: )" + dataType + R"(
68 },
69 }],
70 },
71 descriptor: {
72 a: )" + a + R"(,
73 b: )" + b + R"(,
Tee Jung86bc3d82019-10-01 11:25:56 +090074 activationFunction: )" + activationType + R"(
Mike Kellyaf484012019-02-20 16:53:11 +000075 },
76 },
77 },
78 {
79 layer_type: "OutputLayer",
80 layer: {
81 base:{
82 layerBindingId: 2,
83 base: {
84 index: 2,
85 layerName: "OutputLayer",
86 layerType: "Output",
87 inputSlots: [{
88 index: 0,
89 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
90 }],
91 outputSlots: [{
92 index: 0,
93 tensorInfo: {
94 dimensions: )" + outputShape + R"(,
95 dataType: )" + dataType + R"(
96 },
97 }],
98 }
99 }
100 },
101 }]
102 }
103 )";
104 Setup();
105 }
106};
107
108struct SimpleActivationFixture : ActivationFixture
109{
110 SimpleActivationFixture() : ActivationFixture("[1, 2, 2, 1]",
111 "[1, 2, 2, 1]",
112 "QuantisedAsymm8",
113 "ReLu") {}
114};
115
116struct SimpleActivationFixture2 : ActivationFixture
117{
118 SimpleActivationFixture2() : ActivationFixture("[1, 2, 2, 1]",
119 "[1, 2, 2, 1]",
120 "Float32",
121 "ReLu") {}
122};
123
124struct SimpleActivationFixture3 : ActivationFixture
125{
126 SimpleActivationFixture3() : ActivationFixture("[1, 2, 2, 1]",
127 "[1, 2, 2, 1]",
128 "QuantisedAsymm8",
129 "BoundedReLu",
130 "5.0",
131 "0.0") {}
132};
133
134struct SimpleActivationFixture4 : ActivationFixture
135{
136 SimpleActivationFixture4() : ActivationFixture("[1, 2, 2, 1]",
137 "[1, 2, 2, 1]",
138 "Float32",
139 "BoundedReLu",
140 "5.0",
141 "0.0") {}
142};
143
144
Sadik Armagan1625efc2021-06-10 18:24:34 +0100145TEST_CASE_FIXTURE(SimpleActivationFixture, "ActivationReluQuantisedAsymm8")
Mike Kellyaf484012019-02-20 16:53:11 +0000146{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000147 RunTest<4, armnn::DataType::QAsymmU8>(
Mike Kellyaf484012019-02-20 16:53:11 +0000148 0,
149 {{"InputLayer", {10, 0, 2, 0}}},
150 {{"OutputLayer", {10, 0, 2, 0}}});
151}
152
Sadik Armagan1625efc2021-06-10 18:24:34 +0100153TEST_CASE_FIXTURE(SimpleActivationFixture2, "ActivationReluFloat32")
Mike Kellyaf484012019-02-20 16:53:11 +0000154{
155 RunTest<4, armnn::DataType::Float32>(
156 0,
157 {{"InputLayer", {111, -85, 226, 3}}},
158 {{"OutputLayer", {111, 0, 226, 3}}});
159}
160
161
Sadik Armagan1625efc2021-06-10 18:24:34 +0100162TEST_CASE_FIXTURE(SimpleActivationFixture3, "ActivationBoundedReluQuantisedAsymm8")
Mike Kellyaf484012019-02-20 16:53:11 +0000163{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000164 RunTest<4, armnn::DataType::QAsymmU8>(
Mike Kellyaf484012019-02-20 16:53:11 +0000165 0,
166 {{"InputLayer", {10, 0, 2, 0}}},
167 {{"OutputLayer", {5, 0, 2, 0}}});
168}
169
Sadik Armagan1625efc2021-06-10 18:24:34 +0100170TEST_CASE_FIXTURE(SimpleActivationFixture4, "ActivationBoundedReluFloat32")
Mike Kellyaf484012019-02-20 16:53:11 +0000171{
172 RunTest<4, armnn::DataType::Float32>(
173 0,
174 {{"InputLayer", {111, -85, 226, 3}}},
175 {{"OutputLayer", {5, 0, 5, 3}}});
176}
177
Sadik Armagan1625efc2021-06-10 18:24:34 +0100178}