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