Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 1 | // |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2 | // Copyright © 2017,2020-2023 Arm Ltd and Contributors. All rights reserved. |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 6 | #include "../Serializer.hpp" |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 7 | #include "SerializerTestUtils.hpp" |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 8 | |
Matthew Bentham | ff130e2 | 2020-01-17 11:47:42 +0000 | [diff] [blame] | 9 | #include <armnn/Descriptors.hpp> |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 10 | #include <armnn/INetwork.hpp> |
Matthew Bentham | ff130e2 | 2020-01-17 11:47:42 +0000 | [diff] [blame] | 11 | #include <armnn/TypesUtils.hpp> |
| 12 | #include <armnn/LstmParams.hpp> |
| 13 | #include <armnn/QuantizedLstmParams.hpp> |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 14 | #include <armnnDeserializer/IDeserializer.hpp> |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 15 | #include <armnn/utility/IgnoreUnused.hpp> |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 16 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 17 | #include <random> |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 20 | #include <doctest/doctest.h> |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 21 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 22 | using armnnDeserializer::IDeserializer; |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 23 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 24 | TEST_SUITE("SerializerTests") |
| 25 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 26 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 27 | TEST_CASE("SerializeAddition") |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 28 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 29 | const std::string layerName("addition"); |
| 30 | const armnn::TensorInfo tensorInfo({1, 2, 3}, armnn::DataType::Float32); |
| 31 | |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 32 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 33 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 34 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 35 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 36 | armnn::IConnectableLayer* const additionLayer = network->AddAdditionLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 37 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 38 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 39 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 40 | inputLayer0->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(0)); |
| 41 | inputLayer1->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(1)); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 42 | additionLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 43 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 44 | inputLayer0->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 45 | inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 46 | additionLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
Jim Flynn | 3091b06 | 2019-02-15 14:45:04 +0000 | [diff] [blame] | 47 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 48 | std::string serializedNetwork = SerializeNetwork(*network); |
| 49 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(serializedNetwork); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 50 | CHECK(deserializedNetwork); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 51 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 52 | LayerVerifierBase verifier(layerName, {tensorInfo, tensorInfo}, {tensorInfo}); |
| 53 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 54 | } |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 55 | |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 56 | void SerializeArgMinMaxTest(armnn::DataType dataType) |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 57 | { |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 58 | const std::string layerName("argminmax"); |
| 59 | const armnn::TensorInfo inputInfo({1, 2, 3}, armnn::DataType::Float32); |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 60 | const armnn::TensorInfo outputInfo({1, 3}, dataType); |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 61 | |
| 62 | armnn::ArgMinMaxDescriptor descriptor; |
| 63 | descriptor.m_Function = armnn::ArgMinMaxFunction::Max; |
| 64 | descriptor.m_Axis = 1; |
| 65 | |
| 66 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 67 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 68 | armnn::IConnectableLayer* const argMinMaxLayer = network->AddArgMinMaxLayer(descriptor, layerName.c_str()); |
| 69 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 70 | |
| 71 | inputLayer->GetOutputSlot(0).Connect(argMinMaxLayer->GetInputSlot(0)); |
| 72 | argMinMaxLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 73 | |
| 74 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 75 | argMinMaxLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 76 | |
| 77 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 78 | CHECK(deserializedNetwork); |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 79 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 80 | LayerVerifierBaseWithDescriptor<armnn::ArgMinMaxDescriptor> verifier(layerName, |
| 81 | {inputInfo}, |
| 82 | {outputInfo}, |
| 83 | descriptor); |
| 84 | deserializedNetwork->ExecuteStrategy(verifier); |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 87 | TEST_CASE("SerializeArgMinMaxSigned32") |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 88 | { |
| 89 | SerializeArgMinMaxTest(armnn::DataType::Signed32); |
| 90 | } |
| 91 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 92 | TEST_CASE("SerializeArgMinMaxSigned64") |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 93 | { |
| 94 | SerializeArgMinMaxTest(armnn::DataType::Signed64); |
| 95 | } |
| 96 | |
Samuel Yap | a04f4a1 | 2022-08-19 11:14:38 +0100 | [diff] [blame] | 97 | TEST_CASE("SerializeBatchMatMul") |
| 98 | { |
| 99 | const std::string layerName("batchMatMul"); |
| 100 | const armnn::TensorInfo inputXInfo({2, 3, 4, 5}, armnn::DataType::Float32); |
| 101 | const armnn::TensorInfo inputYInfo({2, 4, 3, 5}, armnn::DataType::Float32); |
| 102 | |
| 103 | const armnn::TensorInfo outputInfo({2, 3, 3, 5}, armnn::DataType::Float32); |
| 104 | |
| 105 | armnn::BatchMatMulDescriptor descriptor(false, |
| 106 | false, |
| 107 | false, |
| 108 | false, |
| 109 | armnn::DataLayout::NHWC, |
| 110 | armnn::DataLayout::NHWC); |
| 111 | |
| 112 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 113 | armnn::IConnectableLayer* const inputXLayer = network->AddInputLayer(0); |
| 114 | armnn::IConnectableLayer* const inputYLayer = network->AddInputLayer(1); |
| 115 | |
| 116 | armnn::IConnectableLayer* const batchMatMulLayer = |
| 117 | network->AddBatchMatMulLayer(descriptor, layerName.c_str()); |
| 118 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 119 | |
| 120 | inputXLayer->GetOutputSlot(0).Connect(batchMatMulLayer->GetInputSlot(0)); |
| 121 | inputYLayer->GetOutputSlot(0).Connect(batchMatMulLayer->GetInputSlot(1)); |
| 122 | batchMatMulLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 123 | |
| 124 | inputXLayer->GetOutputSlot(0).SetTensorInfo(inputXInfo); |
| 125 | inputYLayer->GetOutputSlot(0).SetTensorInfo(inputYInfo); |
| 126 | batchMatMulLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 127 | |
| 128 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 129 | CHECK(deserializedNetwork); |
| 130 | |
| 131 | LayerVerifierBaseWithDescriptor<armnn::BatchMatMulDescriptor> verifier(layerName, |
| 132 | {inputXInfo, inputYInfo}, |
| 133 | {outputInfo}, |
| 134 | descriptor); |
| 135 | deserializedNetwork->ExecuteStrategy(verifier); |
| 136 | } |
| 137 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 138 | TEST_CASE("SerializeBatchNormalization") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 139 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 140 | const std::string layerName("batchNormalization"); |
| 141 | const armnn::TensorInfo inputInfo ({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 142 | const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 143 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 144 | const armnn::TensorInfo meanInfo({1}, armnn::DataType::Float32, 0.0f, 0, true); |
| 145 | const armnn::TensorInfo varianceInfo({1}, armnn::DataType::Float32, 0.0f, 0, true); |
| 146 | const armnn::TensorInfo betaInfo({1}, armnn::DataType::Float32, 0.0f, 0, true); |
| 147 | const armnn::TensorInfo gammaInfo({1}, armnn::DataType::Float32, 0.0f, 0, true); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 148 | |
| 149 | armnn::BatchNormalizationDescriptor descriptor; |
| 150 | descriptor.m_Eps = 0.0010000000475f; |
| 151 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 152 | |
| 153 | std::vector<float> meanData({5.0}); |
| 154 | std::vector<float> varianceData({2.0}); |
| 155 | std::vector<float> betaData({1.0}); |
| 156 | std::vector<float> gammaData({0.0}); |
| 157 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 158 | std::vector<armnn::ConstTensor> constants; |
| 159 | constants.emplace_back(armnn::ConstTensor(meanInfo, meanData)); |
| 160 | constants.emplace_back(armnn::ConstTensor(varianceInfo, varianceData)); |
| 161 | constants.emplace_back(armnn::ConstTensor(betaInfo, betaData)); |
| 162 | constants.emplace_back(armnn::ConstTensor(gammaInfo, gammaData)); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 163 | |
| 164 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 165 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 166 | armnn::IConnectableLayer* const batchNormalizationLayer = |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 167 | network->AddBatchNormalizationLayer(descriptor, |
| 168 | constants[0], |
| 169 | constants[1], |
| 170 | constants[2], |
| 171 | constants[3], |
| 172 | layerName.c_str()); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 173 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 174 | |
| 175 | inputLayer->GetOutputSlot(0).Connect(batchNormalizationLayer->GetInputSlot(0)); |
| 176 | batchNormalizationLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 177 | |
| 178 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 179 | batchNormalizationLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 180 | |
| 181 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 182 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 183 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 184 | LayerVerifierBaseWithDescriptorAndConstants<armnn::BatchNormalizationDescriptor> verifier( |
| 185 | layerName, {inputInfo}, {outputInfo}, descriptor, constants); |
| 186 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 189 | TEST_CASE("SerializeBatchToSpaceNd") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 190 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 191 | const std::string layerName("spaceToBatchNd"); |
| 192 | const armnn::TensorInfo inputInfo({4, 1, 2, 2}, armnn::DataType::Float32); |
| 193 | const armnn::TensorInfo outputInfo({1, 1, 4, 4}, armnn::DataType::Float32); |
| 194 | |
| 195 | armnn::BatchToSpaceNdDescriptor desc; |
| 196 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 197 | desc.m_BlockShape = {2, 2}; |
| 198 | desc.m_Crops = {{0, 0}, {0, 0}}; |
| 199 | |
| 200 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 201 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 202 | armnn::IConnectableLayer* const batchToSpaceNdLayer = network->AddBatchToSpaceNdLayer(desc, layerName.c_str()); |
| 203 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 204 | |
| 205 | inputLayer->GetOutputSlot(0).Connect(batchToSpaceNdLayer->GetInputSlot(0)); |
| 206 | batchToSpaceNdLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 207 | |
| 208 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 209 | batchToSpaceNdLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 210 | |
| 211 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 212 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 213 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 214 | LayerVerifierBaseWithDescriptor<armnn::BatchToSpaceNdDescriptor> verifier(layerName, |
| 215 | {inputInfo}, |
| 216 | {outputInfo}, |
| 217 | desc); |
| 218 | deserializedNetwork->ExecuteStrategy(verifier); |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 221 | TEST_CASE("SerializeCast") |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 222 | { |
| 223 | const std::string layerName("cast"); |
| 224 | |
| 225 | const armnn::TensorShape shape{1, 5, 2, 3}; |
| 226 | |
| 227 | const armnn::TensorInfo inputInfo = armnn::TensorInfo(shape, armnn::DataType::Signed32); |
| 228 | const armnn::TensorInfo outputInfo = armnn::TensorInfo(shape, armnn::DataType::Float32); |
| 229 | |
| 230 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 231 | armnn::IConnectableLayer* inputLayer = network->AddInputLayer(0); |
| 232 | armnn::IConnectableLayer* castLayer = network->AddCastLayer(layerName.c_str()); |
| 233 | armnn::IConnectableLayer* outputLayer = network->AddOutputLayer(0); |
| 234 | |
| 235 | inputLayer->GetOutputSlot(0).Connect(castLayer->GetInputSlot(0)); |
| 236 | castLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 237 | |
| 238 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 239 | castLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 240 | |
| 241 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 242 | CHECK(deserializedNetwork); |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 243 | |
| 244 | LayerVerifierBase verifier(layerName, {inputInfo}, {outputInfo}); |
| 245 | deserializedNetwork->ExecuteStrategy(verifier); |
| 246 | } |
| 247 | |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 248 | TEST_CASE("SerializeChannelShuffle") |
| 249 | { |
| 250 | const std::string layerName("channelShuffle"); |
| 251 | const armnn::TensorInfo inputInfo({1, 9}, armnn::DataType::Float32); |
| 252 | const armnn::TensorInfo outputInfo({1, 9}, armnn::DataType::Float32); |
| 253 | |
| 254 | armnn::ChannelShuffleDescriptor descriptor({3, 1}); |
| 255 | |
| 256 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 257 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 258 | armnn::IConnectableLayer* const ChannelShuffleLayer = |
| 259 | network->AddChannelShuffleLayer(descriptor, layerName.c_str()); |
| 260 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 261 | |
| 262 | inputLayer->GetOutputSlot(0).Connect(ChannelShuffleLayer->GetInputSlot(0)); |
| 263 | ChannelShuffleLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 264 | |
| 265 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 266 | ChannelShuffleLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 267 | |
| 268 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 269 | CHECK(deserializedNetwork); |
| 270 | |
| 271 | LayerVerifierBaseWithDescriptor<armnn::ChannelShuffleDescriptor> verifier( |
| 272 | layerName, {inputInfo}, {outputInfo}, descriptor); |
| 273 | deserializedNetwork->ExecuteStrategy(verifier); |
| 274 | } |
| 275 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 276 | TEST_CASE("SerializeComparison") |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 277 | { |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 278 | const std::string layerName("comparison"); |
| 279 | |
| 280 | const armnn::TensorShape shape{2, 1, 2, 4}; |
| 281 | |
| 282 | const armnn::TensorInfo inputInfo = armnn::TensorInfo(shape, armnn::DataType::Float32); |
| 283 | const armnn::TensorInfo outputInfo = armnn::TensorInfo(shape, armnn::DataType::Boolean); |
| 284 | |
| 285 | armnn::ComparisonDescriptor descriptor(armnn::ComparisonOperation::NotEqual); |
| 286 | |
| 287 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 288 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 289 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
| 290 | armnn::IConnectableLayer* const comparisonLayer = network->AddComparisonLayer(descriptor, layerName.c_str()); |
| 291 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 292 | |
| 293 | inputLayer0->GetOutputSlot(0).Connect(comparisonLayer->GetInputSlot(0)); |
| 294 | inputLayer1->GetOutputSlot(0).Connect(comparisonLayer->GetInputSlot(1)); |
| 295 | comparisonLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 296 | |
| 297 | inputLayer0->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 298 | inputLayer1->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 299 | comparisonLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 300 | |
| 301 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 302 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 303 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 304 | LayerVerifierBaseWithDescriptor<armnn::ComparisonDescriptor> verifier(layerName, |
| 305 | { inputInfo, inputInfo }, |
| 306 | { outputInfo }, |
| 307 | descriptor); |
| 308 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 311 | TEST_CASE("SerializeConstant") |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 312 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 313 | class ConstantLayerVerifier : public LayerVerifierBase |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 314 | { |
| 315 | public: |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 316 | ConstantLayerVerifier(const std::string& layerName, |
| 317 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 318 | const std::vector<armnn::TensorInfo>& outputInfos, |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 319 | const std::vector<armnn::ConstTensor>& constants) |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 320 | : LayerVerifierBase(layerName, inputInfos, outputInfos) |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 321 | , m_Constants(constants) {} |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 322 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 323 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 324 | const armnn::BaseDescriptor& descriptor, |
| 325 | const std::vector<armnn::ConstTensor>& constants, |
| 326 | const char* name, |
| 327 | const armnn::LayerBindingId id = 0) override |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 328 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 329 | armnn::IgnoreUnused(descriptor, id); |
| 330 | |
| 331 | switch (layer->GetType()) |
| 332 | { |
| 333 | case armnn::LayerType::Input: break; |
| 334 | case armnn::LayerType::Output: break; |
| 335 | case armnn::LayerType::Addition: break; |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 336 | case armnn::LayerType::ElementwiseBinary: break; |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 337 | default: |
| 338 | { |
| 339 | this->VerifyNameAndConnections(layer, name); |
| 340 | |
| 341 | for (std::size_t i = 0; i < constants.size(); i++) |
| 342 | { |
| 343 | CompareConstTensor(constants[i], m_Constants[i]); |
| 344 | } |
| 345 | } |
| 346 | } |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 347 | } |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 348 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 349 | private: |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 350 | const std::vector<armnn::ConstTensor> m_Constants; |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 353 | const std::string layerName("constant"); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 354 | const armnn::TensorInfo info({ 2, 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 355 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 356 | std::vector<float> constantData = GenerateRandomData<float>(info.GetNumElements()); |
| 357 | armnn::ConstTensor constTensor(info, constantData); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 358 | |
Matteo Martincigh | f81edaa | 2019-03-04 14:34:30 +0000 | [diff] [blame] | 359 | armnn::INetworkPtr network(armnn::INetwork::Create()); |
Matteo Martincigh | f81edaa | 2019-03-04 14:34:30 +0000 | [diff] [blame] | 360 | armnn::IConnectableLayer* input = network->AddInputLayer(0); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 361 | armnn::IConnectableLayer* constant = network->AddConstantLayer(constTensor, layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 362 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Matteo Martincigh | f81edaa | 2019-03-04 14:34:30 +0000 | [diff] [blame] | 363 | armnn::IConnectableLayer* add = network->AddAdditionLayer(); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 364 | ARMNN_NO_DEPRECATE_WARN_END |
Matteo Martincigh | f81edaa | 2019-03-04 14:34:30 +0000 | [diff] [blame] | 365 | armnn::IConnectableLayer* output = network->AddOutputLayer(0); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 366 | |
| 367 | input->GetOutputSlot(0).Connect(add->GetInputSlot(0)); |
| 368 | constant->GetOutputSlot(0).Connect(add->GetInputSlot(1)); |
| 369 | add->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 370 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 371 | input->GetOutputSlot(0).SetTensorInfo(info); |
| 372 | constant->GetOutputSlot(0).SetTensorInfo(info); |
| 373 | add->GetOutputSlot(0).SetTensorInfo(info); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 374 | |
Matteo Martincigh | f81edaa | 2019-03-04 14:34:30 +0000 | [diff] [blame] | 375 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 376 | CHECK(deserializedNetwork); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 377 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 378 | ConstantLayerVerifier verifier(layerName, {}, {info}, {constTensor}); |
| 379 | deserializedNetwork->ExecuteStrategy(verifier); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 382 | using Convolution2dDescriptor = armnn::Convolution2dDescriptor; |
| 383 | class Convolution2dLayerVerifier : public LayerVerifierBaseWithDescriptor<Convolution2dDescriptor> |
| 384 | { |
| 385 | public: |
| 386 | Convolution2dLayerVerifier(const std::string& layerName, |
| 387 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 388 | const std::vector<armnn::TensorInfo>& outputInfos, |
| 389 | const Convolution2dDescriptor& descriptor) |
| 390 | : LayerVerifierBaseWithDescriptor<Convolution2dDescriptor>(layerName, inputInfos, outputInfos, descriptor) {} |
| 391 | |
| 392 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 393 | const armnn::BaseDescriptor& descriptor, |
| 394 | const std::vector<armnn::ConstTensor>& constants, |
| 395 | const char* name, |
| 396 | const armnn::LayerBindingId id = 0) override |
| 397 | { |
| 398 | armnn::IgnoreUnused(constants, id); |
| 399 | switch (layer->GetType()) |
| 400 | { |
| 401 | case armnn::LayerType::Input: break; |
| 402 | case armnn::LayerType::Output: break; |
| 403 | case armnn::LayerType::Constant: break; |
| 404 | default: |
| 405 | { |
| 406 | VerifyNameAndConnections(layer, name); |
| 407 | const Convolution2dDescriptor& layerDescriptor = |
| 408 | static_cast<const Convolution2dDescriptor&>(descriptor); |
| 409 | CHECK(layerDescriptor.m_BiasEnabled == m_Descriptor.m_BiasEnabled); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | }; |
| 414 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 415 | TEST_CASE("SerializeConvolution2d") |
Finn Williams | dd2ba7e | 2019-03-01 11:51:52 +0000 | [diff] [blame] | 416 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 417 | const std::string layerName("convolution2d"); |
| 418 | const armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32); |
| 419 | const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 420 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 421 | const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 422 | const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 423 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 424 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 425 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 426 | |
| 427 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 428 | armnn::ConstTensor biases(biasesInfo, biasesData); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 429 | |
| 430 | armnn::Convolution2dDescriptor descriptor; |
| 431 | descriptor.m_PadLeft = 1; |
| 432 | descriptor.m_PadRight = 1; |
| 433 | descriptor.m_PadTop = 1; |
| 434 | descriptor.m_PadBottom = 1; |
| 435 | descriptor.m_StrideX = 2; |
| 436 | descriptor.m_StrideY = 2; |
Aron Virginas-Tar | 5e1b0cf | 2019-06-21 14:20:11 +0100 | [diff] [blame] | 437 | descriptor.m_DilationX = 2; |
| 438 | descriptor.m_DilationY = 2; |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 439 | descriptor.m_BiasEnabled = true; |
| 440 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 441 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 442 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 443 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 444 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "weights"); |
| 445 | armnn::IConnectableLayer* const biasLayer = network->AddConstantLayer(biases, "bias"); |
| 446 | armnn::IConnectableLayer* const convLayer = network->AddConvolution2dLayer(descriptor, layerName.c_str()); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 447 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 448 | |
| 449 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 450 | weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1)); |
| 451 | biasLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(2)); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 452 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 453 | |
| 454 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 455 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 456 | biasLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 457 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 458 | |
| 459 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 460 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 461 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 462 | Convolution2dLayerVerifier verifier(layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 463 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 466 | TEST_CASE("SerializeConvolution2dWithPerAxisParams") |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 467 | { |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 468 | using namespace armnn; |
| 469 | |
| 470 | const std::string layerName("convolution2dWithPerAxis"); |
| 471 | const TensorInfo inputInfo ({ 1, 3, 1, 2 }, DataType::QAsymmU8, 0.55f, 128); |
| 472 | const TensorInfo outputInfo({ 1, 3, 1, 3 }, DataType::QAsymmU8, 0.75f, 128); |
| 473 | |
| 474 | const std::vector<float> quantScales{ 0.75f, 0.65f, 0.85f }; |
| 475 | constexpr unsigned int quantDimension = 0; |
| 476 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 477 | const TensorInfo kernelInfo({ 3, 1, 1, 2 }, DataType::QSymmS8, quantScales, quantDimension, true); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 478 | |
| 479 | const std::vector<float> biasQuantScales{ 0.25f, 0.50f, 0.75f }; |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 480 | const TensorInfo biasInfo({ 3 }, DataType::Signed32, biasQuantScales, quantDimension, true); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 481 | |
| 482 | std::vector<int8_t> kernelData = GenerateRandomData<int8_t>(kernelInfo.GetNumElements()); |
| 483 | armnn::ConstTensor weights(kernelInfo, kernelData); |
| 484 | std::vector<int32_t> biasData = GenerateRandomData<int32_t>(biasInfo.GetNumElements()); |
| 485 | armnn::ConstTensor biases(biasInfo, biasData); |
| 486 | |
| 487 | Convolution2dDescriptor descriptor; |
| 488 | descriptor.m_StrideX = 1; |
| 489 | descriptor.m_StrideY = 1; |
| 490 | descriptor.m_PadLeft = 0; |
| 491 | descriptor.m_PadRight = 0; |
| 492 | descriptor.m_PadTop = 0; |
| 493 | descriptor.m_PadBottom = 0; |
| 494 | descriptor.m_BiasEnabled = true; |
| 495 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 496 | |
| 497 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 498 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 499 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "weights"); |
| 500 | armnn::IConnectableLayer* const biasLayer = network->AddConstantLayer(weights, "bias"); |
| 501 | armnn::IConnectableLayer* const convLayer = network->AddConvolution2dLayer(descriptor, layerName.c_str()); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 502 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 503 | |
| 504 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 505 | weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1)); |
| 506 | biasLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(2)); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 507 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 508 | |
| 509 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
Teresa Charlin | d936033 | 2022-08-30 14:27:10 +0100 | [diff] [blame] | 510 | weightsLayer->GetOutputSlot(0).SetTensorInfo(kernelInfo); |
| 511 | biasLayer->GetOutputSlot(0).SetTensorInfo(biasInfo); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 512 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 513 | |
| 514 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 515 | CHECK(deserializedNetwork); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 516 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 517 | Convolution2dLayerVerifier verifier(layerName, {inputInfo, kernelInfo, biasInfo}, {outputInfo}, descriptor); |
| 518 | |
| 519 | deserializedNetwork->ExecuteStrategy(verifier); |
| 520 | } |
| 521 | |
| 522 | TEST_CASE("SerializeConvolution2dWeightsAndBiasesAsConstantLayers") |
| 523 | { |
| 524 | const std::string layerName("convolution2d"); |
| 525 | const armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32); |
| 526 | const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 527 | |
| 528 | const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 529 | const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 530 | |
| 531 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 532 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 533 | |
| 534 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 535 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 536 | |
| 537 | armnn::Convolution2dDescriptor descriptor; |
| 538 | descriptor.m_PadLeft = 1; |
| 539 | descriptor.m_PadRight = 1; |
| 540 | descriptor.m_PadTop = 1; |
| 541 | descriptor.m_PadBottom = 1; |
| 542 | descriptor.m_StrideX = 2; |
| 543 | descriptor.m_StrideY = 2; |
| 544 | descriptor.m_DilationX = 2; |
| 545 | descriptor.m_DilationY = 2; |
| 546 | descriptor.m_BiasEnabled = true; |
| 547 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 548 | |
| 549 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 550 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 551 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "Weights"); |
| 552 | armnn::IConnectableLayer* const biasesLayer = network->AddConstantLayer(biases, "Biases"); |
| 553 | armnn::IConnectableLayer* const convLayer = network->AddConvolution2dLayer(descriptor, |
| 554 | layerName.c_str()); |
| 555 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 556 | |
| 557 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
| 558 | weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1)); |
| 559 | biasesLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(2)); |
| 560 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 561 | |
| 562 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 563 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 564 | biasesLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
| 565 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 566 | |
| 567 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 568 | CHECK(deserializedNetwork); |
| 569 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 570 | const std::vector<armnn::ConstTensor>& constants {weights, biases}; |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 571 | LayerVerifierBaseWithDescriptorAndConstants<armnn::Convolution2dDescriptor> verifier( |
| 572 | layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor, constants); |
| 573 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 574 | deserializedNetwork->ExecuteStrategy(verifier); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 577 | TEST_CASE("SerializeConvolution3d") |
| 578 | { |
| 579 | const std::string layerName("convolution3d"); |
| 580 | const armnn::TensorInfo inputInfo ({ 1, 5, 5, 5, 1 }, armnn::DataType::Float32); |
| 581 | const armnn::TensorInfo outputInfo({ 1, 2, 2, 2, 1 }, armnn::DataType::Float32); |
| 582 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 583 | const armnn::TensorInfo weightsInfo({ 3, 3, 3, 1, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 584 | const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 585 | |
| 586 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 587 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 588 | |
| 589 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 590 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 591 | |
| 592 | armnn::Convolution3dDescriptor descriptor; |
| 593 | descriptor.m_PadLeft = 0; |
| 594 | descriptor.m_PadRight = 0; |
| 595 | descriptor.m_PadTop = 0; |
| 596 | descriptor.m_PadBottom = 0; |
| 597 | descriptor.m_PadFront = 0; |
| 598 | descriptor.m_PadBack = 0; |
| 599 | descriptor.m_DilationX = 1; |
| 600 | descriptor.m_DilationY = 1; |
| 601 | descriptor.m_DilationZ = 1; |
| 602 | descriptor.m_StrideX = 2; |
| 603 | descriptor.m_StrideY = 2; |
| 604 | descriptor.m_StrideZ = 2; |
| 605 | descriptor.m_BiasEnabled = true; |
| 606 | descriptor.m_DataLayout = armnn::DataLayout::NDHWC; |
| 607 | |
| 608 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 609 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 610 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "Weights"); |
| 611 | armnn::IConnectableLayer* const biasesLayer = network->AddConstantLayer(biases, "Biases"); |
| 612 | armnn::IConnectableLayer* const convLayer = network->AddConvolution3dLayer(descriptor, layerName.c_str()); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 613 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 614 | |
| 615 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 616 | weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1)); |
| 617 | biasesLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(2)); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 618 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 619 | |
| 620 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 621 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 622 | biasesLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 623 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 624 | |
| 625 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 626 | CHECK(deserializedNetwork); |
| 627 | |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 628 | LayerVerifierBaseWithDescriptor<armnn::Convolution3dDescriptor> verifier( |
| 629 | layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 630 | deserializedNetwork->ExecuteStrategy(verifier); |
| 631 | } |
| 632 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 633 | TEST_CASE("SerializeDepthToSpace") |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 634 | { |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 635 | const std::string layerName("depthToSpace"); |
| 636 | |
| 637 | const armnn::TensorInfo inputInfo ({ 1, 8, 4, 12 }, armnn::DataType::Float32); |
| 638 | const armnn::TensorInfo outputInfo({ 1, 16, 8, 3 }, armnn::DataType::Float32); |
| 639 | |
| 640 | armnn::DepthToSpaceDescriptor desc; |
| 641 | desc.m_BlockSize = 2; |
| 642 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 643 | |
| 644 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 645 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 646 | armnn::IConnectableLayer* const depthToSpaceLayer = network->AddDepthToSpaceLayer(desc, layerName.c_str()); |
| 647 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 648 | |
| 649 | inputLayer->GetOutputSlot(0).Connect(depthToSpaceLayer->GetInputSlot(0)); |
| 650 | depthToSpaceLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 651 | |
| 652 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 653 | depthToSpaceLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 654 | |
| 655 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 656 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 657 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 658 | LayerVerifierBaseWithDescriptor<armnn::DepthToSpaceDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, desc); |
| 659 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 660 | } |
| 661 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 662 | TEST_CASE("SerializeDepthwiseConvolution2d") |
Conor Kennedy | 79ffdf5 | 2019-03-01 14:24:54 +0000 | [diff] [blame] | 663 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 664 | const std::string layerName("depwiseConvolution2d"); |
| 665 | const armnn::TensorInfo inputInfo ({ 1, 5, 5, 3 }, armnn::DataType::Float32); |
| 666 | const armnn::TensorInfo outputInfo({ 1, 3, 3, 3 }, armnn::DataType::Float32); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 667 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 668 | const armnn::TensorInfo weightsInfo({ 1, 3, 3, 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 669 | const armnn::TensorInfo biasesInfo ({ 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 670 | |
| 671 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 672 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 673 | |
| 674 | std::vector<int32_t> biasesData = GenerateRandomData<int32_t>(biasesInfo.GetNumElements()); |
| 675 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 676 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 677 | armnn::DepthwiseConvolution2dDescriptor descriptor; |
Aron Virginas-Tar | 5e1b0cf | 2019-06-21 14:20:11 +0100 | [diff] [blame] | 678 | descriptor.m_PadLeft = 1; |
| 679 | descriptor.m_PadRight = 1; |
| 680 | descriptor.m_PadTop = 1; |
| 681 | descriptor.m_PadBottom = 1; |
| 682 | descriptor.m_StrideX = 2; |
| 683 | descriptor.m_StrideY = 2; |
| 684 | descriptor.m_DilationX = 2; |
| 685 | descriptor.m_DilationY = 2; |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 686 | descriptor.m_BiasEnabled = true; |
| 687 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 688 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 689 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 690 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 691 | armnn::IConnectableLayer* const depthwiseConvLayer = network->AddDepthwiseConvolution2dLayer(descriptor, |
| 692 | layerName.c_str()); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 693 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 694 | |
| 695 | inputLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(0)); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 696 | depthwiseConvLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 697 | |
| 698 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 699 | depthwiseConvLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 700 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 701 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights); |
| 702 | weightsLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(1u)); |
| 703 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.GetInfo()); |
| 704 | |
| 705 | armnn::IConnectableLayer* const biasLayer = network->AddConstantLayer(biases); |
| 706 | biasLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(2u)); |
| 707 | biasLayer->GetOutputSlot(0).SetTensorInfo(biases.GetInfo()); |
| 708 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 709 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 710 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 711 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 712 | const std::vector<armnn::ConstTensor>& constants {weights, biases}; |
| 713 | LayerVerifierBaseWithDescriptorAndConstants<armnn::DepthwiseConvolution2dDescriptor> verifier( |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 714 | layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor, constants); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 715 | deserializedNetwork->ExecuteStrategy(verifier); |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 718 | TEST_CASE("SerializeDepthwiseConvolution2dWithPerAxisParams") |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 719 | { |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 720 | using namespace armnn; |
| 721 | |
| 722 | const std::string layerName("depwiseConvolution2dWithPerAxis"); |
| 723 | const TensorInfo inputInfo ({ 1, 3, 3, 2 }, DataType::QAsymmU8, 0.55f, 128); |
| 724 | const TensorInfo outputInfo({ 1, 2, 2, 4 }, DataType::QAsymmU8, 0.75f, 128); |
| 725 | |
| 726 | const std::vector<float> quantScales{ 0.75f, 0.80f, 0.90f, 0.95f }; |
| 727 | const unsigned int quantDimension = 0; |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 728 | TensorInfo kernelInfo({ 2, 2, 2, 2 }, DataType::QSymmS8, quantScales, quantDimension, true); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 729 | |
| 730 | const std::vector<float> biasQuantScales{ 0.25f, 0.35f, 0.45f, 0.55f }; |
| 731 | constexpr unsigned int biasQuantDimension = 0; |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 732 | TensorInfo biasInfo({ 4 }, DataType::Signed32, biasQuantScales, biasQuantDimension, true); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 733 | |
| 734 | std::vector<int8_t> kernelData = GenerateRandomData<int8_t>(kernelInfo.GetNumElements()); |
| 735 | armnn::ConstTensor weights(kernelInfo, kernelData); |
| 736 | std::vector<int32_t> biasData = GenerateRandomData<int32_t>(biasInfo.GetNumElements()); |
| 737 | armnn::ConstTensor biases(biasInfo, biasData); |
| 738 | |
| 739 | DepthwiseConvolution2dDescriptor descriptor; |
| 740 | descriptor.m_StrideX = 1; |
| 741 | descriptor.m_StrideY = 1; |
| 742 | descriptor.m_PadLeft = 0; |
| 743 | descriptor.m_PadRight = 0; |
| 744 | descriptor.m_PadTop = 0; |
| 745 | descriptor.m_PadBottom = 0; |
| 746 | descriptor.m_DilationX = 1; |
| 747 | descriptor.m_DilationY = 1; |
| 748 | descriptor.m_BiasEnabled = true; |
| 749 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 750 | |
| 751 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 752 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 753 | armnn::IConnectableLayer* const depthwiseConvLayer = network->AddDepthwiseConvolution2dLayer(descriptor, |
| 754 | layerName.c_str()); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 755 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 756 | |
| 757 | inputLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(0)); |
| 758 | depthwiseConvLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 759 | |
| 760 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 761 | depthwiseConvLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 762 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 763 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights); |
| 764 | weightsLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(1u)); |
| 765 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.GetInfo()); |
| 766 | |
| 767 | armnn::IConnectableLayer* const biasLayer = network->AddConstantLayer(biases); |
| 768 | biasLayer->GetOutputSlot(0).Connect(depthwiseConvLayer->GetInputSlot(2u)); |
| 769 | biasLayer->GetOutputSlot(0).SetTensorInfo(biases.GetInfo()); |
| 770 | |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 771 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 772 | CHECK(deserializedNetwork); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 773 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 774 | const std::vector<armnn::ConstTensor>& constants {weights, biases}; |
| 775 | LayerVerifierBaseWithDescriptorAndConstants<armnn::DepthwiseConvolution2dDescriptor> verifier( |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 776 | layerName, {inputInfo, kernelInfo, biasInfo}, {outputInfo}, descriptor, constants); |
| 777 | deserializedNetwork->ExecuteStrategy(verifier); |
| 778 | } |
| 779 | |
| 780 | TEST_CASE("SerializeDepthwiseConvolution2dWeightsAndBiasesAsConstantLayers") |
| 781 | { |
| 782 | const std::string layerName("depthwiseConvolution2d"); |
| 783 | const armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32); |
| 784 | const armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 785 | |
| 786 | const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 787 | const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 788 | |
| 789 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 790 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 791 | |
| 792 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 793 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 794 | |
| 795 | armnn::DepthwiseConvolution2dDescriptor descriptor; |
| 796 | descriptor.m_PadLeft = 1; |
| 797 | descriptor.m_PadRight = 1; |
| 798 | descriptor.m_PadTop = 1; |
| 799 | descriptor.m_PadBottom = 1; |
| 800 | descriptor.m_StrideX = 2; |
| 801 | descriptor.m_StrideY = 2; |
| 802 | descriptor.m_DilationX = 2; |
| 803 | descriptor.m_DilationY = 2; |
| 804 | descriptor.m_BiasEnabled = true; |
| 805 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 806 | |
| 807 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 808 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 809 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "Weights"); |
| 810 | armnn::IConnectableLayer* const biasesLayer = network->AddConstantLayer(biases, "Biases"); |
| 811 | armnn::IConnectableLayer* const convLayer = network->AddDepthwiseConvolution2dLayer(descriptor, |
| 812 | layerName.c_str()); |
| 813 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 814 | |
| 815 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
| 816 | weightsLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(1)); |
| 817 | biasesLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(2)); |
| 818 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 819 | |
| 820 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 821 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 822 | biasesLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
| 823 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 824 | |
| 825 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 826 | CHECK(deserializedNetwork); |
| 827 | |
| 828 | const std::vector<armnn::ConstTensor>& constants {weights, biases}; |
| 829 | LayerVerifierBaseWithDescriptorAndConstants<armnn::DepthwiseConvolution2dDescriptor> verifier( |
| 830 | layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor, constants); |
| 831 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 832 | deserializedNetwork->ExecuteStrategy(verifier); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 835 | TEST_CASE("SerializeDequantize") |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 836 | { |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 837 | const std::string layerName("dequantize"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 838 | const armnn::TensorInfo inputInfo({ 1, 5, 2, 3 }, armnn::DataType::QAsymmU8, 0.5f, 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 839 | const armnn::TensorInfo outputInfo({ 1, 5, 2, 3 }, armnn::DataType::Float32); |
| 840 | |
| 841 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 842 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 843 | armnn::IConnectableLayer* const dequantizeLayer = network->AddDequantizeLayer(layerName.c_str()); |
| 844 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 845 | |
| 846 | inputLayer->GetOutputSlot(0).Connect(dequantizeLayer->GetInputSlot(0)); |
| 847 | dequantizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 848 | |
| 849 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 850 | dequantizeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 851 | |
| 852 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 853 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 854 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 855 | LayerVerifierBase verifier(layerName, {inputInfo}, {outputInfo}); |
| 856 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 859 | TEST_CASE("SerializeDeserializeDetectionPostProcess") |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 860 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 861 | const std::string layerName("detectionPostProcess"); |
| 862 | |
| 863 | const std::vector<armnn::TensorInfo> inputInfos({ |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 864 | armnn::TensorInfo({ 1, 6, 4 }, armnn::DataType::Float32), |
| 865 | armnn::TensorInfo({ 1, 6, 3}, armnn::DataType::Float32) |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 866 | }); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 867 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 868 | const std::vector<armnn::TensorInfo> outputInfos({ |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 869 | armnn::TensorInfo({ 1, 3, 4 }, armnn::DataType::Float32), |
| 870 | armnn::TensorInfo({ 1, 3 }, armnn::DataType::Float32), |
| 871 | armnn::TensorInfo({ 1, 3 }, armnn::DataType::Float32), |
| 872 | armnn::TensorInfo({ 1 }, armnn::DataType::Float32) |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 873 | }); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 874 | |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 875 | armnn::DetectionPostProcessDescriptor descriptor; |
| 876 | descriptor.m_UseRegularNms = true; |
| 877 | descriptor.m_MaxDetections = 3; |
| 878 | descriptor.m_MaxClassesPerDetection = 1; |
| 879 | descriptor.m_DetectionsPerClass =1; |
| 880 | descriptor.m_NmsScoreThreshold = 0.0; |
| 881 | descriptor.m_NmsIouThreshold = 0.5; |
| 882 | descriptor.m_NumClasses = 2; |
| 883 | descriptor.m_ScaleY = 10.0; |
| 884 | descriptor.m_ScaleX = 10.0; |
| 885 | descriptor.m_ScaleH = 5.0; |
| 886 | descriptor.m_ScaleW = 5.0; |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 887 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 888 | const armnn::TensorInfo anchorsInfo({ 6, 4 }, armnn::DataType::Float32, 0.0f, 0, true); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 889 | const std::vector<float> anchorsData({ |
| 890 | 0.5f, 0.5f, 1.0f, 1.0f, |
| 891 | 0.5f, 0.5f, 1.0f, 1.0f, |
| 892 | 0.5f, 0.5f, 1.0f, 1.0f, |
| 893 | 0.5f, 10.5f, 1.0f, 1.0f, |
| 894 | 0.5f, 10.5f, 1.0f, 1.0f, |
| 895 | 0.5f, 100.5f, 1.0f, 1.0f |
| 896 | }); |
| 897 | armnn::ConstTensor anchors(anchorsInfo, anchorsData); |
| 898 | |
| 899 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 900 | armnn::IConnectableLayer* const detectionLayer = |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 901 | network->AddDetectionPostProcessLayer(descriptor, anchors, layerName.c_str()); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 902 | |
| 903 | for (unsigned int i = 0; i < 2; i++) |
| 904 | { |
| 905 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(static_cast<int>(i)); |
| 906 | inputLayer->GetOutputSlot(0).Connect(detectionLayer->GetInputSlot(i)); |
| 907 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfos[i]); |
| 908 | } |
| 909 | |
| 910 | for (unsigned int i = 0; i < 4; i++) |
| 911 | { |
| 912 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(static_cast<int>(i)); |
| 913 | detectionLayer->GetOutputSlot(i).Connect(outputLayer->GetInputSlot(0)); |
| 914 | detectionLayer->GetOutputSlot(i).SetTensorInfo(outputInfos[i]); |
| 915 | } |
| 916 | |
| 917 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 918 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 919 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 920 | const std::vector<armnn::ConstTensor>& constants {anchors}; |
| 921 | LayerVerifierBaseWithDescriptorAndConstants<armnn::DetectionPostProcessDescriptor> verifier( |
| 922 | layerName, inputInfos, outputInfos, descriptor, constants); |
| 923 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 924 | } |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 925 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 926 | TEST_CASE("SerializeDivision") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 927 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 928 | const std::string layerName("division"); |
| 929 | const armnn::TensorInfo info({ 1, 5, 2, 3 }, armnn::DataType::Float32); |
| 930 | |
| 931 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 932 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 933 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 934 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 935 | armnn::IConnectableLayer* const divisionLayer = network->AddDivisionLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 936 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 937 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 938 | |
| 939 | inputLayer0->GetOutputSlot(0).Connect(divisionLayer->GetInputSlot(0)); |
| 940 | inputLayer1->GetOutputSlot(0).Connect(divisionLayer->GetInputSlot(1)); |
| 941 | divisionLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 942 | |
| 943 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 944 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 945 | divisionLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 946 | |
| 947 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 948 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 949 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 950 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 951 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 954 | TEST_CASE("SerializeDeserializeComparisonEqual") |
Aron Virginas-Tar | 6d2e659 | 2019-10-22 11:44:47 +0100 | [diff] [blame] | 955 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 956 | const std::string layerName("EqualLayer"); |
| 957 | const armnn::TensorInfo inputTensorInfo1 = armnn::TensorInfo({2, 1, 2, 4}, armnn::DataType::Float32); |
| 958 | const armnn::TensorInfo inputTensorInfo2 = armnn::TensorInfo({2, 1, 2, 4}, armnn::DataType::Float32); |
| 959 | const armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({2, 1, 2, 4}, armnn::DataType::Boolean); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 960 | |
| 961 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 962 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(0); |
| 963 | armnn::IConnectableLayer* const inputLayer2 = network->AddInputLayer(1); |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 964 | armnn::ComparisonDescriptor equalDescriptor(armnn::ComparisonOperation::Equal); |
| 965 | armnn::IConnectableLayer* const equalLayer = network->AddComparisonLayer(equalDescriptor, layerName.c_str()); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 966 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 967 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 968 | inputLayer1->GetOutputSlot(0).Connect(equalLayer->GetInputSlot(0)); |
| 969 | inputLayer1->GetOutputSlot(0).SetTensorInfo(inputTensorInfo1); |
| 970 | inputLayer2->GetOutputSlot(0).Connect(equalLayer->GetInputSlot(1)); |
| 971 | inputLayer2->GetOutputSlot(0).SetTensorInfo(inputTensorInfo2); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 972 | equalLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 973 | equalLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 974 | |
| 975 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 976 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 977 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 978 | LayerVerifierBase verifier(layerName, {inputTensorInfo1, inputTensorInfo2}, {outputTensorInfo}); |
| 979 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | 6d2e659 | 2019-10-22 11:44:47 +0100 | [diff] [blame] | 980 | } |
| 981 | |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 982 | void SerializeElementwiseBinaryTest(armnn::BinaryOperation binaryOperation) |
| 983 | { |
| 984 | auto layerName = GetBinaryOperationAsCString(binaryOperation); |
| 985 | const armnn::TensorInfo tensorInfo({ 1, 5, 2, 3 }, armnn::DataType::Float32); |
| 986 | armnn::ElementwiseBinaryDescriptor descriptor(binaryOperation); |
| 987 | |
| 988 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 989 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 990 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
| 991 | armnn::IConnectableLayer* const elementwiseBinaryLayer = network->AddElementwiseBinaryLayer(descriptor, |
| 992 | layerName); |
| 993 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 994 | |
| 995 | inputLayer0->GetOutputSlot(0).Connect(elementwiseBinaryLayer->GetInputSlot(0)); |
| 996 | inputLayer1->GetOutputSlot(0).Connect(elementwiseBinaryLayer->GetInputSlot(1)); |
| 997 | elementwiseBinaryLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 998 | |
| 999 | inputLayer0->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 1000 | inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 1001 | elementwiseBinaryLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 1002 | |
| 1003 | std::string serializedNetwork = SerializeNetwork(*network); |
| 1004 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(serializedNetwork); |
| 1005 | CHECK(deserializedNetwork); |
| 1006 | |
| 1007 | LayerVerifierBaseWithDescriptor<armnn::ElementwiseBinaryDescriptor> |
| 1008 | verifier(layerName, { tensorInfo, tensorInfo }, { tensorInfo }, descriptor); |
| 1009 | deserializedNetwork->ExecuteStrategy(verifier); |
| 1010 | } |
| 1011 | |
| 1012 | TEST_CASE("SerializeElementwiseBinary") |
| 1013 | { |
| 1014 | using op = armnn::BinaryOperation; |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 1015 | std::initializer_list<op> allBinaryOperations = |
| 1016 | {op::Add, op::Div, op::Maximum, op::Minimum, op::Mul, op::Power, op::SqDiff, op::Sub}; |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 1017 | |
| 1018 | for (auto binaryOperation : allBinaryOperations) |
| 1019 | { |
| 1020 | SerializeElementwiseBinaryTest(binaryOperation); |
| 1021 | } |
| 1022 | } |
| 1023 | |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 1024 | void SerializeElementwiseUnaryTest(armnn::UnaryOperation unaryOperation) |
| 1025 | { |
| 1026 | auto layerName = GetUnaryOperationAsCString(unaryOperation); |
| 1027 | |
| 1028 | const armnn::TensorShape shape{2, 1, 2, 2}; |
| 1029 | |
| 1030 | const armnn::TensorInfo inputInfo = armnn::TensorInfo(shape, armnn::DataType::Float32); |
| 1031 | const armnn::TensorInfo outputInfo = armnn::TensorInfo(shape, armnn::DataType::Float32); |
| 1032 | |
| 1033 | armnn::ElementwiseUnaryDescriptor descriptor(unaryOperation); |
| 1034 | |
| 1035 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1036 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1037 | armnn::IConnectableLayer* const elementwiseUnaryLayer = |
| 1038 | network->AddElementwiseUnaryLayer(descriptor, layerName); |
| 1039 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1040 | |
| 1041 | inputLayer->GetOutputSlot(0).Connect(elementwiseUnaryLayer->GetInputSlot(0)); |
| 1042 | elementwiseUnaryLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1043 | |
| 1044 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1045 | elementwiseUnaryLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1046 | |
| 1047 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 1048 | |
| 1049 | CHECK(deserializedNetwork); |
| 1050 | |
| 1051 | LayerVerifierBaseWithDescriptor<armnn::ElementwiseUnaryDescriptor> |
| 1052 | verifier(layerName, { inputInfo }, { outputInfo }, descriptor); |
| 1053 | |
| 1054 | deserializedNetwork->ExecuteStrategy(verifier); |
| 1055 | } |
| 1056 | |
| 1057 | TEST_CASE("SerializeElementwiseUnary") |
| 1058 | { |
| 1059 | using op = armnn::UnaryOperation; |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 1060 | std::initializer_list<op> allUnaryOperations = {op::Abs, op::Ceil, op::Exp, op::Sqrt, op::Rsqrt, op::Neg, |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 1061 | op::LogicalNot, op::Log, op::Sin}; |
| 1062 | |
| 1063 | for (auto unaryOperation : allUnaryOperations) |
| 1064 | { |
| 1065 | SerializeElementwiseUnaryTest(unaryOperation); |
| 1066 | } |
| 1067 | } |
| 1068 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1069 | TEST_CASE("SerializeFill") |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1070 | { |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1071 | const std::string layerName("fill"); |
Teresa Charlin | 4b10fef | 2020-07-29 09:36:41 +0100 | [diff] [blame] | 1072 | const armnn::TensorInfo inputInfo({4}, armnn::DataType::Signed32); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1073 | const armnn::TensorInfo outputInfo({1, 3, 3, 1}, armnn::DataType::Float32); |
| 1074 | |
| 1075 | armnn::FillDescriptor descriptor(1.0f); |
| 1076 | |
| 1077 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1078 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1079 | armnn::IConnectableLayer* const fillLayer = network->AddFillLayer(descriptor, layerName.c_str()); |
| 1080 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1081 | |
| 1082 | inputLayer->GetOutputSlot(0).Connect(fillLayer->GetInputSlot(0)); |
| 1083 | fillLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1084 | |
| 1085 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1086 | fillLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1087 | |
| 1088 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1089 | CHECK(deserializedNetwork); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1090 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1091 | LayerVerifierBaseWithDescriptor<armnn::FillDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, descriptor); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1092 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1093 | deserializedNetwork->ExecuteStrategy(verifier); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1096 | TEST_CASE("SerializeFloor") |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1097 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1098 | const std::string layerName("floor"); |
| 1099 | const armnn::TensorInfo info({4,4}, armnn::DataType::Float32); |
| 1100 | |
| 1101 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1102 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1103 | armnn::IConnectableLayer* const floorLayer = network->AddFloorLayer(layerName.c_str()); |
| 1104 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1105 | |
| 1106 | inputLayer->GetOutputSlot(0).Connect(floorLayer->GetInputSlot(0)); |
| 1107 | floorLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1108 | |
| 1109 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1110 | floorLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1111 | |
| 1112 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1113 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1114 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1115 | LayerVerifierBase verifier(layerName, {info}, {info}); |
| 1116 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1119 | using FullyConnectedDescriptor = armnn::FullyConnectedDescriptor; |
| 1120 | class FullyConnectedLayerVerifier : public LayerVerifierBaseWithDescriptor<FullyConnectedDescriptor> |
| 1121 | { |
| 1122 | public: |
| 1123 | FullyConnectedLayerVerifier(const std::string& layerName, |
| 1124 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 1125 | const std::vector<armnn::TensorInfo>& outputInfos, |
| 1126 | const FullyConnectedDescriptor& descriptor) |
| 1127 | : LayerVerifierBaseWithDescriptor<FullyConnectedDescriptor>(layerName, inputInfos, outputInfos, descriptor) {} |
| 1128 | |
| 1129 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 1130 | const armnn::BaseDescriptor& descriptor, |
| 1131 | const std::vector<armnn::ConstTensor>& constants, |
| 1132 | const char* name, |
| 1133 | const armnn::LayerBindingId id = 0) override |
| 1134 | { |
| 1135 | armnn::IgnoreUnused(constants, id); |
| 1136 | switch (layer->GetType()) |
| 1137 | { |
| 1138 | case armnn::LayerType::Input: break; |
| 1139 | case armnn::LayerType::Output: break; |
| 1140 | case armnn::LayerType::Constant: break; |
| 1141 | default: |
| 1142 | { |
| 1143 | VerifyNameAndConnections(layer, name); |
| 1144 | const FullyConnectedDescriptor& layerDescriptor = |
| 1145 | static_cast<const FullyConnectedDescriptor&>(descriptor); |
| 1146 | CHECK(layerDescriptor.m_ConstantWeights == m_Descriptor.m_ConstantWeights); |
| 1147 | CHECK(layerDescriptor.m_BiasEnabled == m_Descriptor.m_BiasEnabled); |
| 1148 | CHECK(layerDescriptor.m_TransposeWeightMatrix == m_Descriptor.m_TransposeWeightMatrix); |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | }; |
| 1153 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1154 | TEST_CASE("SerializeFullyConnected") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1155 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1156 | const std::string layerName("fullyConnected"); |
| 1157 | const armnn::TensorInfo inputInfo ({ 2, 5, 1, 1 }, armnn::DataType::Float32); |
| 1158 | const armnn::TensorInfo outputInfo({ 2, 3 }, armnn::DataType::Float32); |
| 1159 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 1160 | const armnn::TensorInfo weightsInfo({ 5, 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 1161 | const armnn::TensorInfo biasesInfo ({ 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1162 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 1163 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 1164 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 1165 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 1166 | |
| 1167 | armnn::FullyConnectedDescriptor descriptor; |
| 1168 | descriptor.m_BiasEnabled = true; |
| 1169 | descriptor.m_TransposeWeightMatrix = false; |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 1170 | descriptor.m_ConstantWeights = true; |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1171 | |
| 1172 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1173 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Francis Murtagh | bb6c649 | 2022-02-09 15:13:38 +0000 | [diff] [blame] | 1174 | armnn::IConnectableLayer* const weightsInputLayer = network->AddInputLayer(1); |
| 1175 | armnn::IConnectableLayer* const biasInputLayer = network->AddInputLayer(2); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1176 | armnn::IConnectableLayer* const fullyConnectedLayer = |
Francis Murtagh | bb6c649 | 2022-02-09 15:13:38 +0000 | [diff] [blame] | 1177 | network->AddFullyConnectedLayer(descriptor, |
| 1178 | layerName.c_str()); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1179 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1180 | |
| 1181 | inputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0)); |
Francis Murtagh | bb6c649 | 2022-02-09 15:13:38 +0000 | [diff] [blame] | 1182 | weightsInputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1)); |
| 1183 | biasInputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(2)); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1184 | fullyConnectedLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1185 | |
| 1186 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
Francis Murtagh | bb6c649 | 2022-02-09 15:13:38 +0000 | [diff] [blame] | 1187 | weightsInputLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 1188 | biasInputLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1189 | fullyConnectedLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1190 | |
| 1191 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1192 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1193 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1194 | FullyConnectedLayerVerifier verifier(layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1195 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1198 | TEST_CASE("SerializeFullyConnectedWeightsAndBiasesAsInputs") |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 1199 | { |
| 1200 | const std::string layerName("fullyConnected_weights_as_inputs"); |
| 1201 | const armnn::TensorInfo inputInfo ({ 2, 5, 1, 1 }, armnn::DataType::Float32); |
| 1202 | const armnn::TensorInfo outputInfo({ 2, 3 }, armnn::DataType::Float32); |
| 1203 | |
| 1204 | const armnn::TensorInfo weightsInfo({ 5, 3 }, armnn::DataType::Float32); |
| 1205 | const armnn::TensorInfo biasesInfo ({ 3 }, armnn::DataType::Float32); |
| 1206 | |
| 1207 | armnn::Optional<armnn::ConstTensor> weights = armnn::EmptyOptional(); |
| 1208 | armnn::Optional<armnn::ConstTensor> bias = armnn::EmptyOptional(); |
| 1209 | |
| 1210 | armnn::FullyConnectedDescriptor descriptor; |
| 1211 | descriptor.m_BiasEnabled = true; |
| 1212 | descriptor.m_TransposeWeightMatrix = false; |
| 1213 | descriptor.m_ConstantWeights = false; |
| 1214 | |
| 1215 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1216 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1217 | armnn::IConnectableLayer* const weightsInputLayer = network->AddInputLayer(1); |
| 1218 | armnn::IConnectableLayer* const biasInputLayer = network->AddInputLayer(2); |
| 1219 | armnn::IConnectableLayer* const fullyConnectedLayer = |
| 1220 | network->AddFullyConnectedLayer(descriptor, |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 1221 | layerName.c_str()); |
| 1222 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1223 | |
| 1224 | inputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0)); |
| 1225 | weightsInputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1)); |
| 1226 | biasInputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(2)); |
| 1227 | fullyConnectedLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1228 | |
| 1229 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1230 | weightsInputLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 1231 | biasInputLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
| 1232 | fullyConnectedLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1233 | |
| 1234 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1235 | CHECK(deserializedNetwork); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 1236 | |
| 1237 | const std::vector<armnn::ConstTensor> constants {}; |
| 1238 | LayerVerifierBaseWithDescriptorAndConstants<armnn::FullyConnectedDescriptor> verifier( |
| 1239 | layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor, constants); |
| 1240 | deserializedNetwork->ExecuteStrategy(verifier); |
| 1241 | } |
| 1242 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1243 | TEST_CASE("SerializeFullyConnectedWeightsAndBiasesAsConstantLayers") |
| 1244 | { |
| 1245 | const std::string layerName("fullyConnected_weights_as_inputs"); |
| 1246 | const armnn::TensorInfo inputInfo ({ 2, 5, 1, 1 }, armnn::DataType::Float32); |
| 1247 | const armnn::TensorInfo outputInfo({ 2, 3 }, armnn::DataType::Float32); |
| 1248 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 1249 | const armnn::TensorInfo weightsInfo({ 5, 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 1250 | const armnn::TensorInfo biasesInfo ({ 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1251 | |
| 1252 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 1253 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 1254 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 1255 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 1256 | |
| 1257 | armnn::FullyConnectedDescriptor descriptor; |
| 1258 | descriptor.m_BiasEnabled = true; |
| 1259 | descriptor.m_TransposeWeightMatrix = false; |
| 1260 | descriptor.m_ConstantWeights = true; |
| 1261 | |
| 1262 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1263 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1264 | armnn::IConnectableLayer* const weightsLayer = network->AddConstantLayer(weights, "Weights"); |
| 1265 | armnn::IConnectableLayer* const biasesLayer = network->AddConstantLayer(biases, "Biases"); |
| 1266 | armnn::IConnectableLayer* const fullyConnectedLayer = network->AddFullyConnectedLayer(descriptor,layerName.c_str()); |
| 1267 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1268 | |
| 1269 | inputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0)); |
| 1270 | weightsLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1)); |
| 1271 | biasesLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(2)); |
| 1272 | fullyConnectedLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1273 | |
| 1274 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1275 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsInfo); |
| 1276 | biasesLayer->GetOutputSlot(0).SetTensorInfo(biasesInfo); |
| 1277 | fullyConnectedLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1278 | |
| 1279 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 1280 | CHECK(deserializedNetwork); |
| 1281 | |
| 1282 | FullyConnectedLayerVerifier verifier(layerName, {inputInfo, weightsInfo, biasesInfo}, {outputInfo}, descriptor); |
| 1283 | deserializedNetwork->ExecuteStrategy(verifier); |
| 1284 | } |
| 1285 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1286 | TEST_CASE("SerializeGather") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1287 | { |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1288 | using GatherDescriptor = armnn::GatherDescriptor; |
| 1289 | class GatherLayerVerifier : public LayerVerifierBaseWithDescriptor<GatherDescriptor> |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1290 | { |
| 1291 | public: |
| 1292 | GatherLayerVerifier(const std::string& layerName, |
| 1293 | const std::vector<armnn::TensorInfo>& inputInfos, |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1294 | const std::vector<armnn::TensorInfo>& outputInfos, |
| 1295 | const GatherDescriptor& descriptor) |
| 1296 | : LayerVerifierBaseWithDescriptor<GatherDescriptor>(layerName, inputInfos, outputInfos, descriptor) {} |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1297 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1298 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 1299 | const armnn::BaseDescriptor& descriptor, |
| 1300 | const std::vector<armnn::ConstTensor>& constants, |
| 1301 | const char* name, |
| 1302 | const armnn::LayerBindingId id = 0) override |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1303 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1304 | armnn::IgnoreUnused(constants, id); |
| 1305 | switch (layer->GetType()) |
| 1306 | { |
| 1307 | case armnn::LayerType::Input: break; |
| 1308 | case armnn::LayerType::Output: break; |
| 1309 | case armnn::LayerType::Constant: break; |
| 1310 | default: |
| 1311 | { |
| 1312 | VerifyNameAndConnections(layer, name); |
| 1313 | const GatherDescriptor& layerDescriptor = static_cast<const GatherDescriptor&>(descriptor); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1314 | CHECK(layerDescriptor.m_Axis == m_Descriptor.m_Axis); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1317 | } |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | |
| 1320 | const std::string layerName("gather"); |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1321 | armnn::TensorInfo paramsInfo({ 8 }, armnn::DataType::QAsymmU8); |
| 1322 | armnn::TensorInfo outputInfo({ 3 }, armnn::DataType::QAsymmU8); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 1323 | const armnn::TensorInfo indicesInfo({ 3 }, armnn::DataType::Signed32, 0.0f, 0, true); |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1324 | GatherDescriptor descriptor; |
| 1325 | descriptor.m_Axis = 1; |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1326 | |
| 1327 | paramsInfo.SetQuantizationScale(1.0f); |
| 1328 | paramsInfo.SetQuantizationOffset(0); |
| 1329 | outputInfo.SetQuantizationScale(1.0f); |
| 1330 | outputInfo.SetQuantizationOffset(0); |
| 1331 | |
| 1332 | const std::vector<int32_t>& indicesData = {7, 6, 5}; |
| 1333 | |
| 1334 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1335 | armnn::IConnectableLayer *const inputLayer = network->AddInputLayer(0); |
| 1336 | armnn::IConnectableLayer *const constantLayer = |
| 1337 | network->AddConstantLayer(armnn::ConstTensor(indicesInfo, indicesData)); |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1338 | armnn::IConnectableLayer *const gatherLayer = network->AddGatherLayer(descriptor, layerName.c_str()); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1339 | armnn::IConnectableLayer *const outputLayer = network->AddOutputLayer(0); |
| 1340 | |
| 1341 | inputLayer->GetOutputSlot(0).Connect(gatherLayer->GetInputSlot(0)); |
| 1342 | constantLayer->GetOutputSlot(0).Connect(gatherLayer->GetInputSlot(1)); |
| 1343 | gatherLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1344 | |
| 1345 | inputLayer->GetOutputSlot(0).SetTensorInfo(paramsInfo); |
| 1346 | constantLayer->GetOutputSlot(0).SetTensorInfo(indicesInfo); |
| 1347 | gatherLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1348 | |
| 1349 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1350 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1351 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1352 | GatherLayerVerifier verifier(layerName, {paramsInfo, indicesInfo}, {outputInfo}, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1353 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Teresa Charlin | 6966bfa | 2022-04-25 17:14:50 +0100 | [diff] [blame] | 1356 | TEST_CASE("SerializeGatherNd") |
| 1357 | { |
| 1358 | class GatherNdLayerVerifier : public LayerVerifierBase |
| 1359 | { |
| 1360 | public: |
| 1361 | GatherNdLayerVerifier(const std::string& layerName, |
| 1362 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 1363 | const std::vector<armnn::TensorInfo>& outputInfos) |
| 1364 | : LayerVerifierBase(layerName, inputInfos, outputInfos) {} |
| 1365 | |
| 1366 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 1367 | const armnn::BaseDescriptor&, |
Teresa Charlin | 6966bfa | 2022-04-25 17:14:50 +0100 | [diff] [blame] | 1368 | const std::vector<armnn::ConstTensor>& constants, |
| 1369 | const char* name, |
| 1370 | const armnn::LayerBindingId id = 0) override |
| 1371 | { |
| 1372 | armnn::IgnoreUnused(constants, id); |
| 1373 | switch (layer->GetType()) |
| 1374 | { |
| 1375 | case armnn::LayerType::Input: |
| 1376 | case armnn::LayerType::Output: |
| 1377 | case armnn::LayerType::Constant: |
| 1378 | break; |
| 1379 | default: |
| 1380 | { |
| 1381 | VerifyNameAndConnections(layer, name); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | }; |
| 1386 | |
| 1387 | const std::string layerName("gatherNd"); |
| 1388 | armnn::TensorInfo paramsInfo({ 6, 3 }, armnn::DataType::QAsymmU8); |
| 1389 | armnn::TensorInfo outputInfo({ 3, 3 }, armnn::DataType::QAsymmU8); |
| 1390 | const armnn::TensorInfo indicesInfo({ 3, 1 }, armnn::DataType::Signed32, 0.0f, 0, true); |
| 1391 | |
| 1392 | paramsInfo.SetQuantizationScale(1.0f); |
| 1393 | paramsInfo.SetQuantizationOffset(0); |
| 1394 | outputInfo.SetQuantizationScale(1.0f); |
| 1395 | outputInfo.SetQuantizationOffset(0); |
| 1396 | |
| 1397 | const std::vector<int32_t>& indicesData = {5, 1, 0}; |
| 1398 | |
| 1399 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1400 | armnn::IConnectableLayer *const inputLayer = network->AddInputLayer(0); |
| 1401 | armnn::IConnectableLayer *const constantLayer = |
| 1402 | network->AddConstantLayer(armnn::ConstTensor(indicesInfo, indicesData)); |
| 1403 | armnn::IConnectableLayer *const gatherNdLayer = network->AddGatherNdLayer(layerName.c_str()); |
| 1404 | armnn::IConnectableLayer *const outputLayer = network->AddOutputLayer(0); |
| 1405 | |
| 1406 | inputLayer->GetOutputSlot(0).Connect(gatherNdLayer->GetInputSlot(0)); |
| 1407 | constantLayer->GetOutputSlot(0).Connect(gatherNdLayer->GetInputSlot(1)); |
| 1408 | gatherNdLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1409 | |
| 1410 | inputLayer->GetOutputSlot(0).SetTensorInfo(paramsInfo); |
| 1411 | constantLayer->GetOutputSlot(0).SetTensorInfo(indicesInfo); |
| 1412 | gatherNdLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1413 | |
| 1414 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 1415 | CHECK(deserializedNetwork); |
| 1416 | |
| 1417 | GatherNdLayerVerifier verifier(layerName, {paramsInfo, indicesInfo}, {outputInfo}); |
| 1418 | deserializedNetwork->ExecuteStrategy(verifier); |
| 1419 | } |
Aron Virginas-Tar | 6d2e659 | 2019-10-22 11:44:47 +0100 | [diff] [blame] | 1420 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 1421 | TEST_CASE("SerializeComparisonGreater") |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 1422 | { |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1423 | const std::string layerName("greater"); |
| 1424 | |
| 1425 | const armnn::TensorShape shape{2, 1, 2, 4}; |
| 1426 | |
| 1427 | const armnn::TensorInfo inputInfo = armnn::TensorInfo(shape, armnn::DataType::Float32); |
| 1428 | const armnn::TensorInfo outputInfo = armnn::TensorInfo(shape, armnn::DataType::Boolean); |
| 1429 | |
| 1430 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1431 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1432 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 1433 | armnn::ComparisonDescriptor greaterDescriptor(armnn::ComparisonOperation::Greater); |
| 1434 | armnn::IConnectableLayer* const equalLayer = network->AddComparisonLayer(greaterDescriptor, layerName.c_str()); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1435 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1436 | |
| 1437 | inputLayer0->GetOutputSlot(0).Connect(equalLayer->GetInputSlot(0)); |
| 1438 | inputLayer1->GetOutputSlot(0).Connect(equalLayer->GetInputSlot(1)); |
| 1439 | equalLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1440 | |
| 1441 | inputLayer0->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1442 | inputLayer1->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1443 | equalLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1444 | |
| 1445 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1446 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1447 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1448 | LayerVerifierBase verifier(layerName, { inputInfo, inputInfo }, { outputInfo }); |
| 1449 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1450 | } |
| 1451 | |
Aron Virginas-Tar | 6d2e659 | 2019-10-22 11:44:47 +0100 | [diff] [blame] | 1452 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1453 | TEST_CASE("SerializeInstanceNormalization") |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1454 | { |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 1455 | const std::string layerName("instanceNormalization"); |
| 1456 | const armnn::TensorInfo info({ 1, 2, 1, 5 }, armnn::DataType::Float32); |
| 1457 | |
| 1458 | armnn::InstanceNormalizationDescriptor descriptor; |
| 1459 | descriptor.m_Gamma = 1.1f; |
| 1460 | descriptor.m_Beta = 0.1f; |
| 1461 | descriptor.m_Eps = 0.0001f; |
| 1462 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 1463 | |
| 1464 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1465 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1466 | armnn::IConnectableLayer* const instanceNormLayer = |
| 1467 | network->AddInstanceNormalizationLayer(descriptor, layerName.c_str()); |
| 1468 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1469 | |
| 1470 | inputLayer->GetOutputSlot(0).Connect(instanceNormLayer->GetInputSlot(0)); |
| 1471 | instanceNormLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1472 | |
| 1473 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1474 | instanceNormLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1475 | |
| 1476 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1477 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 1478 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1479 | LayerVerifierBaseWithDescriptor<armnn::InstanceNormalizationDescriptor> verifier( |
| 1480 | layerName, {info}, {info}, descriptor); |
| 1481 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1484 | TEST_CASE("SerializeL2Normalization") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1485 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1486 | const std::string l2NormLayerName("l2Normalization"); |
| 1487 | const armnn::TensorInfo info({1, 2, 1, 5}, armnn::DataType::Float32); |
| 1488 | |
| 1489 | armnn::L2NormalizationDescriptor desc; |
| 1490 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1491 | desc.m_Eps = 0.0001f; |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1492 | |
| 1493 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1494 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1495 | armnn::IConnectableLayer* const l2NormLayer = network->AddL2NormalizationLayer(desc, l2NormLayerName.c_str()); |
| 1496 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1497 | |
| 1498 | inputLayer0->GetOutputSlot(0).Connect(l2NormLayer->GetInputSlot(0)); |
| 1499 | l2NormLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1500 | |
| 1501 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 1502 | l2NormLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1503 | |
| 1504 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1505 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1506 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1507 | LayerVerifierBaseWithDescriptor<armnn::L2NormalizationDescriptor> verifier( |
| 1508 | l2NormLayerName, {info}, {info}, desc); |
| 1509 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1512 | TEST_CASE("EnsureL2NormalizationBackwardCompatibility") |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1513 | { |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1514 | // The hex data below is a flat buffer containing a simple network with one input |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1515 | // a L2Normalization layer and an output layer with dimensions as per the tensor infos below. |
| 1516 | // |
| 1517 | // This test verifies that we can still read back these old style |
| 1518 | // models without the normalization epsilon value. |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1519 | const std::vector<uint8_t> l2NormalizationModel = |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1520 | { |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1521 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x0A, 0x00, |
| 1522 | 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 1523 | 0x3C, 0x01, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1524 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xE8, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0B, |
| 1525 | 0x04, 0x00, 0x00, 0x00, 0xD6, 0xFE, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, |
| 1526 | 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9E, 0xFF, 0xFF, 0xFF, 0x02, 0x00, 0x00, 0x00, |
| 1527 | 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1528 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1529 | 0x4C, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
| 1530 | 0x00, 0x20, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 1531 | 0x20, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1532 | 0x0E, 0x00, 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0E, 0x00, 0x00, 0x00, |
| 1533 | 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x20, 0x00, |
| 1534 | 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x6C, 0x32, 0x4E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, |
| 1535 | 0x69, 0x6F, 0x6E, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, |
| 1536 | 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, |
| 1537 | 0x52, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 1538 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, |
| 1539 | 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1540 | 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, |
| 1541 | 0x04, 0x00, 0x00, 0x00, 0xF6, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0A, 0x00, |
| 1542 | 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x14, 0x00, 0x00, 0x00, |
| 1543 | 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 1544 | 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1545 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0A, 0x00, 0x00, 0x00, |
| 1546 | 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x08, 0x00, |
| 1547 | 0x07, 0x00, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1548 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 1549 | 0x05, 0x00, 0x00, 0x00, 0x00 |
| 1550 | }; |
| 1551 | |
| 1552 | armnn::INetworkPtr deserializedNetwork = |
| 1553 | DeserializeNetwork(std::string(l2NormalizationModel.begin(), l2NormalizationModel.end())); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1554 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1555 | |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1556 | const std::string layerName("l2Normalization"); |
Teresa Charlin | acb3ec5 | 2023-04-03 19:57:00 +0100 | [diff] [blame] | 1557 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 2, 1, 5}, armnn::DataType::Float32, 0.0f, 0); |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1558 | |
| 1559 | armnn::L2NormalizationDescriptor desc; |
| 1560 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1561 | // Since this variable does not exist in the l2NormalizationModel dump, the default value will be loaded |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1562 | desc.m_Eps = 1e-12f; |
| 1563 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1564 | LayerVerifierBaseWithDescriptor<armnn::L2NormalizationDescriptor> verifier( |
| 1565 | layerName, {inputInfo}, {inputInfo}, desc); |
| 1566 | deserializedNetwork->ExecuteStrategy(verifier); |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1569 | TEST_CASE("SerializeLogicalBinary") |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1570 | { |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1571 | const std::string layerName("logicalBinaryAnd"); |
| 1572 | |
| 1573 | const armnn::TensorShape shape{2, 1, 2, 2}; |
| 1574 | |
| 1575 | const armnn::TensorInfo inputInfo = armnn::TensorInfo(shape, armnn::DataType::Boolean); |
| 1576 | const armnn::TensorInfo outputInfo = armnn::TensorInfo(shape, armnn::DataType::Boolean); |
| 1577 | |
| 1578 | armnn::LogicalBinaryDescriptor descriptor(armnn::LogicalBinaryOperation::LogicalAnd); |
| 1579 | |
| 1580 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1581 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1582 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
| 1583 | armnn::IConnectableLayer* const logicalBinaryLayer = network->AddLogicalBinaryLayer(descriptor, layerName.c_str()); |
| 1584 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1585 | |
| 1586 | inputLayer0->GetOutputSlot(0).Connect(logicalBinaryLayer->GetInputSlot(0)); |
| 1587 | inputLayer1->GetOutputSlot(0).Connect(logicalBinaryLayer->GetInputSlot(1)); |
| 1588 | logicalBinaryLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1589 | |
| 1590 | inputLayer0->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1591 | inputLayer1->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1592 | logicalBinaryLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1593 | |
| 1594 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1595 | CHECK(deserializedNetwork); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1596 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1597 | LayerVerifierBaseWithDescriptor<armnn::LogicalBinaryDescriptor> verifier( |
| 1598 | layerName, { inputInfo, inputInfo }, { outputInfo }, descriptor); |
| 1599 | deserializedNetwork->ExecuteStrategy(verifier); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1602 | TEST_CASE("SerializeLogSoftmax") |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1603 | { |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1604 | const std::string layerName("log_softmax"); |
| 1605 | const armnn::TensorInfo info({1, 10}, armnn::DataType::Float32); |
| 1606 | |
| 1607 | armnn::LogSoftmaxDescriptor descriptor; |
| 1608 | descriptor.m_Beta = 1.0f; |
| 1609 | descriptor.m_Axis = -1; |
| 1610 | |
| 1611 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1612 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1613 | armnn::IConnectableLayer* const logSoftmaxLayer = network->AddLogSoftmaxLayer(descriptor, layerName.c_str()); |
| 1614 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1615 | |
| 1616 | inputLayer->GetOutputSlot(0).Connect(logSoftmaxLayer->GetInputSlot(0)); |
| 1617 | logSoftmaxLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1618 | |
| 1619 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1620 | logSoftmaxLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1621 | |
| 1622 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1623 | CHECK(deserializedNetwork); |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1624 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1625 | LayerVerifierBaseWithDescriptor<armnn::LogSoftmaxDescriptor> verifier(layerName, {info}, {info}, descriptor); |
| 1626 | deserializedNetwork->ExecuteStrategy(verifier); |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1629 | TEST_CASE("SerializeMaximum") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1630 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1631 | const std::string layerName("maximum"); |
| 1632 | const armnn::TensorInfo info({ 1, 2, 2, 3 }, armnn::DataType::Float32); |
| 1633 | |
| 1634 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1635 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1636 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1637 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1638 | armnn::IConnectableLayer* const maximumLayer = network->AddMaximumLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1639 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1640 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1641 | |
| 1642 | inputLayer0->GetOutputSlot(0).Connect(maximumLayer->GetInputSlot(0)); |
| 1643 | inputLayer1->GetOutputSlot(0).Connect(maximumLayer->GetInputSlot(1)); |
| 1644 | maximumLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1645 | |
| 1646 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 1647 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 1648 | maximumLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1649 | |
| 1650 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1651 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1652 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1653 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 1654 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1657 | TEST_CASE("SerializeMean") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1658 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1659 | const std::string layerName("mean"); |
| 1660 | const armnn::TensorInfo inputInfo({1, 1, 3, 2}, armnn::DataType::Float32); |
| 1661 | const armnn::TensorInfo outputInfo({1, 1, 1, 2}, armnn::DataType::Float32); |
| 1662 | |
| 1663 | armnn::MeanDescriptor descriptor; |
| 1664 | descriptor.m_Axis = { 2 }; |
| 1665 | descriptor.m_KeepDims = true; |
| 1666 | |
| 1667 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1668 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1669 | armnn::IConnectableLayer* const meanLayer = network->AddMeanLayer(descriptor, layerName.c_str()); |
| 1670 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1671 | |
| 1672 | inputLayer->GetOutputSlot(0).Connect(meanLayer->GetInputSlot(0)); |
| 1673 | meanLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1674 | |
| 1675 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1676 | meanLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1677 | |
| 1678 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1679 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1680 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1681 | LayerVerifierBaseWithDescriptor<armnn::MeanDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, descriptor); |
| 1682 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1685 | TEST_CASE("SerializeMerge") |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1686 | { |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1687 | const std::string layerName("merge"); |
| 1688 | const armnn::TensorInfo info({ 1, 2, 2, 3 }, armnn::DataType::Float32); |
| 1689 | |
| 1690 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1691 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1692 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
| 1693 | armnn::IConnectableLayer* const mergeLayer = network->AddMergeLayer(layerName.c_str()); |
| 1694 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1695 | |
| 1696 | inputLayer0->GetOutputSlot(0).Connect(mergeLayer->GetInputSlot(0)); |
| 1697 | inputLayer1->GetOutputSlot(0).Connect(mergeLayer->GetInputSlot(1)); |
| 1698 | mergeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1699 | |
| 1700 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 1701 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 1702 | mergeLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1703 | |
| 1704 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1705 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1706 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1707 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 1708 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1711 | class MergerLayerVerifier : public LayerVerifierBaseWithDescriptor<armnn::OriginsDescriptor> |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1712 | { |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1713 | public: |
| 1714 | MergerLayerVerifier(const std::string& layerName, |
| 1715 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 1716 | const std::vector<armnn::TensorInfo>& outputInfos, |
| 1717 | const armnn::OriginsDescriptor& descriptor) |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 1718 | : LayerVerifierBaseWithDescriptor<armnn::OriginsDescriptor>(layerName, inputInfos, outputInfos, descriptor) {} |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1719 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1720 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 1721 | const armnn::BaseDescriptor& descriptor, |
| 1722 | const std::vector<armnn::ConstTensor>& constants, |
| 1723 | const char* name, |
| 1724 | const armnn::LayerBindingId id = 0) override |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1725 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1726 | armnn::IgnoreUnused(descriptor, constants, id); |
| 1727 | switch (layer->GetType()) |
| 1728 | { |
| 1729 | case armnn::LayerType::Input: break; |
| 1730 | case armnn::LayerType::Output: break; |
| 1731 | case armnn::LayerType::Merge: |
| 1732 | { |
| 1733 | throw armnn::Exception("MergerLayer should have translated to ConcatLayer"); |
| 1734 | break; |
| 1735 | } |
| 1736 | case armnn::LayerType::Concat: |
| 1737 | { |
| 1738 | VerifyNameAndConnections(layer, name); |
| 1739 | const armnn::MergerDescriptor& layerDescriptor = |
| 1740 | static_cast<const armnn::MergerDescriptor&>(descriptor); |
| 1741 | VerifyDescriptor(layerDescriptor); |
| 1742 | break; |
| 1743 | } |
| 1744 | default: |
| 1745 | { |
| 1746 | throw armnn::Exception("Unexpected layer type in Merge test model"); |
| 1747 | } |
| 1748 | } |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1749 | } |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1750 | }; |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1751 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1752 | TEST_CASE("EnsureMergerLayerBackwardCompatibility") |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1753 | { |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1754 | // The hex data below is a flat buffer containing a simple network with two inputs |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1755 | // a merger layer (now deprecated) and an output layer with dimensions as per the tensor infos below. |
| 1756 | // |
| 1757 | // This test verifies that we can still read back these old style |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1758 | // models replacing the MergerLayers with ConcatLayers with the same parameters. |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1759 | const std::vector<uint8_t> mergerModel = |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1760 | { |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1761 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x0A, 0x00, |
| 1762 | 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, |
| 1763 | 0x38, 0x02, 0x00, 0x00, 0x8C, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 1764 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 1765 | 0xF4, 0xFD, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x92, 0xFE, 0xFF, 0xFF, 0x04, 0x00, |
| 1766 | 0x00, 0x00, 0x9A, 0xFE, 0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x7E, 0xFE, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, |
| 1767 | 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1768 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1769 | 0xF8, 0xFE, 0xFF, 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xFE, 0xFF, 0xFF, 0x00, 0x00, |
| 1770 | 0x00, 0x1F, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 1771 | 0x68, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, |
| 1772 | 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, |
| 1773 | 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x22, 0xFF, 0xFF, 0xFF, 0x04, 0x00, |
| 1774 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1775 | 0x00, 0x00, 0x00, 0x00, 0x3E, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1776 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0xFF, 0xFF, 0xFF, |
| 1777 | 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 1778 | 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6D, 0x65, 0x72, 0x67, 0x65, 0x72, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 1779 | 0x5C, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0xFF, |
| 1780 | 0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x92, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, |
| 1781 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 1782 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 1783 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, |
| 1784 | 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0E, 0x00, |
| 1785 | 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1786 | 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0E, 0x00, |
| 1787 | 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1788 | 0x0E, 0x00, 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0E, 0x00, 0x00, 0x00, |
| 1789 | 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, |
| 1790 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 1791 | 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 1792 | 0x00, 0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1793 | 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 1794 | 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, |
| 1795 | 0x04, 0x00, 0x00, 0x00, 0xF6, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0A, 0x00, |
| 1796 | 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x14, 0x00, 0x00, 0x00, |
| 1797 | 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 1798 | 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1799 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0A, 0x00, 0x00, 0x00, |
| 1800 | 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x08, 0x00, |
| 1801 | 0x07, 0x00, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1802 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 1803 | 0x02, 0x00, 0x00, 0x00 |
| 1804 | }; |
| 1805 | |
| 1806 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(std::string(mergerModel.begin(), mergerModel.end())); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1807 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1808 | |
Teresa Charlin | acb3ec5 | 2023-04-03 19:57:00 +0100 | [diff] [blame] | 1809 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({ 2, 3, 2, 2 }, armnn::DataType::Float32, 0.0f, 0); |
| 1810 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({ 4, 3, 2, 2 }, armnn::DataType::Float32, 0.0f, 0); |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1811 | |
| 1812 | const std::vector<armnn::TensorShape> shapes({inputInfo.GetShape(), inputInfo.GetShape()}); |
| 1813 | |
| 1814 | armnn::OriginsDescriptor descriptor = |
Jim Flynn | 825af45 | 2019-05-20 12:49:28 +0100 | [diff] [blame] | 1815 | armnn::CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), 0); |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1816 | |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 1817 | MergerLayerVerifier verifier("merger", { inputInfo, inputInfo }, { outputInfo }, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1818 | deserializedNetwork->ExecuteStrategy(verifier); |
Jim Flynn | 5fa8393 | 2019-05-09 15:35:43 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1821 | TEST_CASE("SerializeConcat") |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1822 | { |
| 1823 | const std::string layerName("concat"); |
| 1824 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({2, 3, 2, 2}, armnn::DataType::Float32); |
| 1825 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({4, 3, 2, 2}, armnn::DataType::Float32); |
| 1826 | |
| 1827 | const std::vector<armnn::TensorShape> shapes({inputInfo.GetShape(), inputInfo.GetShape()}); |
| 1828 | |
| 1829 | armnn::OriginsDescriptor descriptor = |
| 1830 | armnn::CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), 0); |
| 1831 | |
| 1832 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1833 | armnn::IConnectableLayer* const inputLayerOne = network->AddInputLayer(0); |
| 1834 | armnn::IConnectableLayer* const inputLayerTwo = network->AddInputLayer(1); |
| 1835 | armnn::IConnectableLayer* const concatLayer = network->AddConcatLayer(descriptor, layerName.c_str()); |
| 1836 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1837 | |
| 1838 | inputLayerOne->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(0)); |
| 1839 | inputLayerTwo->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(1)); |
| 1840 | concatLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1841 | |
| 1842 | inputLayerOne->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1843 | inputLayerTwo->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 1844 | concatLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1845 | |
| 1846 | std::string concatLayerNetwork = SerializeNetwork(*network); |
| 1847 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(concatLayerNetwork); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1848 | CHECK(deserializedNetwork); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1849 | |
| 1850 | // NOTE: using the MergerLayerVerifier to ensure that it is a concat layer and not a |
| 1851 | // merger layer that gets placed into the graph. |
| 1852 | MergerLayerVerifier verifier(layerName, {inputInfo, inputInfo}, {outputInfo}, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1853 | deserializedNetwork->ExecuteStrategy(verifier); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1854 | } |
| 1855 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1856 | TEST_CASE("SerializeMinimum") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1857 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1858 | const std::string layerName("minimum"); |
| 1859 | const armnn::TensorInfo info({ 1, 2, 2, 3 }, armnn::DataType::Float32); |
| 1860 | |
| 1861 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1862 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1863 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1864 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1865 | armnn::IConnectableLayer* const minimumLayer = network->AddMinimumLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1866 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1867 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1868 | |
| 1869 | inputLayer0->GetOutputSlot(0).Connect(minimumLayer->GetInputSlot(0)); |
| 1870 | inputLayer1->GetOutputSlot(0).Connect(minimumLayer->GetInputSlot(1)); |
| 1871 | minimumLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1872 | |
| 1873 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 1874 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 1875 | minimumLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1876 | |
| 1877 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1878 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1879 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1880 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 1881 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1884 | TEST_CASE("SerializeMultiplication") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1885 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1886 | const std::string layerName("multiplication"); |
| 1887 | const armnn::TensorInfo info({ 1, 5, 2, 3 }, armnn::DataType::Float32); |
| 1888 | |
| 1889 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1890 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 1891 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1892 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1893 | armnn::IConnectableLayer* const multiplicationLayer = network->AddMultiplicationLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 1894 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1895 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1896 | |
| 1897 | inputLayer0->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(0)); |
| 1898 | inputLayer1->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(1)); |
| 1899 | multiplicationLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1900 | |
| 1901 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 1902 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 1903 | multiplicationLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1904 | |
| 1905 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1906 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1907 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1908 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 1909 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1912 | TEST_CASE("SerializePrelu") |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 1913 | { |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 1914 | const std::string layerName("prelu"); |
| 1915 | |
| 1916 | armnn::TensorInfo inputTensorInfo ({ 4, 1, 2 }, armnn::DataType::Float32); |
| 1917 | armnn::TensorInfo alphaTensorInfo ({ 5, 4, 3, 1 }, armnn::DataType::Float32); |
| 1918 | armnn::TensorInfo outputTensorInfo({ 5, 4, 3, 2 }, armnn::DataType::Float32); |
| 1919 | |
| 1920 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1921 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1922 | armnn::IConnectableLayer* const alphaLayer = network->AddInputLayer(1); |
| 1923 | armnn::IConnectableLayer* const preluLayer = network->AddPreluLayer(layerName.c_str()); |
| 1924 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1925 | |
| 1926 | inputLayer->GetOutputSlot(0).Connect(preluLayer->GetInputSlot(0)); |
| 1927 | alphaLayer->GetOutputSlot(0).Connect(preluLayer->GetInputSlot(1)); |
| 1928 | preluLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1929 | |
| 1930 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 1931 | alphaLayer->GetOutputSlot(0).SetTensorInfo(alphaTensorInfo); |
| 1932 | preluLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1933 | |
| 1934 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1935 | CHECK(deserializedNetwork); |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 1936 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1937 | LayerVerifierBase verifier(layerName, {inputTensorInfo, alphaTensorInfo}, {outputTensorInfo}); |
| 1938 | deserializedNetwork->ExecuteStrategy(verifier); |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 1939 | } |
| 1940 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1941 | TEST_CASE("SerializeNormalization") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1942 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1943 | const std::string layerName("normalization"); |
| 1944 | const armnn::TensorInfo info({2, 1, 2, 2}, armnn::DataType::Float32); |
| 1945 | |
| 1946 | armnn::NormalizationDescriptor desc; |
| 1947 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 1948 | desc.m_NormSize = 3; |
| 1949 | desc.m_Alpha = 1; |
| 1950 | desc.m_Beta = 1; |
| 1951 | desc.m_K = 1; |
| 1952 | |
| 1953 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1954 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1955 | armnn::IConnectableLayer* const normalizationLayer = network->AddNormalizationLayer(desc, layerName.c_str()); |
| 1956 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1957 | |
| 1958 | inputLayer->GetOutputSlot(0).Connect(normalizationLayer->GetInputSlot(0)); |
| 1959 | normalizationLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1960 | |
| 1961 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1962 | normalizationLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 1963 | |
| 1964 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1965 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1966 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1967 | LayerVerifierBaseWithDescriptor<armnn::NormalizationDescriptor> verifier(layerName, {info}, {info}, desc); |
| 1968 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1971 | TEST_CASE("SerializePad") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1972 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1973 | const std::string layerName("pad"); |
| 1974 | const armnn::TensorInfo inputTensorInfo = armnn::TensorInfo({1, 2, 3, 4}, armnn::DataType::Float32); |
| 1975 | const armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 5, 7}, armnn::DataType::Float32); |
| 1976 | |
| 1977 | armnn::PadDescriptor desc({{0, 0}, {1, 0}, {1, 1}, {1, 2}}); |
| 1978 | |
| 1979 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 1980 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 1981 | armnn::IConnectableLayer* const padLayer = network->AddPadLayer(desc, layerName.c_str()); |
| 1982 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 1983 | |
| 1984 | inputLayer->GetOutputSlot(0).Connect(padLayer->GetInputSlot(0)); |
| 1985 | padLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 1986 | |
| 1987 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 1988 | padLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1989 | |
| 1990 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1991 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1992 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 1993 | LayerVerifierBaseWithDescriptor<armnn::PadDescriptor> verifier(layerName, |
| 1994 | {inputTensorInfo}, |
| 1995 | {outputTensorInfo}, |
| 1996 | desc); |
| 1997 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Matthew Sloyan | 2e5d0b2 | 2021-10-21 14:05:31 +0100 | [diff] [blame] | 2000 | TEST_CASE("SerializePadReflect") |
| 2001 | { |
| 2002 | const std::string layerName("padReflect"); |
| 2003 | const armnn::TensorInfo inputTensorInfo = armnn::TensorInfo({1, 2, 3, 4}, armnn::DataType::Float32); |
| 2004 | const armnn::TensorInfo outputTensorInfo = armnn::TensorInfo({1, 3, 5, 7}, armnn::DataType::Float32); |
| 2005 | |
| 2006 | armnn::PadDescriptor desc({{0, 0}, {1, 0}, {1, 1}, {1, 2}}); |
| 2007 | desc.m_PaddingMode = armnn::PaddingMode::Reflect; |
| 2008 | |
| 2009 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2010 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2011 | armnn::IConnectableLayer* const padLayer = network->AddPadLayer(desc, layerName.c_str()); |
| 2012 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2013 | |
| 2014 | inputLayer->GetOutputSlot(0).Connect(padLayer->GetInputSlot(0)); |
| 2015 | padLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2016 | |
| 2017 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 2018 | padLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2019 | |
| 2020 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 2021 | CHECK(deserializedNetwork); |
| 2022 | |
| 2023 | LayerVerifierBaseWithDescriptor<armnn::PadDescriptor> verifier(layerName, |
| 2024 | {inputTensorInfo}, |
| 2025 | {outputTensorInfo}, |
| 2026 | desc); |
| 2027 | deserializedNetwork->ExecuteStrategy(verifier); |
| 2028 | } |
| 2029 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2030 | TEST_CASE("EnsurePadBackwardCompatibility") |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2031 | { |
| 2032 | // The PadDescriptor is being extended with a float PadValue (so a value other than 0 |
| 2033 | // can be used to pad the tensor. |
| 2034 | // |
| 2035 | // This test contains a binary representation of a simple input->pad->output network |
| 2036 | // prior to this change to test that the descriptor has been updated in a backward |
| 2037 | // compatible way with respect to Deserialization of older binary dumps |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 2038 | const std::vector<uint8_t> padModel = |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2039 | { |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 2040 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x0A, 0x00, |
| 2041 | 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 2042 | 0x54, 0x01, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2043 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xD0, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0B, |
| 2044 | 0x04, 0x00, 0x00, 0x00, 0x96, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x9E, 0xFF, 0xFF, 0xFF, 0x04, 0x00, |
| 2045 | 0x00, 0x00, 0x72, 0xFF, 0xFF, 0xFF, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 2046 | 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 2047 | 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, |
| 2048 | 0x00, 0x00, 0x00, 0x00, 0x24, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x16, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, |
| 2049 | 0x0E, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, |
| 2050 | 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, |
| 2051 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2052 | 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2053 | 0x0E, 0x00, 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0E, 0x00, 0x00, 0x00, |
| 2054 | 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, |
| 2055 | 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, |
| 2056 | 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, |
| 2057 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x52, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, |
| 2058 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, |
| 2059 | 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 2060 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, |
| 2061 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0xF6, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, |
| 2062 | 0x00, 0x00, 0x06, 0x00, 0x0A, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2063 | 0x0E, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x00, |
| 2064 | 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2065 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, |
| 2066 | 0x08, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2067 | 0x0A, 0x00, 0x10, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 2068 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 2069 | 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 |
| 2070 | }; |
| 2071 | |
| 2072 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(std::string(padModel.begin(), padModel.end())); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2073 | CHECK(deserializedNetwork); |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2074 | |
Teresa Charlin | acb3ec5 | 2023-04-03 19:57:00 +0100 | [diff] [blame] | 2075 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({ 1, 2, 3, 4 }, armnn::DataType::Float32, 0.0f, 0); |
| 2076 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({ 1, 3, 5, 7 }, armnn::DataType::Float32, 0.0f, 0); |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2077 | |
Aron Virginas-Tar | 6e0d962 | 2019-10-22 16:24:48 +0100 | [diff] [blame] | 2078 | armnn::PadDescriptor descriptor({{ 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 }}); |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2079 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2080 | LayerVerifierBaseWithDescriptor<armnn::PadDescriptor> verifier("pad", { inputInfo }, { outputInfo }, descriptor); |
| 2081 | deserializedNetwork->ExecuteStrategy(verifier); |
Jim Flynn | 965c7c6 | 2019-06-24 14:32:41 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2084 | TEST_CASE("SerializePermute") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2085 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2086 | const std::string layerName("permute"); |
| 2087 | const armnn::TensorInfo inputTensorInfo({4, 3, 2, 1}, armnn::DataType::Float32); |
| 2088 | const armnn::TensorInfo outputTensorInfo({1, 2, 3, 4}, armnn::DataType::Float32); |
| 2089 | |
| 2090 | armnn::PermuteDescriptor descriptor(armnn::PermutationVector({3, 2, 1, 0})); |
| 2091 | |
| 2092 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2093 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2094 | armnn::IConnectableLayer* const permuteLayer = network->AddPermuteLayer(descriptor, layerName.c_str()); |
| 2095 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2096 | |
| 2097 | inputLayer->GetOutputSlot(0).Connect(permuteLayer->GetInputSlot(0)); |
| 2098 | permuteLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2099 | |
| 2100 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 2101 | permuteLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2102 | |
| 2103 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2104 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2105 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2106 | LayerVerifierBaseWithDescriptor<armnn::PermuteDescriptor> verifier( |
| 2107 | layerName, {inputTensorInfo}, {outputTensorInfo}, descriptor); |
| 2108 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2111 | TEST_CASE("SerializePooling2d") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2112 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2113 | const std::string layerName("pooling2d"); |
| 2114 | const armnn::TensorInfo inputInfo({1, 2, 2, 1}, armnn::DataType::Float32); |
| 2115 | const armnn::TensorInfo outputInfo({1, 1, 1, 1}, armnn::DataType::Float32); |
| 2116 | |
| 2117 | armnn::Pooling2dDescriptor desc; |
| 2118 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 2119 | desc.m_PadTop = 0; |
| 2120 | desc.m_PadBottom = 0; |
| 2121 | desc.m_PadLeft = 0; |
| 2122 | desc.m_PadRight = 0; |
| 2123 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 2124 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Floor; |
| 2125 | desc.m_PaddingMethod = armnn::PaddingMethod::Exclude; |
| 2126 | desc.m_PoolHeight = 2; |
| 2127 | desc.m_PoolWidth = 2; |
| 2128 | desc.m_StrideX = 2; |
| 2129 | desc.m_StrideY = 2; |
| 2130 | |
| 2131 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2132 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2133 | armnn::IConnectableLayer* const pooling2dLayer = network->AddPooling2dLayer(desc, layerName.c_str()); |
| 2134 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2135 | |
| 2136 | inputLayer->GetOutputSlot(0).Connect(pooling2dLayer->GetInputSlot(0)); |
| 2137 | pooling2dLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2138 | |
| 2139 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2140 | pooling2dLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2141 | |
| 2142 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2143 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2144 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2145 | LayerVerifierBaseWithDescriptor<armnn::Pooling2dDescriptor> verifier( |
| 2146 | layerName, {inputInfo}, {outputInfo}, desc); |
| 2147 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2150 | TEST_CASE("SerializePooling3d") |
| 2151 | { |
| 2152 | const std::string layerName("pooling3d"); |
| 2153 | const armnn::TensorInfo inputInfo({1, 1, 2, 2, 2}, armnn::DataType::Float32); |
| 2154 | const armnn::TensorInfo outputInfo({1, 1, 1, 1, 1}, armnn::DataType::Float32); |
| 2155 | |
| 2156 | armnn::Pooling3dDescriptor desc; |
| 2157 | desc.m_DataLayout = armnn::DataLayout::NDHWC; |
| 2158 | desc.m_PadFront = 0; |
| 2159 | desc.m_PadBack = 0; |
| 2160 | desc.m_PadTop = 0; |
| 2161 | desc.m_PadBottom = 0; |
| 2162 | desc.m_PadLeft = 0; |
| 2163 | desc.m_PadRight = 0; |
| 2164 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 2165 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Floor; |
| 2166 | desc.m_PaddingMethod = armnn::PaddingMethod::Exclude; |
| 2167 | desc.m_PoolHeight = 2; |
| 2168 | desc.m_PoolWidth = 2; |
| 2169 | desc.m_PoolDepth = 2; |
| 2170 | desc.m_StrideX = 2; |
| 2171 | desc.m_StrideY = 2; |
| 2172 | desc.m_StrideZ = 2; |
| 2173 | |
| 2174 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2175 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2176 | armnn::IConnectableLayer* const pooling3dLayer = network->AddPooling3dLayer(desc, layerName.c_str()); |
| 2177 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2178 | |
| 2179 | inputLayer->GetOutputSlot(0).Connect(pooling3dLayer->GetInputSlot(0)); |
| 2180 | pooling3dLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2181 | |
| 2182 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2183 | pooling3dLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2184 | |
| 2185 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 2186 | CHECK(deserializedNetwork); |
| 2187 | |
| 2188 | LayerVerifierBaseWithDescriptor<armnn::Pooling3dDescriptor> verifier( |
| 2189 | layerName, {inputInfo}, {outputInfo}, desc); |
| 2190 | deserializedNetwork->ExecuteStrategy(verifier); |
| 2191 | } |
| 2192 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2193 | TEST_CASE("SerializeQuantize") |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 2194 | { |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 2195 | const std::string layerName("quantize"); |
| 2196 | const armnn::TensorInfo info({ 1, 2, 2, 3 }, armnn::DataType::Float32); |
| 2197 | |
| 2198 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2199 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2200 | armnn::IConnectableLayer* const quantizeLayer = network->AddQuantizeLayer(layerName.c_str()); |
| 2201 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2202 | |
| 2203 | inputLayer->GetOutputSlot(0).Connect(quantizeLayer->GetInputSlot(0)); |
| 2204 | quantizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2205 | |
| 2206 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2207 | quantizeLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2208 | |
| 2209 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2210 | CHECK(deserializedNetwork); |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 2211 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2212 | LayerVerifierBase verifier(layerName, {info}, {info}); |
| 2213 | deserializedNetwork->ExecuteStrategy(verifier); |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 2214 | } |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 2215 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2216 | TEST_CASE("SerializeRank") |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2217 | { |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2218 | const std::string layerName("rank"); |
| 2219 | const armnn::TensorInfo inputInfo({1, 9}, armnn::DataType::Float32); |
| 2220 | const armnn::TensorInfo outputInfo({1}, armnn::DataType::Signed32); |
| 2221 | |
| 2222 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2223 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2224 | armnn::IConnectableLayer* const rankLayer = network->AddRankLayer(layerName.c_str()); |
| 2225 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2226 | |
| 2227 | inputLayer->GetOutputSlot(0).Connect(rankLayer->GetInputSlot(0)); |
| 2228 | rankLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2229 | |
| 2230 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2231 | rankLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2232 | |
| 2233 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2234 | CHECK(deserializedNetwork); |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2235 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2236 | LayerVerifierBase verifier(layerName, {inputInfo}, {outputInfo}); |
| 2237 | deserializedNetwork->ExecuteStrategy(verifier); |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2238 | } |
| 2239 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2240 | TEST_CASE("SerializeReduceSum") |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2241 | { |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2242 | const std::string layerName("Reduce_Sum"); |
| 2243 | const armnn::TensorInfo inputInfo({1, 1, 3, 2}, armnn::DataType::Float32); |
| 2244 | const armnn::TensorInfo outputInfo({1, 1, 1, 2}, armnn::DataType::Float32); |
| 2245 | |
| 2246 | armnn::ReduceDescriptor descriptor; |
| 2247 | descriptor.m_vAxis = { 2 }; |
| 2248 | descriptor.m_ReduceOperation = armnn::ReduceOperation::Sum; |
| 2249 | |
| 2250 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2251 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2252 | armnn::IConnectableLayer* const reduceSumLayer = network->AddReduceLayer(descriptor, layerName.c_str()); |
| 2253 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2254 | |
| 2255 | inputLayer->GetOutputSlot(0).Connect(reduceSumLayer->GetInputSlot(0)); |
| 2256 | reduceSumLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2257 | |
| 2258 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2259 | reduceSumLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2260 | |
| 2261 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2262 | CHECK(deserializedNetwork); |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2263 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2264 | LayerVerifierBaseWithDescriptor<armnn::ReduceDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, descriptor); |
| 2265 | deserializedNetwork->ExecuteStrategy(verifier); |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2268 | TEST_CASE("SerializeReshape") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2269 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2270 | const std::string layerName("reshape"); |
| 2271 | const armnn::TensorInfo inputInfo({1, 9}, armnn::DataType::Float32); |
| 2272 | const armnn::TensorInfo outputInfo({3, 3}, armnn::DataType::Float32); |
| 2273 | |
| 2274 | armnn::ReshapeDescriptor descriptor({3, 3}); |
| 2275 | |
| 2276 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2277 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2278 | armnn::IConnectableLayer* const reshapeLayer = network->AddReshapeLayer(descriptor, layerName.c_str()); |
| 2279 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2280 | |
| 2281 | inputLayer->GetOutputSlot(0).Connect(reshapeLayer->GetInputSlot(0)); |
| 2282 | reshapeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2283 | |
| 2284 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2285 | reshapeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2286 | |
| 2287 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2288 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2289 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2290 | LayerVerifierBaseWithDescriptor<armnn::ReshapeDescriptor> verifier( |
| 2291 | layerName, {inputInfo}, {outputInfo}, descriptor); |
| 2292 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2295 | TEST_CASE("SerializeResize") |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2296 | { |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2297 | const std::string layerName("resize"); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2298 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2299 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32); |
| 2300 | |
| 2301 | armnn::ResizeDescriptor desc; |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 2302 | desc.m_TargetWidth = 4; |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2303 | desc.m_TargetHeight = 2; |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 2304 | desc.m_Method = armnn::ResizeMethod::NearestNeighbor; |
David Monahan | 4a0c9b9 | 2020-05-30 09:48:39 +0100 | [diff] [blame] | 2305 | desc.m_AlignCorners = true; |
| 2306 | desc.m_HalfPixelCenters = true; |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2307 | |
| 2308 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2309 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2310 | armnn::IConnectableLayer* const resizeLayer = network->AddResizeLayer(desc, layerName.c_str()); |
| 2311 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2312 | |
| 2313 | inputLayer->GetOutputSlot(0).Connect(resizeLayer->GetInputSlot(0)); |
| 2314 | resizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2315 | |
| 2316 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2317 | resizeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2318 | |
| 2319 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2320 | CHECK(deserializedNetwork); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2321 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2322 | LayerVerifierBaseWithDescriptor<armnn::ResizeDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, desc); |
| 2323 | deserializedNetwork->ExecuteStrategy(verifier); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2324 | } |
| 2325 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2326 | class ResizeBilinearLayerVerifier : public LayerVerifierBaseWithDescriptor<armnn::ResizeDescriptor> |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2327 | { |
| 2328 | public: |
| 2329 | ResizeBilinearLayerVerifier(const std::string& layerName, |
| 2330 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 2331 | const std::vector<armnn::TensorInfo>& outputInfos, |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2332 | const armnn::ResizeDescriptor& descriptor) |
| 2333 | : LayerVerifierBaseWithDescriptor<armnn::ResizeDescriptor>( |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2334 | layerName, inputInfos, outputInfos, descriptor) {} |
| 2335 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2336 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 2337 | const armnn::BaseDescriptor& descriptor, |
| 2338 | const std::vector<armnn::ConstTensor>& constants, |
| 2339 | const char* name, |
| 2340 | const armnn::LayerBindingId id = 0) override |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2341 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2342 | armnn::IgnoreUnused(descriptor, constants, id); |
| 2343 | switch (layer->GetType()) |
| 2344 | { |
| 2345 | case armnn::LayerType::Input: break; |
| 2346 | case armnn::LayerType::Output: break; |
| 2347 | case armnn::LayerType::Resize: |
| 2348 | { |
| 2349 | VerifyNameAndConnections(layer, name); |
| 2350 | const armnn::ResizeDescriptor& layerDescriptor = |
| 2351 | static_cast<const armnn::ResizeDescriptor&>(descriptor); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2352 | CHECK(layerDescriptor.m_Method == armnn::ResizeMethod::Bilinear); |
| 2353 | CHECK(layerDescriptor.m_TargetWidth == m_Descriptor.m_TargetWidth); |
| 2354 | CHECK(layerDescriptor.m_TargetHeight == m_Descriptor.m_TargetHeight); |
| 2355 | CHECK(layerDescriptor.m_DataLayout == m_Descriptor.m_DataLayout); |
| 2356 | CHECK(layerDescriptor.m_AlignCorners == m_Descriptor.m_AlignCorners); |
| 2357 | CHECK(layerDescriptor.m_HalfPixelCenters == m_Descriptor.m_HalfPixelCenters); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | } |
| 2360 | default: |
| 2361 | { |
| 2362 | throw armnn::Exception("Unexpected layer type in test model. ResizeBiliniar " |
| 2363 | "should have translated to Resize"); |
| 2364 | } |
| 2365 | } |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2366 | } |
| 2367 | }; |
| 2368 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2369 | TEST_CASE("SerializeResizeBilinear") |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2370 | { |
| 2371 | const std::string layerName("resizeBilinear"); |
| 2372 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32); |
| 2373 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32); |
| 2374 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2375 | armnn::ResizeDescriptor desc; |
| 2376 | desc.m_Method = armnn::ResizeMethod::Bilinear; |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2377 | desc.m_TargetWidth = 4u; |
| 2378 | desc.m_TargetHeight = 2u; |
David Monahan | 4a0c9b9 | 2020-05-30 09:48:39 +0100 | [diff] [blame] | 2379 | desc.m_AlignCorners = true; |
| 2380 | desc.m_HalfPixelCenters = true; |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2381 | |
| 2382 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2383 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2384 | armnn::IConnectableLayer* const resizeLayer = network->AddResizeLayer(desc, layerName.c_str()); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2385 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2386 | |
| 2387 | inputLayer->GetOutputSlot(0).Connect(resizeLayer->GetInputSlot(0)); |
| 2388 | resizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2389 | |
| 2390 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2391 | resizeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2392 | |
| 2393 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2394 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2395 | |
| 2396 | ResizeBilinearLayerVerifier verifier(layerName, {inputInfo}, {outputInfo}, desc); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2397 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2400 | TEST_CASE("EnsureResizeBilinearBackwardCompatibility") |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2401 | { |
| 2402 | // The hex data below is a flat buffer containing a simple network with an input, |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2403 | // a ResizeBilinearLayer (now deprecated and removed) and an output |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2404 | // |
| 2405 | // This test verifies that we can still deserialize this old-style model by replacing |
| 2406 | // the ResizeBilinearLayer with an equivalent ResizeLayer |
| 2407 | const std::vector<uint8_t> resizeBilinearModel = |
| 2408 | { |
| 2409 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x0A, 0x00, |
| 2410 | 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 2411 | 0x50, 0x01, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2412 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xD4, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0B, |
| 2413 | 0x04, 0x00, 0x00, 0x00, 0xC2, 0xFE, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, |
| 2414 | 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8A, 0xFF, 0xFF, 0xFF, 0x02, 0x00, 0x00, 0x00, |
| 2415 | 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2416 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2417 | 0x38, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xFF, 0xFF, 0xFF, 0x00, 0x00, |
| 2418 | 0x00, 0x1A, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0E, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 2419 | 0x34, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x12, 0x00, 0x08, 0x00, 0x0C, 0x00, |
| 2420 | 0x07, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 2421 | 0x00, 0x00, 0x0E, 0x00, 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0E, 0x00, |
| 2422 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, |
| 2423 | 0x20, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x72, 0x65, 0x73, 0x69, 0x7A, 0x65, 0x42, 0x69, 0x6C, 0x69, |
| 2424 | 0x6E, 0x65, 0x61, 0x72, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 2425 | 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 2426 | 0x00, 0x00, 0x52, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2427 | 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 2428 | 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2429 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2430 | 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0xF6, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, |
| 2431 | 0x0A, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x14, 0x00, |
| 2432 | 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, |
| 2433 | 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2434 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0A, 0x00, |
| 2435 | 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, |
| 2436 | 0x08, 0x00, 0x07, 0x00, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, |
| 2437 | 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, |
| 2438 | 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 |
| 2439 | }; |
| 2440 | |
| 2441 | armnn::INetworkPtr deserializedNetwork = |
| 2442 | DeserializeNetwork(std::string(resizeBilinearModel.begin(), resizeBilinearModel.end())); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2443 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2444 | |
Teresa Charlin | acb3ec5 | 2023-04-03 19:57:00 +0100 | [diff] [blame] | 2445 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32, 0.0f, 0); |
| 2446 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32, 0.0f, 0); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2447 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2448 | armnn::ResizeDescriptor descriptor; |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2449 | descriptor.m_TargetWidth = 4u; |
| 2450 | descriptor.m_TargetHeight = 2u; |
| 2451 | |
| 2452 | ResizeBilinearLayerVerifier verifier("resizeBilinear", { inputInfo }, { outputInfo }, descriptor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2453 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | fe414cf | 2019-10-31 14:35:58 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 2456 | TEST_CASE("SerializeShape") |
| 2457 | { |
| 2458 | const std::string layerName("shape"); |
| 2459 | const armnn::TensorInfo inputInfo({1, 3, 3, 1}, armnn::DataType::Signed32); |
| 2460 | const armnn::TensorInfo outputInfo({ 4 }, armnn::DataType::Signed32); |
| 2461 | |
| 2462 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2463 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2464 | armnn::IConnectableLayer* const shapeLayer = network->AddShapeLayer(layerName.c_str()); |
| 2465 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2466 | |
| 2467 | inputLayer->GetOutputSlot(0).Connect(shapeLayer->GetInputSlot(0)); |
| 2468 | shapeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2469 | |
| 2470 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2471 | shapeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2472 | |
| 2473 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
| 2474 | CHECK(deserializedNetwork); |
| 2475 | |
| 2476 | LayerVerifierBase verifier(layerName, {inputInfo}, {outputInfo}); |
| 2477 | |
| 2478 | deserializedNetwork->ExecuteStrategy(verifier); |
| 2479 | } |
| 2480 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2481 | TEST_CASE("SerializeSlice") |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 2482 | { |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 2483 | const std::string layerName{"slice"}; |
| 2484 | |
| 2485 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({3, 2, 3, 1}, armnn::DataType::Float32); |
| 2486 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({2, 2, 2, 1}, armnn::DataType::Float32); |
| 2487 | |
| 2488 | armnn::SliceDescriptor descriptor({ 0, 0, 1, 0}, {2, 2, 2, 1}); |
| 2489 | |
| 2490 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2491 | |
| 2492 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2493 | armnn::IConnectableLayer* const sliceLayer = network->AddSliceLayer(descriptor, layerName.c_str()); |
| 2494 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2495 | |
| 2496 | inputLayer->GetOutputSlot(0).Connect(sliceLayer->GetInputSlot(0)); |
| 2497 | sliceLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2498 | |
| 2499 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2500 | sliceLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2501 | |
| 2502 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2503 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 2504 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2505 | LayerVerifierBaseWithDescriptor<armnn::SliceDescriptor> verifier(layerName, {inputInfo}, {outputInfo}, descriptor); |
| 2506 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2509 | TEST_CASE("SerializeSoftmax") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2510 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2511 | const std::string layerName("softmax"); |
| 2512 | const armnn::TensorInfo info({1, 10}, armnn::DataType::Float32); |
| 2513 | |
| 2514 | armnn::SoftmaxDescriptor descriptor; |
| 2515 | descriptor.m_Beta = 1.0f; |
| 2516 | |
| 2517 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2518 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2519 | armnn::IConnectableLayer* const softmaxLayer = network->AddSoftmaxLayer(descriptor, layerName.c_str()); |
| 2520 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2521 | |
| 2522 | inputLayer->GetOutputSlot(0).Connect(softmaxLayer->GetInputSlot(0)); |
| 2523 | softmaxLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2524 | |
| 2525 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2526 | softmaxLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2527 | |
| 2528 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2529 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2530 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2531 | LayerVerifierBaseWithDescriptor<armnn::SoftmaxDescriptor> verifier(layerName, {info}, {info}, descriptor); |
| 2532 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2535 | TEST_CASE("SerializeSpaceToBatchNd") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2536 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2537 | const std::string layerName("spaceToBatchNd"); |
| 2538 | const armnn::TensorInfo inputInfo({2, 1, 2, 4}, armnn::DataType::Float32); |
| 2539 | const armnn::TensorInfo outputInfo({8, 1, 1, 3}, armnn::DataType::Float32); |
| 2540 | |
| 2541 | armnn::SpaceToBatchNdDescriptor desc; |
| 2542 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 2543 | desc.m_BlockShape = {2, 2}; |
| 2544 | desc.m_PadList = {{0, 0}, {2, 0}}; |
| 2545 | |
| 2546 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2547 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2548 | armnn::IConnectableLayer* const spaceToBatchNdLayer = network->AddSpaceToBatchNdLayer(desc, layerName.c_str()); |
| 2549 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2550 | |
| 2551 | inputLayer->GetOutputSlot(0).Connect(spaceToBatchNdLayer->GetInputSlot(0)); |
| 2552 | spaceToBatchNdLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2553 | |
| 2554 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2555 | spaceToBatchNdLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2556 | |
| 2557 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2558 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2559 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2560 | LayerVerifierBaseWithDescriptor<armnn::SpaceToBatchNdDescriptor> verifier( |
| 2561 | layerName, {inputInfo}, {outputInfo}, desc); |
| 2562 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2565 | TEST_CASE("SerializeSpaceToDepth") |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2566 | { |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2567 | const std::string layerName("spaceToDepth"); |
| 2568 | |
| 2569 | const armnn::TensorInfo inputInfo ({ 1, 16, 8, 3 }, armnn::DataType::Float32); |
| 2570 | const armnn::TensorInfo outputInfo({ 1, 8, 4, 12 }, armnn::DataType::Float32); |
| 2571 | |
| 2572 | armnn::SpaceToDepthDescriptor desc; |
| 2573 | desc.m_BlockSize = 2; |
| 2574 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 2575 | |
| 2576 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2577 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2578 | armnn::IConnectableLayer* const spaceToDepthLayer = network->AddSpaceToDepthLayer(desc, layerName.c_str()); |
| 2579 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2580 | |
| 2581 | inputLayer->GetOutputSlot(0).Connect(spaceToDepthLayer->GetInputSlot(0)); |
| 2582 | spaceToDepthLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2583 | |
| 2584 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2585 | spaceToDepthLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2586 | |
| 2587 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2588 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2589 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2590 | LayerVerifierBaseWithDescriptor<armnn::SpaceToDepthDescriptor> verifier( |
| 2591 | layerName, {inputInfo}, {outputInfo}, desc); |
| 2592 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2593 | } |
| 2594 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2595 | TEST_CASE("SerializeSplitter") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2596 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2597 | const unsigned int numViews = 3; |
| 2598 | const unsigned int numDimensions = 4; |
| 2599 | const unsigned int inputShape[] = {1, 18, 4, 4}; |
| 2600 | const unsigned int outputShape[] = {1, 6, 4, 4}; |
| 2601 | |
| 2602 | // This is modelled on how the caffe parser sets up a splitter layer to partition an input along dimension one. |
| 2603 | unsigned int splitterDimSizes[4] = {static_cast<unsigned int>(inputShape[0]), |
| 2604 | static_cast<unsigned int>(inputShape[1]), |
| 2605 | static_cast<unsigned int>(inputShape[2]), |
| 2606 | static_cast<unsigned int>(inputShape[3])}; |
| 2607 | splitterDimSizes[1] /= numViews; |
| 2608 | armnn::ViewsDescriptor desc(numViews, numDimensions); |
| 2609 | |
| 2610 | for (unsigned int g = 0; g < numViews; ++g) |
| 2611 | { |
| 2612 | desc.SetViewOriginCoord(g, 1, splitterDimSizes[1] * g); |
| 2613 | |
| 2614 | for (unsigned int dimIdx=0; dimIdx < 4; dimIdx++) |
| 2615 | { |
| 2616 | desc.SetViewSize(g, dimIdx, splitterDimSizes[dimIdx]); |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | const std::string layerName("splitter"); |
| 2621 | const armnn::TensorInfo inputInfo(numDimensions, inputShape, armnn::DataType::Float32); |
| 2622 | const armnn::TensorInfo outputInfo(numDimensions, outputShape, armnn::DataType::Float32); |
| 2623 | |
| 2624 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2625 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2626 | armnn::IConnectableLayer* const splitterLayer = network->AddSplitterLayer(desc, layerName.c_str()); |
| 2627 | armnn::IConnectableLayer* const outputLayer0 = network->AddOutputLayer(0); |
| 2628 | armnn::IConnectableLayer* const outputLayer1 = network->AddOutputLayer(1); |
| 2629 | armnn::IConnectableLayer* const outputLayer2 = network->AddOutputLayer(2); |
| 2630 | |
| 2631 | inputLayer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0)); |
| 2632 | splitterLayer->GetOutputSlot(0).Connect(outputLayer0->GetInputSlot(0)); |
| 2633 | splitterLayer->GetOutputSlot(1).Connect(outputLayer1->GetInputSlot(0)); |
| 2634 | splitterLayer->GetOutputSlot(2).Connect(outputLayer2->GetInputSlot(0)); |
| 2635 | |
| 2636 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2637 | splitterLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2638 | splitterLayer->GetOutputSlot(1).SetTensorInfo(outputInfo); |
| 2639 | splitterLayer->GetOutputSlot(2).SetTensorInfo(outputInfo); |
| 2640 | |
| 2641 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2642 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2643 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2644 | LayerVerifierBaseWithDescriptor<armnn::ViewsDescriptor> verifier( |
| 2645 | layerName, {inputInfo}, {outputInfo, outputInfo, outputInfo}, desc); |
| 2646 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2649 | TEST_CASE("SerializeStack") |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 2650 | { |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 2651 | const std::string layerName("stack"); |
| 2652 | |
| 2653 | armnn::TensorInfo inputTensorInfo ({4, 3, 5}, armnn::DataType::Float32); |
| 2654 | armnn::TensorInfo outputTensorInfo({4, 3, 2, 5}, armnn::DataType::Float32); |
| 2655 | |
| 2656 | armnn::StackDescriptor descriptor(2, 2, {4, 3, 5}); |
| 2657 | |
| 2658 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2659 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(0); |
| 2660 | armnn::IConnectableLayer* const inputLayer2 = network->AddInputLayer(1); |
| 2661 | armnn::IConnectableLayer* const stackLayer = network->AddStackLayer(descriptor, layerName.c_str()); |
| 2662 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2663 | |
| 2664 | inputLayer1->GetOutputSlot(0).Connect(stackLayer->GetInputSlot(0)); |
| 2665 | inputLayer2->GetOutputSlot(0).Connect(stackLayer->GetInputSlot(1)); |
| 2666 | stackLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2667 | |
| 2668 | inputLayer1->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 2669 | inputLayer2->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 2670 | stackLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2671 | |
| 2672 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2673 | CHECK(deserializedNetwork); |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 2674 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2675 | LayerVerifierBaseWithDescriptor<armnn::StackDescriptor> verifier( |
| 2676 | layerName, {inputTensorInfo, inputTensorInfo}, {outputTensorInfo}, descriptor); |
| 2677 | deserializedNetwork->ExecuteStrategy(verifier); |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2680 | TEST_CASE("SerializeStandIn") |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 2681 | { |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 2682 | const std::string layerName("standIn"); |
| 2683 | |
| 2684 | armnn::TensorInfo tensorInfo({ 1u }, armnn::DataType::Float32); |
| 2685 | armnn::StandInDescriptor descriptor(2u, 2u); |
| 2686 | |
| 2687 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2688 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 2689 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
| 2690 | armnn::IConnectableLayer* const standInLayer = network->AddStandInLayer(descriptor, layerName.c_str()); |
| 2691 | armnn::IConnectableLayer* const outputLayer0 = network->AddOutputLayer(0); |
| 2692 | armnn::IConnectableLayer* const outputLayer1 = network->AddOutputLayer(1); |
| 2693 | |
| 2694 | inputLayer0->GetOutputSlot(0).Connect(standInLayer->GetInputSlot(0)); |
| 2695 | inputLayer0->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 2696 | |
| 2697 | inputLayer1->GetOutputSlot(0).Connect(standInLayer->GetInputSlot(1)); |
| 2698 | inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 2699 | |
| 2700 | standInLayer->GetOutputSlot(0).Connect(outputLayer0->GetInputSlot(0)); |
| 2701 | standInLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 2702 | |
| 2703 | standInLayer->GetOutputSlot(1).Connect(outputLayer1->GetInputSlot(0)); |
| 2704 | standInLayer->GetOutputSlot(1).SetTensorInfo(tensorInfo); |
| 2705 | |
| 2706 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2707 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 2708 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2709 | LayerVerifierBaseWithDescriptor<armnn::StandInDescriptor> verifier( |
| 2710 | layerName, { tensorInfo, tensorInfo }, { tensorInfo, tensorInfo }, descriptor); |
| 2711 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 2712 | } |
| 2713 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2714 | TEST_CASE("SerializeStridedSlice") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2715 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2716 | const std::string layerName("stridedSlice"); |
| 2717 | const armnn::TensorInfo inputInfo = armnn::TensorInfo({3, 2, 3, 1}, armnn::DataType::Float32); |
| 2718 | const armnn::TensorInfo outputInfo = armnn::TensorInfo({3, 1}, armnn::DataType::Float32); |
| 2719 | |
| 2720 | armnn::StridedSliceDescriptor desc({0, 0, 1, 0}, {1, 1, 1, 1}, {1, 1, 1, 1}); |
| 2721 | desc.m_EndMask = (1 << 4) - 1; |
| 2722 | desc.m_ShrinkAxisMask = (1 << 1) | (1 << 2); |
| 2723 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 2724 | |
| 2725 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2726 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2727 | armnn::IConnectableLayer* const stridedSliceLayer = network->AddStridedSliceLayer(desc, layerName.c_str()); |
| 2728 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2729 | |
| 2730 | inputLayer->GetOutputSlot(0).Connect(stridedSliceLayer->GetInputSlot(0)); |
| 2731 | stridedSliceLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2732 | |
| 2733 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2734 | stridedSliceLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2735 | |
| 2736 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2737 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2738 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2739 | LayerVerifierBaseWithDescriptor<armnn::StridedSliceDescriptor> verifier( |
| 2740 | layerName, {inputInfo}, {outputInfo}, desc); |
| 2741 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2744 | TEST_CASE("SerializeSubtraction") |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2745 | { |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2746 | const std::string layerName("subtraction"); |
| 2747 | const armnn::TensorInfo info({ 1, 4 }, armnn::DataType::Float32); |
| 2748 | |
| 2749 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2750 | armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); |
| 2751 | armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 2752 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2753 | armnn::IConnectableLayer* const subtractionLayer = network->AddSubtractionLayer(layerName.c_str()); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 2754 | ARMNN_NO_DEPRECATE_WARN_END |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2755 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2756 | |
| 2757 | inputLayer0->GetOutputSlot(0).Connect(subtractionLayer->GetInputSlot(0)); |
| 2758 | inputLayer1->GetOutputSlot(0).Connect(subtractionLayer->GetInputSlot(1)); |
| 2759 | subtractionLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2760 | |
| 2761 | inputLayer0->GetOutputSlot(0).SetTensorInfo(info); |
| 2762 | inputLayer1->GetOutputSlot(0).SetTensorInfo(info); |
| 2763 | subtractionLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2764 | |
| 2765 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2766 | CHECK(deserializedNetwork); |
Nattapat Chaimanowong | 03acd68 | 2019-03-20 11:19:52 +0000 | [diff] [blame] | 2767 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2768 | LayerVerifierBase verifier(layerName, {info, info}, {info}); |
| 2769 | deserializedNetwork->ExecuteStrategy(verifier); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2772 | TEST_CASE("SerializeSwitch") |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2773 | { |
| 2774 | class SwitchLayerVerifier : public LayerVerifierBase |
| 2775 | { |
| 2776 | public: |
| 2777 | SwitchLayerVerifier(const std::string& layerName, |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 2778 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 2779 | const std::vector<armnn::TensorInfo>& outputInfos) |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2780 | : LayerVerifierBase(layerName, inputInfos, outputInfos) {} |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2781 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2782 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 2783 | const armnn::BaseDescriptor& descriptor, |
| 2784 | const std::vector<armnn::ConstTensor>& constants, |
| 2785 | const char* name, |
| 2786 | const armnn::LayerBindingId id = 0) override |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2787 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2788 | armnn::IgnoreUnused(descriptor, constants, id); |
| 2789 | switch (layer->GetType()) |
| 2790 | { |
| 2791 | case armnn::LayerType::Input: break; |
| 2792 | case armnn::LayerType::Output: break; |
| 2793 | case armnn::LayerType::Constant: break; |
| 2794 | case armnn::LayerType::Switch: |
| 2795 | { |
| 2796 | VerifyNameAndConnections(layer, name); |
| 2797 | break; |
| 2798 | } |
| 2799 | default: |
| 2800 | { |
| 2801 | throw armnn::Exception("Unexpected layer type in Switch test model"); |
| 2802 | } |
| 2803 | } |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2804 | } |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2805 | }; |
| 2806 | |
| 2807 | const std::string layerName("switch"); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 2808 | const armnn::TensorInfo info({ 1, 4 }, armnn::DataType::Float32, 0.0f, 0, true); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2809 | |
| 2810 | std::vector<float> constantData = GenerateRandomData<float>(info.GetNumElements()); |
| 2811 | armnn::ConstTensor constTensor(info, constantData); |
| 2812 | |
| 2813 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2814 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2815 | armnn::IConnectableLayer* const constantLayer = network->AddConstantLayer(constTensor, "constant"); |
| 2816 | armnn::IConnectableLayer* const switchLayer = network->AddSwitchLayer(layerName.c_str()); |
| 2817 | armnn::IConnectableLayer* const trueOutputLayer = network->AddOutputLayer(0); |
| 2818 | armnn::IConnectableLayer* const falseOutputLayer = network->AddOutputLayer(1); |
| 2819 | |
| 2820 | inputLayer->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(0)); |
| 2821 | constantLayer->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(1)); |
| 2822 | switchLayer->GetOutputSlot(0).Connect(trueOutputLayer->GetInputSlot(0)); |
| 2823 | switchLayer->GetOutputSlot(1).Connect(falseOutputLayer->GetInputSlot(0)); |
| 2824 | |
| 2825 | inputLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2826 | constantLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2827 | switchLayer->GetOutputSlot(0).SetTensorInfo(info); |
| 2828 | switchLayer->GetOutputSlot(1).SetTensorInfo(info); |
| 2829 | |
| 2830 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2831 | CHECK(deserializedNetwork); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2832 | |
| 2833 | SwitchLayerVerifier verifier(layerName, {info, info}, {info, info}); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2834 | deserializedNetwork->ExecuteStrategy(verifier); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2837 | TEST_CASE("SerializeTranspose") |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2838 | { |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2839 | const std::string layerName("transpose"); |
| 2840 | const armnn::TensorInfo inputTensorInfo({4, 3, 2, 1}, armnn::DataType::Float32); |
| 2841 | const armnn::TensorInfo outputTensorInfo({1, 2, 3, 4}, armnn::DataType::Float32); |
| 2842 | |
| 2843 | armnn::TransposeDescriptor descriptor(armnn::PermutationVector({3, 2, 1, 0})); |
| 2844 | |
| 2845 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2846 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2847 | armnn::IConnectableLayer* const transposeLayer = network->AddTransposeLayer(descriptor, layerName.c_str()); |
| 2848 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2849 | |
| 2850 | inputLayer->GetOutputSlot(0).Connect(transposeLayer->GetInputSlot(0)); |
| 2851 | transposeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2852 | |
| 2853 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 2854 | transposeLayer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2855 | |
| 2856 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2857 | CHECK(deserializedNetwork); |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2858 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2859 | LayerVerifierBaseWithDescriptor<armnn::TransposeDescriptor> verifier( |
| 2860 | layerName, {inputTensorInfo}, {outputTensorInfo}, descriptor); |
| 2861 | deserializedNetwork->ExecuteStrategy(verifier); |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2864 | TEST_CASE("SerializeTransposeConvolution2d") |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 2865 | { |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 2866 | const std::string layerName("transposeConvolution2d"); |
| 2867 | const armnn::TensorInfo inputInfo ({ 1, 7, 7, 1 }, armnn::DataType::Float32); |
| 2868 | const armnn::TensorInfo outputInfo({ 1, 9, 9, 1 }, armnn::DataType::Float32); |
| 2869 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 2870 | const armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 2871 | const armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 2872 | |
| 2873 | std::vector<float> weightsData = GenerateRandomData<float>(weightsInfo.GetNumElements()); |
| 2874 | armnn::ConstTensor weights(weightsInfo, weightsData); |
| 2875 | |
| 2876 | std::vector<float> biasesData = GenerateRandomData<float>(biasesInfo.GetNumElements()); |
| 2877 | armnn::ConstTensor biases(biasesInfo, biasesData); |
| 2878 | |
| 2879 | armnn::TransposeConvolution2dDescriptor descriptor; |
| 2880 | descriptor.m_PadLeft = 1; |
| 2881 | descriptor.m_PadRight = 1; |
| 2882 | descriptor.m_PadTop = 1; |
| 2883 | descriptor.m_PadBottom = 1; |
| 2884 | descriptor.m_StrideX = 1; |
| 2885 | descriptor.m_StrideY = 1; |
| 2886 | descriptor.m_BiasEnabled = true; |
| 2887 | descriptor.m_DataLayout = armnn::DataLayout::NHWC; |
| 2888 | |
| 2889 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 2890 | armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0); |
| 2891 | armnn::IConnectableLayer* const convLayer = |
| 2892 | network->AddTransposeConvolution2dLayer(descriptor, |
| 2893 | weights, |
| 2894 | armnn::Optional<armnn::ConstTensor>(biases), |
| 2895 | layerName.c_str()); |
| 2896 | armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); |
| 2897 | |
| 2898 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
| 2899 | convLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 2900 | |
| 2901 | inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 2902 | convLayer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2903 | |
| 2904 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2905 | CHECK(deserializedNetwork); |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 2906 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2907 | const std::vector<armnn::ConstTensor> constants {weights, biases}; |
| 2908 | LayerVerifierBaseWithDescriptorAndConstants<armnn::TransposeConvolution2dDescriptor> verifier( |
| 2909 | layerName, {inputInfo}, {outputInfo}, descriptor, constants); |
| 2910 | deserializedNetwork->ExecuteStrategy(verifier); |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2913 | TEST_CASE("SerializeDeserializeNonLinearNetwork") |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2914 | { |
| 2915 | class ConstantLayerVerifier : public LayerVerifierBase |
| 2916 | { |
| 2917 | public: |
| 2918 | ConstantLayerVerifier(const std::string& layerName, |
| 2919 | const std::vector<armnn::TensorInfo>& inputInfos, |
| 2920 | const std::vector<armnn::TensorInfo>& outputInfos, |
| 2921 | const armnn::ConstTensor& layerInput) |
| 2922 | : LayerVerifierBase(layerName, inputInfos, outputInfos) |
| 2923 | , m_LayerInput(layerInput) {} |
| 2924 | |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2925 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 2926 | const armnn::BaseDescriptor& descriptor, |
| 2927 | const std::vector<armnn::ConstTensor>& constants, |
| 2928 | const char* name, |
| 2929 | const armnn::LayerBindingId id = 0) override |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2930 | { |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2931 | armnn::IgnoreUnused(descriptor, constants, id); |
| 2932 | switch (layer->GetType()) |
| 2933 | { |
| 2934 | case armnn::LayerType::Input: break; |
| 2935 | case armnn::LayerType::Output: break; |
| 2936 | case armnn::LayerType::Addition: break; |
| 2937 | case armnn::LayerType::Constant: |
| 2938 | { |
| 2939 | VerifyNameAndConnections(layer, name); |
| 2940 | CompareConstTensor(constants.at(0), m_LayerInput); |
| 2941 | break; |
| 2942 | } |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2943 | case armnn::LayerType::ElementwiseBinary: break; |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2944 | default: |
| 2945 | { |
| 2946 | throw armnn::Exception("Unexpected layer type in test model"); |
| 2947 | } |
| 2948 | } |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2951 | private: |
| 2952 | armnn::ConstTensor m_LayerInput; |
| 2953 | }; |
| 2954 | |
| 2955 | const std::string layerName("constant"); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 2956 | const armnn::TensorInfo info({ 2, 3 }, armnn::DataType::Float32, 0.0f, 0, true); |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2957 | |
| 2958 | std::vector<float> constantData = GenerateRandomData<float>(info.GetNumElements()); |
| 2959 | armnn::ConstTensor constTensor(info, constantData); |
| 2960 | |
| 2961 | armnn::INetworkPtr network(armnn::INetwork::Create()); |
| 2962 | armnn::IConnectableLayer* input = network->AddInputLayer(0); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 2963 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2964 | armnn::IConnectableLayer* add = network->AddAdditionLayer(); |
Mike Kelly | 2c14db6 | 2023-03-15 15:06:23 +0000 | [diff] [blame] | 2965 | ARMNN_NO_DEPRECATE_WARN_END |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2966 | armnn::IConnectableLayer* constant = network->AddConstantLayer(constTensor, layerName.c_str()); |
| 2967 | armnn::IConnectableLayer* output = network->AddOutputLayer(0); |
| 2968 | |
| 2969 | input->GetOutputSlot(0).Connect(add->GetInputSlot(0)); |
| 2970 | constant->GetOutputSlot(0).Connect(add->GetInputSlot(1)); |
| 2971 | add->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 2972 | |
| 2973 | input->GetOutputSlot(0).SetTensorInfo(info); |
| 2974 | constant->GetOutputSlot(0).SetTensorInfo(info); |
| 2975 | add->GetOutputSlot(0).SetTensorInfo(info); |
| 2976 | |
| 2977 | armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network)); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 2978 | CHECK(deserializedNetwork); |
Sadik Armagan | db059fd | 2019-03-20 12:28:32 +0000 | [diff] [blame] | 2979 | |
| 2980 | ConstantLayerVerifier verifier(layerName, {}, {info}, constTensor); |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 2981 | deserializedNetwork->ExecuteStrategy(verifier); |
James Conroy | 8d33318 | 2020-05-13 10:27:58 +0100 | [diff] [blame] | 2982 | } |
| 2983 | |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 2984 | } |