Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1 | // |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2 | // Copyright © 2017,2019-2023 Arm Ltd and Contributors. All rights reserved. |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 6 | #include "Deserializer.hpp" |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 7 | |
Matthew Bentham | ff130e2 | 2020-01-17 11:47:42 +0000 | [diff] [blame] | 8 | #include <armnn/Descriptors.hpp> |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 9 | #include <armnn/Exceptions.hpp> |
Matthew Bentham | ff130e2 | 2020-01-17 11:47:42 +0000 | [diff] [blame] | 10 | #include <armnn/TypesUtils.hpp> |
| 11 | #include <armnn/LstmParams.hpp> |
| 12 | #include <armnn/QuantizedLstmParams.hpp> |
Simon Obute | db5804e | 2022-04-14 15:49:52 +0100 | [diff] [blame] | 13 | #include <armnn/Logging.hpp> |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 14 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 15 | #include <armnnUtils/Permute.hpp> |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 16 | #include <armnnUtils/Transpose.hpp> |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 17 | #include <armnn/utility/Assert.hpp> |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 18 | #include <armnn/utility/IgnoreUnused.hpp> |
Matthew Sloyan | 0663d66 | 2020-09-14 11:47:26 +0100 | [diff] [blame] | 19 | #include <armnn/utility/NumericCast.hpp> |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 20 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 21 | #include <ParserHelper.hpp> |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 22 | #include <VerificationHelpers.hpp> |
| 23 | |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 24 | #include <fmt/format.h> |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 25 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 26 | #include <fstream> |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 27 | #include <algorithm> |
| 28 | #include <limits> |
| 29 | #include <numeric> |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 30 | |
| 31 | using armnn::ParseException; |
| 32 | using namespace armnn; |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 33 | using namespace armnnSerializer; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 34 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 35 | namespace armnnDeserializer |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 36 | { |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 37 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 38 | IDeserializer::IDeserializer() : pDeserializerImpl(new DeserializerImpl()){} |
| 39 | |
| 40 | IDeserializer::~IDeserializer() = default; |
| 41 | |
| 42 | IDeserializer *IDeserializer::CreateRaw() |
| 43 | { |
| 44 | return new IDeserializer(); |
| 45 | } |
| 46 | |
| 47 | IDeserializerPtr IDeserializer::Create() |
| 48 | { |
| 49 | return IDeserializerPtr(CreateRaw(), &IDeserializer::Destroy); |
| 50 | } |
| 51 | |
| 52 | void IDeserializer::Destroy(IDeserializer *parser) |
| 53 | { |
| 54 | delete parser; |
| 55 | } |
| 56 | |
| 57 | armnn::INetworkPtr IDeserializer::CreateNetworkFromBinary(const std::vector<uint8_t> &binaryContent) |
| 58 | { |
| 59 | return pDeserializerImpl->CreateNetworkFromBinary(binaryContent); |
| 60 | } |
| 61 | |
| 62 | armnn::INetworkPtr IDeserializer::CreateNetworkFromBinary(std::istream &binaryContent) |
| 63 | { |
| 64 | return pDeserializerImpl->CreateNetworkFromBinary(binaryContent); |
| 65 | } |
| 66 | |
| 67 | BindingPointInfo IDeserializer::GetNetworkInputBindingInfo(unsigned int layerId, const std::string &name) const |
| 68 | { |
| 69 | return pDeserializerImpl->GetNetworkInputBindingInfo(layerId, name); |
| 70 | } |
| 71 | |
| 72 | BindingPointInfo IDeserializer::GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const |
| 73 | { |
| 74 | return pDeserializerImpl->GetNetworkOutputBindingInfo(layerId, name); |
| 75 | } |
| 76 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 77 | namespace |
| 78 | { |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 79 | |
| 80 | const uint32_t VIRTUAL_LAYER_ID = std::numeric_limits<uint32_t>::max(); |
| 81 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 82 | void CheckGraph(const GraphPtr& graph, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 83 | unsigned int layersIndex, |
| 84 | const CheckLocation& location) |
| 85 | { |
| 86 | if (graph->layers() == nullptr) |
| 87 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 88 | throw ParseException(fmt::format("{0} was called with invalid (null) graph. " |
| 89 | "Possible reason is that the graph is not yet loaded and Unpack(ed). " |
| 90 | "layers:{1} at {2}", |
| 91 | location.m_Function, |
| 92 | layersIndex, |
| 93 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 94 | } |
| 95 | else if (layersIndex >= graph->layers()->size()) |
| 96 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 97 | throw ParseException(fmt::format("{0} was called with an invalid layers index. layers:{1} at {2}", |
| 98 | location.m_Function, |
| 99 | layersIndex, |
| 100 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 104 | void CheckLayers(const GraphPtr& graph, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 105 | unsigned int layersIndex, |
| 106 | unsigned int layerIndex, |
| 107 | const CheckLocation& location) |
| 108 | { |
| 109 | if (graph->layers() == nullptr) |
| 110 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 111 | throw ParseException(fmt::format("{0} was called with invalid (null) graph. " |
| 112 | "Possible reason is that the graph is not yet loaded and Unpack(ed). " |
| 113 | "layers:{1} at {2}", |
| 114 | location.m_Function, |
| 115 | layersIndex, |
| 116 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 117 | } |
| 118 | else if (layersIndex >= graph->layers()->size()) |
| 119 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 120 | throw ParseException(fmt::format("{0} was called with an invalid layers index. " |
| 121 | "layers:{1} at {2}", |
| 122 | location.m_Function, |
| 123 | layersIndex, |
| 124 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 125 | } |
| 126 | else if (layerIndex >= graph->layers()[layersIndex].size() |
| 127 | && layerIndex != VIRTUAL_LAYER_ID) |
| 128 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 129 | throw ParseException(fmt::format("{0} was called with an invalid layer index. " |
| 130 | "layers:{1} layer:{2} at {3}", |
| 131 | location.m_Function, |
| 132 | layersIndex, |
| 133 | layerIndex, |
| 134 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 138 | void CheckTensorPtr(TensorRawPtr rawPtr, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 139 | const CheckLocation& location) |
| 140 | { |
| 141 | if (rawPtr == nullptr) |
| 142 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 143 | throw ParseException(fmt::format("{0} was called with a null tensor pointer. at {1}", |
| 144 | location.m_Function, |
| 145 | location.FileLine())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 149 | void CheckConstTensorPtr(ConstTensorRawPtr rawPtr, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 150 | const CheckLocation& location) |
| 151 | { |
| 152 | if (rawPtr == nullptr) |
| 153 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 154 | throw ParseException(fmt::format("{0} was called with a null const tensor pointer. at {1}", |
| 155 | location.m_Function, |
| 156 | location.FileLine())); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 160 | void CheckConstTensorSize(const unsigned int constTensorSize, |
| 161 | const unsigned int tensorSize, |
| 162 | const CheckLocation& location) |
| 163 | { |
| 164 | if (constTensorSize != tensorSize) |
| 165 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 166 | throw ParseException(fmt::format("{0} wrong number of components supplied to tensor. at:{1}", |
| 167 | location.m_Function, |
| 168 | location.FileLine())); |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 172 | #define CHECK_TENSOR_PTR(TENSOR_PTR) \ |
| 173 | CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION()) |
| 174 | |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 175 | #define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE) \ |
| 176 | CheckConstTensorSize(CONST_TENSOR_SIZE, TENSOR_SIZE, CHECK_LOCATION()) |
| 177 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 178 | #define CHECK_CONST_TENSOR_PTR(TENSOR_PTR) \ |
| 179 | CheckConstTensorPtr(TENSOR_PTR, CHECK_LOCATION()) |
| 180 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 181 | #define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX) \ |
| 182 | CheckLayers(GRAPH, LAYERS_INDEX, LAYER_INDEX, CHECK_LOCATION()) |
| 183 | |
| 184 | #define CHECK_GRAPH(GRAPH, LAYERS_INDEX) \ |
| 185 | CheckGraph(GRAPH, LAYERS_INDEX, CHECK_LOCATION()) |
| 186 | } |
| 187 | |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 188 | bool CheckShape(const armnn::TensorShape& actual, const std::vector<uint32_t>& expected) |
| 189 | { |
| 190 | const unsigned int actualSize = actual.GetNumDimensions(); |
| 191 | if (actualSize != expected.size()) |
| 192 | { |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | for (unsigned int i = 0u; i < actualSize; i++) |
| 197 | { |
| 198 | if (actual[i] != static_cast<unsigned int>(expected[i])) |
| 199 | { |
| 200 | return false; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 207 | IDeserializer::DeserializerImpl::DeserializerImpl() |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 208 | : m_Network(nullptr, nullptr), |
| 209 | //May require LayerType_Max to be included |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 210 | m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupportedLayer) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 211 | { |
| 212 | // register supported layers |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 213 | m_ParserFunctions[Layer_AbsLayer] = &DeserializerImpl::ParseAbs; |
| 214 | m_ParserFunctions[Layer_ActivationLayer] = &DeserializerImpl::ParseActivation; |
| 215 | m_ParserFunctions[Layer_AdditionLayer] = &DeserializerImpl::ParseAdd; |
| 216 | m_ParserFunctions[Layer_ArgMinMaxLayer] = &DeserializerImpl::ParseArgMinMax; |
Samuel Yap | a04f4a1 | 2022-08-19 11:14:38 +0100 | [diff] [blame] | 217 | m_ParserFunctions[Layer_BatchMatMulLayer] = &DeserializerImpl::ParseBatchMatMul; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 218 | m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &DeserializerImpl::ParseBatchToSpaceNd; |
| 219 | m_ParserFunctions[Layer_BatchNormalizationLayer] = &DeserializerImpl::ParseBatchNormalization; |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 220 | m_ParserFunctions[Layer_CastLayer] = &DeserializerImpl::ParseCast; |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 221 | m_ParserFunctions[Layer_ChannelShuffleLayer] = &DeserializerImpl::ParseChannelShuffle; |
| 222 | m_ParserFunctions[Layer_ComparisonLayer] = &DeserializerImpl::ParseComparison; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 223 | m_ParserFunctions[Layer_ConcatLayer] = &DeserializerImpl::ParseConcat; |
| 224 | m_ParserFunctions[Layer_ConstantLayer] = &DeserializerImpl::ParseConstant; |
| 225 | m_ParserFunctions[Layer_Convolution2dLayer] = &DeserializerImpl::ParseConvolution2d; |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 226 | m_ParserFunctions[Layer_Convolution3dLayer] = &DeserializerImpl::ParseConvolution3d; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 227 | m_ParserFunctions[Layer_DepthToSpaceLayer] = &DeserializerImpl::ParseDepthToSpace; |
| 228 | m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &DeserializerImpl::ParseDepthwiseConvolution2d; |
| 229 | m_ParserFunctions[Layer_DequantizeLayer] = &DeserializerImpl::ParseDequantize; |
| 230 | m_ParserFunctions[Layer_DetectionPostProcessLayer] = &DeserializerImpl::ParseDetectionPostProcess; |
| 231 | m_ParserFunctions[Layer_DivisionLayer] = &DeserializerImpl::ParseDivision; |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 232 | m_ParserFunctions[Layer_ElementwiseBinaryLayer] = &DeserializerImpl::ParseElementwiseBinary; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 233 | m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &DeserializerImpl::ParseElementwiseUnary; |
| 234 | m_ParserFunctions[Layer_EqualLayer] = &DeserializerImpl::ParseEqual; |
| 235 | m_ParserFunctions[Layer_FullyConnectedLayer] = &DeserializerImpl::ParseFullyConnected; |
| 236 | m_ParserFunctions[Layer_FillLayer] = &DeserializerImpl::ParseFill; |
| 237 | m_ParserFunctions[Layer_FloorLayer] = &DeserializerImpl::ParseFloor; |
| 238 | m_ParserFunctions[Layer_GatherLayer] = &DeserializerImpl::ParseGather; |
Teresa Charlin | 6966bfa | 2022-04-25 17:14:50 +0100 | [diff] [blame] | 239 | m_ParserFunctions[Layer_GatherNdLayer] = &DeserializerImpl::ParseGatherNd; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 240 | m_ParserFunctions[Layer_GreaterLayer] = &DeserializerImpl::ParseGreater; |
| 241 | m_ParserFunctions[Layer_InstanceNormalizationLayer] = &DeserializerImpl::ParseInstanceNormalization; |
| 242 | m_ParserFunctions[Layer_L2NormalizationLayer] = &DeserializerImpl::ParseL2Normalization; |
| 243 | m_ParserFunctions[Layer_LogicalBinaryLayer] = &DeserializerImpl::ParseLogicalBinary; |
| 244 | m_ParserFunctions[Layer_LogSoftmaxLayer] = &DeserializerImpl::ParseLogSoftmax; |
| 245 | m_ParserFunctions[Layer_LstmLayer] = &DeserializerImpl::ParseLstm; |
| 246 | m_ParserFunctions[Layer_MaximumLayer] = &DeserializerImpl::ParseMaximum; |
| 247 | m_ParserFunctions[Layer_MeanLayer] = &DeserializerImpl::ParseMean; |
| 248 | m_ParserFunctions[Layer_MinimumLayer] = &DeserializerImpl::ParseMinimum; |
| 249 | m_ParserFunctions[Layer_MergeLayer] = &DeserializerImpl::ParseMerge; |
| 250 | m_ParserFunctions[Layer_MergerLayer] = &DeserializerImpl::ParseConcat; |
| 251 | m_ParserFunctions[Layer_MultiplicationLayer] = &DeserializerImpl::ParseMultiplication; |
| 252 | m_ParserFunctions[Layer_NormalizationLayer] = &DeserializerImpl::ParseNormalization; |
| 253 | m_ParserFunctions[Layer_PadLayer] = &DeserializerImpl::ParsePad; |
| 254 | m_ParserFunctions[Layer_PermuteLayer] = &DeserializerImpl::ParsePermute; |
| 255 | m_ParserFunctions[Layer_Pooling2dLayer] = &DeserializerImpl::ParsePooling2d; |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 256 | m_ParserFunctions[Layer_Pooling3dLayer] = &DeserializerImpl::ParsePooling3d; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 257 | m_ParserFunctions[Layer_PreluLayer] = &DeserializerImpl::ParsePrelu; |
| 258 | m_ParserFunctions[Layer_QLstmLayer] = &DeserializerImpl::ParseQLstm; |
| 259 | m_ParserFunctions[Layer_QuantizeLayer] = &DeserializerImpl::ParseQuantize; |
| 260 | m_ParserFunctions[Layer_QuantizedLstmLayer] = &DeserializerImpl::ParseQuantizedLstm; |
| 261 | m_ParserFunctions[Layer_RankLayer] = &DeserializerImpl::ParseRank; |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 262 | m_ParserFunctions[Layer_ReduceLayer] = &DeserializerImpl::ParseReduce; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 263 | m_ParserFunctions[Layer_ReshapeLayer] = &DeserializerImpl::ParseReshape; |
| 264 | m_ParserFunctions[Layer_ResizeBilinearLayer] = &DeserializerImpl::ParseResizeBilinear; |
| 265 | m_ParserFunctions[Layer_ResizeLayer] = &DeserializerImpl::ParseResize; |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 266 | m_ParserFunctions[Layer_ReverseV2Layer] = &DeserializerImpl::ParseReverseV2; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 267 | m_ParserFunctions[Layer_RsqrtLayer] = &DeserializerImpl::ParseRsqrt; |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 268 | m_ParserFunctions[Layer_ShapeLayer] = &DeserializerImpl::ParseShape; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 269 | m_ParserFunctions[Layer_SliceLayer] = &DeserializerImpl::ParseSlice; |
| 270 | m_ParserFunctions[Layer_SoftmaxLayer] = &DeserializerImpl::ParseSoftmax; |
| 271 | m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &DeserializerImpl::ParseSpaceToBatchNd; |
| 272 | m_ParserFunctions[Layer_SpaceToDepthLayer] = &DeserializerImpl::ParseSpaceToDepth; |
| 273 | m_ParserFunctions[Layer_SplitterLayer] = &DeserializerImpl::ParseSplitter; |
| 274 | m_ParserFunctions[Layer_StackLayer] = &DeserializerImpl::ParseStack; |
| 275 | m_ParserFunctions[Layer_StandInLayer] = &DeserializerImpl::ParseStandIn; |
| 276 | m_ParserFunctions[Layer_StridedSliceLayer] = &DeserializerImpl::ParseStridedSlice; |
| 277 | m_ParserFunctions[Layer_SubtractionLayer] = &DeserializerImpl::ParseSubtraction; |
| 278 | m_ParserFunctions[Layer_SwitchLayer] = &DeserializerImpl::ParseSwitch; |
David Monahan | 616b22f | 2023-07-25 12:08:10 +0100 | [diff] [blame] | 279 | m_ParserFunctions[Layer_TileLayer] = &DeserializerImpl::ParseTile; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 280 | m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &DeserializerImpl::ParseTransposeConvolution2d; |
| 281 | m_ParserFunctions[Layer_TransposeLayer] = &DeserializerImpl::ParseTranspose; |
Narumol Prangnawarat | a0162e1 | 2021-07-23 14:47:49 +0100 | [diff] [blame] | 282 | m_ParserFunctions[Layer_UnidirectionalSequenceLstmLayer] = &DeserializerImpl::ParseUnidirectionalSequenceLstm; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 285 | LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& graphPtr, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 286 | { |
| 287 | auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type(); |
| 288 | |
| 289 | switch(layerType) |
| 290 | { |
FinnWilliamsArm | 4ffcc8f | 2019-09-05 14:34:20 +0100 | [diff] [blame] | 291 | case Layer::Layer_AbsLayer: |
| 292 | return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base(); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 293 | case Layer::Layer_ActivationLayer: |
| 294 | return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 295 | case Layer::Layer_AdditionLayer: |
| 296 | return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base(); |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 297 | case Layer::Layer_ArgMinMaxLayer: |
| 298 | return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base(); |
Samuel Yap | a04f4a1 | 2022-08-19 11:14:38 +0100 | [diff] [blame] | 299 | case Layer::Layer_BatchMatMulLayer: |
| 300 | return graphPtr->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer()->base(); |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 301 | case Layer::Layer_BatchToSpaceNdLayer: |
| 302 | return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base(); |
ruoyan01 | 8e7fa23 | 2019-02-28 15:09:07 +0000 | [diff] [blame] | 303 | case Layer::Layer_BatchNormalizationLayer: |
| 304 | return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base(); |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 305 | case Layer::Layer_CastLayer: |
| 306 | return graphPtr->layers()->Get(layerIndex)->layer_as_CastLayer()->base(); |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 307 | case Layer::Layer_ChannelShuffleLayer: |
| 308 | return graphPtr->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->base(); |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 309 | case Layer::Layer_ComparisonLayer: |
| 310 | return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base(); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 311 | case Layer::Layer_ConcatLayer: |
| 312 | return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base(); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 313 | case Layer::Layer_ConstantLayer: |
| 314 | return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base(); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 315 | case Layer::Layer_Convolution2dLayer: |
| 316 | return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base(); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 317 | case Layer::Layer_Convolution3dLayer: |
| 318 | return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution3dLayer()->base(); |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 319 | case Layer::Layer_DepthToSpaceLayer: |
| 320 | return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base(); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 321 | case Layer::Layer_DepthwiseConvolution2dLayer: |
| 322 | return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base(); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 323 | case Layer::Layer_DequantizeLayer: |
| 324 | return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base(); |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 325 | case Layer::Layer_DetectionPostProcessLayer: |
| 326 | return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base(); |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 327 | case Layer::Layer_DivisionLayer: |
| 328 | return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base(); |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 329 | case Layer::Layer_EqualLayer: |
| 330 | return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base(); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 331 | case Layer::Layer_ElementwiseBinaryLayer: |
| 332 | return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer()->base(); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 333 | case Layer::Layer_ElementwiseUnaryLayer: |
| 334 | return graphPtr->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer()->base(); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 335 | case Layer::Layer_FullyConnectedLayer: |
| 336 | return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base(); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 337 | case Layer::Layer_FillLayer: |
| 338 | return graphPtr->layers()->Get(layerIndex)->layer_as_FillLayer()->base(); |
Finn Williams | dd2ba7e | 2019-03-01 11:51:52 +0000 | [diff] [blame] | 339 | case Layer::Layer_FloorLayer: |
| 340 | return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base(); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 341 | case Layer::Layer_GatherLayer: |
| 342 | return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base(); |
Teresa Charlin | 6966bfa | 2022-04-25 17:14:50 +0100 | [diff] [blame] | 343 | case Layer::Layer_GatherNdLayer: |
| 344 | return graphPtr->layers()->Get(layerIndex)->layer_as_GatherNdLayer()->base(); |
Conor Kennedy | 79ffdf5 | 2019-03-01 14:24:54 +0000 | [diff] [blame] | 345 | case Layer::Layer_GreaterLayer: |
| 346 | return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 347 | case Layer::Layer_InputLayer: |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 348 | return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base(); |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 349 | case Layer::Layer_InstanceNormalizationLayer: |
| 350 | return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base(); |
Narumol Prangnawarat | 495701f | 2019-03-07 17:31:34 +0000 | [diff] [blame] | 351 | case Layer::Layer_L2NormalizationLayer: |
| 352 | return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base(); |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 353 | case Layer::Layer_LogicalBinaryLayer: |
| 354 | return graphPtr->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer()->base(); |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 355 | case Layer::Layer_LogSoftmaxLayer: |
| 356 | return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base(); |
Jim Flynn | 11af375 | 2019-03-19 17:22:29 +0000 | [diff] [blame] | 357 | case Layer::Layer_LstmLayer: |
| 358 | return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base(); |
Sadik Armagan | ac97c8c | 2019-03-04 17:44:21 +0000 | [diff] [blame] | 359 | case Layer::Layer_MeanLayer: |
| 360 | return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base(); |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 361 | case Layer::Layer_MinimumLayer: |
| 362 | return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base(); |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame] | 363 | case Layer::Layer_MaximumLayer: |
| 364 | return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base(); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 365 | case Layer::Layer_MergeLayer: |
| 366 | return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base(); |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 367 | case Layer::Layer_MergerLayer: |
| 368 | return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base(); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 369 | case Layer::Layer_MultiplicationLayer: |
| 370 | return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base(); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 371 | case Layer::Layer_NormalizationLayer: |
| 372 | return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 373 | case Layer::Layer_OutputLayer: |
| 374 | return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base(); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 375 | case Layer::Layer_PadLayer: |
| 376 | return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base(); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 377 | case Layer::Layer_PermuteLayer: |
| 378 | return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base(); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 379 | case Layer::Layer_Pooling2dLayer: |
| 380 | return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base(); |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 381 | case Layer::Layer_Pooling3dLayer: |
| 382 | return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base(); |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 383 | case Layer::Layer_PreluLayer: |
| 384 | return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base(); |
James Conroy | 8d33318 | 2020-05-13 10:27:58 +0100 | [diff] [blame] | 385 | case Layer::Layer_QLstmLayer: |
| 386 | return graphPtr->layers()->Get(layerIndex)->layer_as_QLstmLayer()->base(); |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 387 | case Layer::Layer_QuantizeLayer: |
| 388 | return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base(); |
Jan Eilers | 5b01a89 | 2019-07-23 09:47:43 +0100 | [diff] [blame] | 389 | case Layer::Layer_QuantizedLstmLayer: |
| 390 | return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base(); |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 391 | case Layer::Layer_RankLayer: |
| 392 | return graphPtr->layers()->Get(layerIndex)->layer_as_RankLayer()->base(); |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 393 | case Layer::Layer_ReduceLayer: |
| 394 | return graphPtr->layers()->Get(layerIndex)->layer_as_ReduceLayer()->base(); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 395 | case Layer::Layer_ReshapeLayer: |
| 396 | return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base(); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 397 | case Layer::Layer_ResizeBilinearLayer: |
| 398 | return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base(); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 399 | case Layer::Layer_ResizeLayer: |
| 400 | return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base(); |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 401 | case Layer::Layer_ReverseV2Layer: |
| 402 | return graphPtr->layers()->Get(layerIndex)->layer_as_ReverseV2Layer()->base(); |
Sadik Armagan | 8b42a38 | 2019-03-01 14:24:49 +0000 | [diff] [blame] | 403 | case Layer::Layer_RsqrtLayer: |
| 404 | return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base(); |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 405 | case Layer::Layer_ShapeLayer: |
| 406 | return graphPtr->layers()->Get(layerIndex)->layer_as_ShapeLayer()->base(); |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 407 | case Layer::Layer_SliceLayer: |
| 408 | return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base(); |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 409 | case Layer::Layer_SoftmaxLayer: |
| 410 | return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base(); |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 411 | case Layer::Layer_SpaceToBatchNdLayer: |
| 412 | return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base(); |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 413 | case Layer::Layer_SpaceToDepthLayer: |
| 414 | return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base(); |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 415 | case Layer::Layer_SplitterLayer: |
| 416 | return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base(); |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 417 | case Layer::Layer_StackLayer: |
| 418 | return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base(); |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 419 | case Layer::Layer_StandInLayer: |
| 420 | return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base(); |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 421 | case Layer::Layer_StridedSliceLayer: |
| 422 | return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base(); |
Conor Kennedy | da1f975 | 2019-03-01 14:37:12 +0000 | [diff] [blame] | 423 | case Layer::Layer_SubtractionLayer: |
| 424 | return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base(); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 425 | case Layer::Layer_SwitchLayer: |
| 426 | return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base(); |
David Monahan | 616b22f | 2023-07-25 12:08:10 +0100 | [diff] [blame] | 427 | case Layer::Layer_TileLayer: |
| 428 | return graphPtr->layers()->Get(layerIndex)->layer_as_TileLayer()->base(); |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 429 | case Layer::Layer_TransposeConvolution2dLayer: |
| 430 | return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base(); |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 431 | case Layer::Layer_TransposeLayer: |
| 432 | return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeLayer()->base(); |
Narumol Prangnawarat | a0162e1 | 2021-07-23 14:47:49 +0100 | [diff] [blame] | 433 | case Layer::Layer_UnidirectionalSequenceLstmLayer: |
| 434 | return graphPtr->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer()->base(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 435 | case Layer::Layer_NONE: |
| 436 | default: |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 437 | throw ParseException(fmt::format("Layer type {} not recognized", layerType)); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 441 | std::string IDeserializer::DeserializerImpl::GetLayerName(const GraphPtr& graph, unsigned int index) |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 442 | { |
| 443 | auto layer = GetBaseLayer(graph, index); |
| 444 | assert(layer); |
| 445 | return layer->layerName()->str(); |
| 446 | } |
| 447 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 448 | int32_t IDeserializer::DeserializerImpl::GetBindingLayerInfo(const GraphPtr& graphPtr, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 449 | { |
| 450 | auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type(); |
| 451 | |
| 452 | if (layerType == Layer::Layer_InputLayer) |
| 453 | { |
| 454 | return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId(); |
| 455 | } |
| 456 | else if ( layerType == Layer::Layer_OutputLayer ) |
| 457 | { |
| 458 | return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId(); |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 463 | armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout) |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 464 | { |
| 465 | switch (dataLayout) |
| 466 | { |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 467 | case armnnSerializer::DataLayout::DataLayout_NHWC: |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 468 | return armnn::DataLayout::NHWC; |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 469 | case armnnSerializer::DataLayout::DataLayout_NDHWC: |
| 470 | return armnn::DataLayout::NDHWC; |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 471 | case armnnSerializer::DataLayout::DataLayout_NCDHW: |
| 472 | return armnn::DataLayout::NCDHW; |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 473 | case armnnSerializer::DataLayout::DataLayout_NCHW: |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 474 | default: |
| 475 | return armnn::DataLayout::NCHW; |
| 476 | } |
| 477 | } |
| 478 | |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 479 | armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function) |
| 480 | { |
| 481 | switch (function) |
| 482 | { |
| 483 | case armnnSerializer::ActivationFunction_Sigmoid: |
| 484 | return armnn::ActivationFunction::Sigmoid; |
| 485 | case armnnSerializer::ActivationFunction_TanH: |
| 486 | return armnn::ActivationFunction::TanH; |
| 487 | case armnnSerializer::ActivationFunction_Linear: |
| 488 | return armnn::ActivationFunction::Linear; |
| 489 | case armnnSerializer::ActivationFunction_ReLu: |
| 490 | return armnn::ActivationFunction::ReLu; |
| 491 | case armnnSerializer::ActivationFunction_BoundedReLu: |
| 492 | return armnn::ActivationFunction::BoundedReLu; |
| 493 | case armnnSerializer::ActivationFunction_LeakyReLu: |
| 494 | return armnn::ActivationFunction::LeakyReLu; |
| 495 | case armnnSerializer::ActivationFunction_Abs: |
| 496 | return armnn::ActivationFunction::Abs; |
| 497 | case armnnSerializer::ActivationFunction_Sqrt: |
| 498 | return armnn::ActivationFunction::Sqrt; |
| 499 | case armnnSerializer::ActivationFunction_Square: |
| 500 | return armnn::ActivationFunction::Square; |
David Monahan | 3b3c381 | 2020-02-25 09:03:29 +0000 | [diff] [blame] | 501 | case armnnSerializer::ActivationFunction_Elu: |
| 502 | return armnn::ActivationFunction::Elu; |
Colm Donelan | 03fbeaf | 2020-02-26 15:39:23 +0000 | [diff] [blame] | 503 | case armnnSerializer::ActivationFunction_HardSwish: |
| 504 | return armnn::ActivationFunction::HardSwish; |
Teresa Charlin | 077cddb | 2023-09-15 15:19:21 +0100 | [diff] [blame] | 505 | case armnnSerializer::ActivationFunction_Gelu: |
| 506 | return armnn::ActivationFunction::Gelu; |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 507 | default: |
| 508 | return armnn::ActivationFunction::Sigmoid; |
| 509 | } |
| 510 | } |
| 511 | |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 512 | armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction function) |
| 513 | { |
| 514 | switch (function) |
| 515 | { |
| 516 | case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max: |
| 517 | return armnn::ArgMinMaxFunction::Max; |
| 518 | case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min: |
| 519 | default: |
| 520 | return armnn::ArgMinMaxFunction::Min; |
| 521 | } |
| 522 | } |
| 523 | |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 524 | armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation) |
| 525 | { |
| 526 | switch (operation) |
| 527 | { |
| 528 | case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal: |
| 529 | return armnn::ComparisonOperation::Equal; |
| 530 | case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater: |
| 531 | return armnn::ComparisonOperation::Greater; |
| 532 | case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual: |
| 533 | return armnn::ComparisonOperation::GreaterOrEqual; |
| 534 | case armnnSerializer::ComparisonOperation::ComparisonOperation_Less: |
| 535 | return armnn::ComparisonOperation::Less; |
| 536 | case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual: |
| 537 | return armnn::ComparisonOperation::LessOrEqual; |
| 538 | case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual: |
| 539 | default: |
| 540 | return armnn::ComparisonOperation::NotEqual; |
| 541 | } |
| 542 | } |
| 543 | |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 544 | armnn::ReduceOperation ToReduceOperation(armnnSerializer::ReduceOperation operation) |
| 545 | { |
| 546 | switch (operation) |
| 547 | { |
| 548 | case armnnSerializer::ReduceOperation::ReduceOperation_Sum: |
| 549 | return armnn::ReduceOperation::Sum; |
| 550 | case armnnSerializer::ReduceOperation::ReduceOperation_Max: |
| 551 | return armnn::ReduceOperation::Max; |
| 552 | case armnnSerializer::ReduceOperation::ReduceOperation_Mean: |
| 553 | return armnn::ReduceOperation::Mean; |
| 554 | case armnnSerializer::ReduceOperation::ReduceOperation_Min: |
| 555 | return armnn::ReduceOperation::Min; |
Teresa Charlin | 4e3e831 | 2021-08-05 12:34:37 +0100 | [diff] [blame] | 556 | case armnnSerializer::ReduceOperation::ReduceOperation_Prod: |
| 557 | return armnn::ReduceOperation::Prod; |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 558 | default: |
| 559 | return armnn::ReduceOperation::Sum; |
| 560 | } |
| 561 | } |
| 562 | |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 563 | armnn::LogicalBinaryOperation ToLogicalBinaryOperation(armnnSerializer::LogicalBinaryOperation operation) |
| 564 | { |
| 565 | switch (operation) |
| 566 | { |
| 567 | case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalAnd: |
| 568 | return armnn::LogicalBinaryOperation::LogicalAnd; |
| 569 | case armnnSerializer::LogicalBinaryOperation::LogicalBinaryOperation_LogicalOr: |
| 570 | return armnn::LogicalBinaryOperation::LogicalOr; |
| 571 | default: |
| 572 | throw armnn::InvalidArgumentException("Logical Binary operation unknown"); |
| 573 | } |
| 574 | } |
| 575 | |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 576 | armnn::BinaryOperation ToElementwiseBinaryOperation(armnnSerializer::BinaryOperation operation) |
| 577 | { |
| 578 | switch (operation) |
| 579 | { |
| 580 | case armnnSerializer::BinaryOperation::BinaryOperation_Add: |
| 581 | return armnn::BinaryOperation::Add; |
| 582 | case armnnSerializer::BinaryOperation::BinaryOperation_Div: |
| 583 | return armnn::BinaryOperation::Div; |
| 584 | case armnnSerializer::BinaryOperation::BinaryOperation_Maximum: |
| 585 | return armnn::BinaryOperation::Maximum; |
| 586 | case armnnSerializer::BinaryOperation::BinaryOperation_Minimum: |
| 587 | return armnn::BinaryOperation::Minimum; |
| 588 | case armnnSerializer::BinaryOperation::BinaryOperation_Mul: |
| 589 | return armnn::BinaryOperation::Mul; |
| 590 | case armnnSerializer::BinaryOperation::BinaryOperation_Sub: |
| 591 | return armnn::BinaryOperation::Sub; |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 592 | case armnnSerializer::BinaryOperation::BinaryOperation_SqDiff: |
| 593 | return armnn::BinaryOperation::SqDiff; |
| 594 | case armnnSerializer::BinaryOperation::BinaryOperation_Power: |
| 595 | return armnn::BinaryOperation::Power; |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 596 | default: |
| 597 | throw armnn::InvalidArgumentException("Binary operation unknown"); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | armnn::UnaryOperation ToElementwiseUnaryOperation(armnnSerializer::UnaryOperation operation) |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 602 | { |
| 603 | switch (operation) |
| 604 | { |
| 605 | case armnnSerializer::UnaryOperation::UnaryOperation_Abs: |
| 606 | return armnn::UnaryOperation::Abs; |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 607 | case armnnSerializer::UnaryOperation::UnaryOperation_Ceil: |
| 608 | return armnn::UnaryOperation::Ceil; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 609 | case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt: |
| 610 | return armnn::UnaryOperation::Rsqrt; |
| 611 | case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt: |
| 612 | return armnn::UnaryOperation::Sqrt; |
| 613 | case armnnSerializer::UnaryOperation::UnaryOperation_Exp: |
| 614 | return armnn::UnaryOperation::Exp; |
| 615 | case armnnSerializer::UnaryOperation::UnaryOperation_Neg: |
| 616 | return armnn::UnaryOperation::Neg; |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 617 | case armnnSerializer::UnaryOperation::UnaryOperation_LogicalNot: |
| 618 | return armnn::UnaryOperation::LogicalNot; |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 619 | case armnnSerializer::UnaryOperation::UnaryOperation_Log: |
| 620 | return armnn::UnaryOperation::Log; |
| 621 | case armnnSerializer::UnaryOperation::UnaryOperation_Sin: |
| 622 | return armnn::UnaryOperation::Sin; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 623 | default: |
| 624 | throw armnn::InvalidArgumentException("Unary operation unknown"); |
| 625 | } |
| 626 | } |
| 627 | |
Matthew Sloyan | 2e5d0b2 | 2021-10-21 14:05:31 +0100 | [diff] [blame] | 628 | armnn::PaddingMode ToPaddingMode(armnnSerializer::PaddingMode paddingMode) |
| 629 | { |
| 630 | switch (paddingMode) |
| 631 | { |
| 632 | case armnnSerializer::PaddingMode::PaddingMode_Reflect: |
| 633 | return armnn::PaddingMode::Reflect; |
| 634 | case armnnSerializer::PaddingMode::PaddingMode_Symmetric: |
| 635 | return armnn::PaddingMode::Symmetric; |
| 636 | default: |
| 637 | return armnn::PaddingMode::Constant; |
| 638 | } |
| 639 | } |
| 640 | |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 641 | armnn::ResizeMethod ToResizeMethod(armnnSerializer::ResizeMethod method) |
| 642 | { |
| 643 | switch (method) |
| 644 | { |
| 645 | case armnnSerializer::ResizeMethod_NearestNeighbor: |
| 646 | return armnn::ResizeMethod::NearestNeighbor; |
| 647 | case armnnSerializer::ResizeMethod_Bilinear: |
Aron Virginas-Tar | 3c9b270 | 2019-10-31 13:45:16 +0000 | [diff] [blame] | 648 | return armnn::ResizeMethod::Bilinear; |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 649 | default: |
| 650 | return armnn::ResizeMethod::NearestNeighbor; |
| 651 | } |
| 652 | } |
| 653 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 654 | armnn::TensorInfo ToTensorInfo(TensorRawPtr tensorPtr) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 655 | { |
| 656 | armnn::DataType type; |
| 657 | CHECK_TENSOR_PTR(tensorPtr); |
| 658 | |
| 659 | switch (tensorPtr->dataType()) |
| 660 | { |
Francis Murtagh | ddb1d06 | 2020-03-10 13:51:45 +0000 | [diff] [blame] | 661 | case DataType_QAsymmS8: |
| 662 | type = armnn::DataType::QAsymmS8; |
| 663 | break; |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 664 | case DataType_QSymmS8: |
| 665 | type = armnn::DataType::QSymmS8; |
| 666 | break; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 667 | case DataType_QuantisedAsymm8: |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 668 | case DataType_QAsymmU8: |
| 669 | type = armnn::DataType::QAsymmU8; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 670 | break; |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 671 | case DataType_QSymmS16: |
Nattapat Chaimanowong | cd5ac23 | 2019-03-19 12:26:36 +0000 | [diff] [blame] | 672 | case DataType_QuantisedSymm16: |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 673 | type = armnn::DataType::QSymmS16; |
Nattapat Chaimanowong | cd5ac23 | 2019-03-19 12:26:36 +0000 | [diff] [blame] | 674 | break; |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 675 | case DataType_Signed32: |
| 676 | type = armnn::DataType::Signed32; |
| 677 | break; |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 678 | case DataType_Signed64: |
| 679 | type = armnn::DataType::Signed64; |
| 680 | break; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 681 | case DataType_Float32: |
| 682 | type = armnn::DataType::Float32; |
| 683 | break; |
| 684 | case DataType_Float16: |
| 685 | type = armnn::DataType::Float16; |
| 686 | break; |
| 687 | case DataType_Boolean: |
| 688 | type = armnn::DataType::Boolean; |
| 689 | break; |
| 690 | default: |
| 691 | { |
| 692 | CheckLocation location = CHECK_LOCATION(); |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 693 | throw ParseException(fmt::format("Unsupported data type {0} = {1}. {2}", |
| 694 | tensorPtr->dataType(), |
| 695 | EnumNameDataType(tensorPtr->dataType()), |
| 696 | location.AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 697 | } |
| 698 | } |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 699 | |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 700 | float quantizationScale = tensorPtr->quantizationScale(); |
| 701 | int32_t quantizationOffset = tensorPtr->quantizationOffset(); |
| 702 | |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 703 | if (tensorPtr->dimensionality() == static_cast<unsigned int>(Dimensionality::Scalar)) |
| 704 | { |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 705 | return armnn::TensorInfo(TensorShape{armnn::Dimensionality::Scalar}, |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 706 | type, |
| 707 | quantizationScale, |
| 708 | quantizationOffset); |
| 709 | } |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 710 | else if (tensorPtr->dimensionality() == static_cast<unsigned int>(Dimensionality::NotSpecified)) |
| 711 | { |
| 712 | armnn::TensorInfo result(TensorShape{Dimensionality::NotSpecified}, |
| 713 | type, |
| 714 | quantizationScale, |
| 715 | quantizationOffset); |
| 716 | return result; |
| 717 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 718 | |
| 719 | auto dimensions = tensorPtr->dimensions(); |
| 720 | unsigned int size = dimensions->size(); |
| 721 | std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size); |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 722 | bool dimensionsSpecificity[armnn::MaxNumOfTensorDimensions]; |
| 723 | std::fill_n(dimensionsSpecificity, armnn::MaxNumOfTensorDimensions, true); |
| 724 | // For backwards compatibility check if the dimensionSpecificity vector is present first. |
| 725 | // The default is to have dimensionSpecificity set to all true's anyway. |
| 726 | if (tensorPtr->dimensionSpecificity() != nullptr) |
| 727 | { |
| 728 | auto dimensionSpecificity = tensorPtr->dimensionSpecificity(); |
| 729 | size = dimensionSpecificity->size(); |
| 730 | for (unsigned int i = 0; i < size; ++i) |
| 731 | { |
| 732 | dimensionsSpecificity[i] = dimensionSpecificity->Get(i); |
| 733 | } |
| 734 | } |
| 735 | // Construct a TensorShape |
| 736 | TensorShape shape(size, outputDims.data(), dimensionsSpecificity); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 737 | |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 738 | auto quantizationScales = tensorPtr->quantizationScales(); |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 739 | if (quantizationScales) |
| 740 | { |
| 741 | unsigned int quantizationScalesSize = quantizationScales->size(); |
| 742 | std::vector<float> scales(quantizationScales->begin(), quantizationScales->begin() + quantizationScalesSize); |
| 743 | unsigned int quantizationDim = tensorPtr->quantizationDim(); |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 744 | armnn::TensorInfo result(shape, |
Sadik Armagan | 1a84fe3 | 2020-03-27 15:56:57 +0000 | [diff] [blame] | 745 | type, |
| 746 | scales, |
| 747 | quantizationDim); |
| 748 | return result; |
| 749 | } |
| 750 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 751 | // two statements (on purpose) for easier debugging: |
Colm Donelan | 800b281 | 2021-02-12 12:43:35 +0000 | [diff] [blame] | 752 | armnn::TensorInfo result(shape, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 753 | type, |
| 754 | quantizationScale, |
| 755 | quantizationOffset); |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 756 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 757 | return result; |
| 758 | } |
| 759 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 760 | armnn::ConstTensor ToConstTensor(ConstTensorRawPtr constTensorPtr) |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 761 | { |
| 762 | CHECK_CONST_TENSOR_PTR(constTensorPtr); |
| 763 | armnn::TensorInfo tensorInfo = ToTensorInfo(constTensorPtr->info()); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 764 | tensorInfo.SetConstant(); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 765 | |
| 766 | switch (constTensorPtr->data_type()) |
| 767 | { |
| 768 | case ConstTensorData_ByteData: |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 769 | { |
| 770 | auto byteData = constTensorPtr->data_as_ByteData()->data(); |
| 771 | CHECK_CONST_TENSOR_SIZE(byteData->size(), tensorInfo.GetNumElements()); |
| 772 | return armnn::ConstTensor(tensorInfo, byteData->data()); |
| 773 | } |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 774 | case ConstTensorData_ShortData: |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 775 | { |
| 776 | auto shortData = constTensorPtr->data_as_ShortData()->data(); |
| 777 | CHECK_CONST_TENSOR_SIZE(shortData->size(), tensorInfo.GetNumElements()); |
| 778 | return armnn::ConstTensor(tensorInfo, shortData->data()); |
| 779 | } |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 780 | case ConstTensorData_IntData: |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 781 | { |
| 782 | auto intData = constTensorPtr->data_as_IntData()->data(); |
| 783 | CHECK_CONST_TENSOR_SIZE(intData->size(), tensorInfo.GetNumElements()); |
| 784 | return armnn::ConstTensor(tensorInfo, intData->data()); |
| 785 | } |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 786 | case ConstTensorData_LongData: |
Saoirse Stewart | f11bab5 | 2019-02-25 09:22:58 +0000 | [diff] [blame] | 787 | { |
| 788 | auto longData = constTensorPtr->data_as_LongData()->data(); |
| 789 | CHECK_CONST_TENSOR_SIZE(longData->size(), tensorInfo.GetNumElements()); |
| 790 | return armnn::ConstTensor(tensorInfo, longData->data()); |
| 791 | } |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 792 | default: |
| 793 | { |
| 794 | CheckLocation location = CHECK_LOCATION(); |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 795 | throw ParseException(fmt::format("Unsupported data type {0} = {1}. {2}", |
| 796 | constTensorPtr->data_type(), |
| 797 | EnumNameConstTensorData(constTensorPtr->data_type()), |
| 798 | location.AsString())); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | } |
| 802 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 803 | TensorRawPtrVector IDeserializer::DeserializerImpl::GetInputs(const GraphPtr& graphPtr, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 804 | { |
| 805 | CHECK_LAYERS(graphPtr, 0, layerIndex); |
| 806 | auto layer = GetBaseLayer(graphPtr, layerIndex); |
| 807 | const auto& numInputs = layer->inputSlots()->size(); |
| 808 | |
| 809 | TensorRawPtrVector result(numInputs); |
| 810 | |
| 811 | for (unsigned int i=0; i<numInputs; ++i) |
| 812 | { |
| 813 | auto inputId = CHECKED_NON_NEGATIVE(static_cast<int32_t> |
| 814 | (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex())); |
| 815 | result[i] = GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo(); |
| 816 | } |
| 817 | return result; |
| 818 | } |
| 819 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 820 | TensorRawPtrVector IDeserializer::DeserializerImpl::GetOutputs(const GraphPtr& graphPtr, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 821 | { |
| 822 | CHECK_LAYERS(graphPtr, 0, layerIndex); |
| 823 | auto layer = GetBaseLayer(graphPtr, layerIndex); |
| 824 | const auto& numOutputs = layer->outputSlots()->size(); |
| 825 | |
| 826 | TensorRawPtrVector result(numOutputs); |
| 827 | |
| 828 | for (unsigned int i=0; i<numOutputs; ++i) |
| 829 | { |
| 830 | result[i] = layer->outputSlots()->Get(i)->tensorInfo(); |
| 831 | } |
| 832 | return result; |
| 833 | } |
| 834 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 835 | void IDeserializer::DeserializerImpl::ParseUnsupportedLayer(GraphPtr graph, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 836 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 837 | CHECK_LAYERS(graph, 0, layerIndex); |
| 838 | const auto layerName = GetBaseLayer(graph, layerIndex)->layerName()->c_str(); |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 839 | throw ParseException(fmt::format("Layer not supported. layerIndex: {0} " |
| 840 | "layerName: {1} / {2}", |
| 841 | layerIndex, |
| 842 | layerName, |
| 843 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 846 | void IDeserializer::DeserializerImpl::ResetParser() |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 847 | { |
| 848 | m_Network = armnn::INetworkPtr(nullptr, nullptr); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 849 | m_InputBindings.clear(); |
| 850 | m_OutputBindings.clear(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 853 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 854 | INetworkPtr IDeserializer::DeserializerImpl::CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 855 | { |
| 856 | ResetParser(); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 857 | GraphPtr graph = LoadGraphFromBinary(binaryContent.data(), binaryContent.size()); |
| 858 | return CreateNetworkFromGraph(graph); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 861 | armnn::INetworkPtr IDeserializer::DeserializerImpl::CreateNetworkFromBinary(std::istream& binaryContent) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 862 | { |
Derek Lamberti | 2b183fb | 2019-02-18 16:36:57 +0000 | [diff] [blame] | 863 | ResetParser(); |
Simon Obute | db5804e | 2022-04-14 15:49:52 +0100 | [diff] [blame] | 864 | if (binaryContent.fail()) { |
| 865 | ARMNN_LOG(error) << (std::string("Cannot read input")); |
| 866 | throw ParseException("Unable to read Input stream data"); |
| 867 | } |
| 868 | binaryContent.seekg(0, std::ios::end); |
| 869 | const std::streamoff size = binaryContent.tellg(); |
| 870 | std::vector<char> content(static_cast<size_t>(size)); |
| 871 | binaryContent.seekg(0); |
| 872 | binaryContent.read(content.data(), static_cast<std::streamsize>(size)); |
| 873 | GraphPtr graph = LoadGraphFromBinary(reinterpret_cast<uint8_t*>(content.data()), static_cast<size_t>(size)); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 874 | return CreateNetworkFromGraph(graph); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 877 | GraphPtr IDeserializer::DeserializerImpl::LoadGraphFromBinary(const uint8_t* binaryContent, size_t len) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 878 | { |
| 879 | if (binaryContent == nullptr) |
| 880 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 881 | throw InvalidArgumentException(fmt::format("Invalid (null) binary content {}", |
| 882 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 883 | } |
| 884 | flatbuffers::Verifier verifier(binaryContent, len); |
| 885 | if (verifier.VerifyBuffer<SerializedGraph>() == false) |
| 886 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 887 | throw ParseException(fmt::format("Buffer doesn't conform to the expected Armnn " |
| 888 | "flatbuffers format. size:{0} {1}", |
| 889 | len, |
| 890 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 891 | } |
| 892 | return GetSerializedGraph(binaryContent); |
| 893 | } |
| 894 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 895 | INetworkPtr IDeserializer::DeserializerImpl::CreateNetworkFromGraph(GraphPtr graph) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 896 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 897 | if (graph == nullptr) |
| 898 | { |
| 899 | throw armnn::InvalidArgumentException("CreateNetworkFromGraph: graph pointer is null"); |
| 900 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 901 | m_Network = INetwork::Create(); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 902 | unsigned int layerIndex = 0; |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 903 | for (AnyLayer const* layer : *graph->layers()) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 904 | { |
| 905 | if (layer->layer_type() != Layer_InputLayer && |
| 906 | layer->layer_type() != Layer_OutputLayer) |
| 907 | { |
| 908 | // lookup and call the parser function |
| 909 | auto& parserFunction = m_ParserFunctions[layer->layer_type()]; |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 910 | (this->*parserFunction)(graph, layerIndex); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 911 | } |
| 912 | ++layerIndex; |
| 913 | } |
| 914 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 915 | SetupInputLayers(graph); |
| 916 | SetupOutputLayers(graph); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 917 | |
| 918 | // establish the connections from the layer outputs to the inputs of the subsequent layers |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 919 | for (auto&& graphIt : m_GraphConnections) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 920 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 921 | Connections& connections = graphIt.second; |
| 922 | for (auto&& outputIt : connections.outputSlots) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 923 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 924 | const unsigned int outputSlotIndex = outputIt.first; |
| 925 | IOutputSlot* outputSlot = outputIt.second; |
| 926 | if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end()) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 927 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 928 | for (IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex]) |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 929 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 930 | outputSlot->Connect(*inputSlot); |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 931 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | return std::move(m_Network); |
| 937 | } |
| 938 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 939 | BindingPointInfo IDeserializer::DeserializerImpl::GetNetworkInputBindingInfo(unsigned int layerIndex, |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 940 | const std::string& name) const |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 941 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 942 | IgnoreUnused(layerIndex); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 943 | for (auto inputBinding : m_InputBindings) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 944 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 945 | if (inputBinding.first == name) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 946 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 947 | return inputBinding.second; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 948 | } |
| 949 | } |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 950 | throw ParseException(fmt::format("No input binding found for layer:{0} / {1}", |
| 951 | name, |
| 952 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 955 | BindingPointInfo IDeserializer::DeserializerImpl::GetNetworkOutputBindingInfo(unsigned int layerIndex, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 956 | const std::string& name) const |
| 957 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 958 | IgnoreUnused(layerIndex); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 959 | for (auto outputBinding : m_OutputBindings) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 960 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 961 | if (outputBinding.first == name) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 962 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 963 | return outputBinding.second; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 964 | } |
| 965 | } |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 966 | throw ParseException(fmt::format("No output binding found for layer:{0} / {1}", |
| 967 | name, |
| 968 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 971 | unsigned int IDeserializer::DeserializerImpl::GetInputLayerInVector(GraphPtr graph, int targetId) |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 972 | { |
| 973 | for (unsigned int i = 0; i < graph->layers()->size(); i++) |
| 974 | { |
| 975 | auto layer = graph->layers()->Get(i); |
| 976 | if (layer->layer_type() == Layer::Layer_InputLayer) |
| 977 | { |
| 978 | auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId(); |
| 979 | if (layerBindingId == targetId) |
| 980 | { |
| 981 | return i; |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | throw ParseException("Input layer with given layerBindingId not found"); |
| 986 | } |
| 987 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 988 | unsigned int IDeserializer::DeserializerImpl::GetOutputLayerInVector(GraphPtr graph, int targetId) |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 989 | { |
| 990 | for (unsigned int i = 0; i < graph->layers()->size(); i++) |
| 991 | { |
| 992 | auto layer = graph->layers()->Get(i); |
| 993 | if (layer->layer_type() == Layer::Layer_OutputLayer) |
| 994 | { |
| 995 | auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId(); |
| 996 | if (layerBindingId == targetId) |
| 997 | { |
| 998 | return i; |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | throw ParseException("Output layer with given layerBindingId not found"); |
| 1003 | } |
| 1004 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1005 | unsigned int IDeserializer::DeserializerImpl::GetLayerIndexInVector(GraphPtr graph, unsigned int targetIndex) |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1006 | { |
| 1007 | for (unsigned int i = 0; i < graph->layers()->size(); i++) |
| 1008 | { |
| 1009 | LayerBaseRawPtr layer = GetBaseLayer(graph, i); |
| 1010 | if (layer->index() == targetIndex) |
| 1011 | { |
| 1012 | return i; |
| 1013 | } |
| 1014 | } |
| 1015 | throw ParseException("Layer with given index not found"); |
| 1016 | } |
| 1017 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1018 | IDeserializer::DeserializerImpl::FeatureVersions IDeserializer::DeserializerImpl::GetFeatureVersions(GraphPtr graph) |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1019 | { |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1020 | IDeserializer::DeserializerImpl::FeatureVersions versions; |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1021 | |
| 1022 | if (graph->featureVersions()) |
| 1023 | { |
| 1024 | versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme(); |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1025 | versions.m_WeightsLayoutScheme = graph->featureVersions()->weightsLayoutScheme(); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1026 | versions.m_ConstTensorsAsInputs = graph->featureVersions()->constantTensorsAsInputs(); |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | return versions; |
| 1030 | } |
| 1031 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1032 | void IDeserializer::DeserializerImpl::SetupInputLayers(GraphPtr graph) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1033 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1034 | CHECK_GRAPH(graph, 0); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1035 | const unsigned int numInputs = graph->inputIds()->size(); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1036 | m_InputBindings.clear(); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1037 | m_InputBindings.reserve(numInputs); |
| 1038 | |
| 1039 | for (unsigned int i = 0; i < numInputs; i++) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1040 | { |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1041 | unsigned int inputLayerIndex = 0xFFFFFFFF; |
| 1042 | if (GetFeatureVersions(graph).m_BindingIdScheme == 0) |
| 1043 | { |
Matthew Sloyan | 0663d66 | 2020-09-14 11:47:26 +0100 | [diff] [blame] | 1044 | const unsigned int inputId = armnn::numeric_cast<unsigned int>(graph->inputIds()->Get(i)); |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1045 | inputLayerIndex = GetLayerIndexInVector(graph, inputId); |
| 1046 | } |
| 1047 | else |
| 1048 | { |
| 1049 | const int inputId = graph->inputIds()->Get(i); |
| 1050 | inputLayerIndex = GetInputLayerInVector(graph, inputId); |
| 1051 | } |
| 1052 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1053 | LayerBaseRawPtr baseLayer = GetBaseLayer(graph, inputLayerIndex); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1054 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1055 | // GetBindingLayerInfo expect the index to be index in the vector not index property on each layer base |
| 1056 | LayerBindingId bindingId = GetBindingLayerInfo(graph, inputLayerIndex); |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 1057 | if (baseLayer->layerName()->c_str() == nullptr) |
| 1058 | { |
| 1059 | throw ParseException(fmt::format("Input with layer index [{0}] has no name", inputLayerIndex)); |
| 1060 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1061 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1062 | IConnectableLayer* inputLayer = |
| 1063 | m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str()); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1064 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1065 | const armnn::TensorInfo& tensorInfo = ToTensorInfo(baseLayer->outputSlots()->Get(0)->tensorInfo()); |
| 1066 | inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 1067 | RegisterOutputSlots(graph, inputLayerIndex, inputLayer); |
| 1068 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1069 | BindingPointInfo bindingInfo = {bindingId, tensorInfo}; |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1070 | m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo)); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1074 | void IDeserializer::DeserializerImpl::SetupOutputLayers(GraphPtr graph) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1075 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1076 | CHECK_GRAPH(graph, 0); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1077 | const unsigned int numOutputs = graph->outputIds()->size(); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1078 | m_OutputBindings.clear(); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1079 | m_OutputBindings.reserve(numOutputs); |
| 1080 | |
| 1081 | for (unsigned int i = 0; i < numOutputs; i++) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1082 | { |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1083 | unsigned int outputLayerIndex = 0xFFFFFFFF; |
| 1084 | if (GetFeatureVersions(graph).m_BindingIdScheme == 0) |
| 1085 | { |
Matthew Sloyan | 0663d66 | 2020-09-14 11:47:26 +0100 | [diff] [blame] | 1086 | const unsigned int outputId = armnn::numeric_cast<unsigned int>(graph->outputIds()->Get(i)); |
Tee Jung | aa920c5 | 2019-11-05 10:48:25 +0000 | [diff] [blame] | 1087 | outputLayerIndex = GetLayerIndexInVector(graph, outputId); |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | const int outputId = graph->outputIds()->Get(i); |
| 1092 | outputLayerIndex = GetOutputLayerInVector(graph, outputId); |
| 1093 | } |
| 1094 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1095 | LayerBaseRawPtr baseLayer = GetBaseLayer(graph, outputLayerIndex); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1096 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1097 | // GetBindingLayerInfo expect the index to be index in the vector not index property on each layer base |
| 1098 | LayerBindingId bindingId = GetBindingLayerInfo(graph, outputLayerIndex); |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 1099 | if (baseLayer->layerName()->c_str() == nullptr) |
| 1100 | { |
| 1101 | throw ParseException(fmt::format("Output with layer index [{0}] has no name", outputLayerIndex)); |
| 1102 | } |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1103 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1104 | IConnectableLayer* outputLayer = |
| 1105 | m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str()); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1106 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1107 | RegisterInputSlots(graph, outputLayerIndex, outputLayer); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1108 | unsigned int sourceLayerIndex = |
| 1109 | GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex()); |
Colm Donelan | 30aa371 | 2021-04-07 17:28:01 +0100 | [diff] [blame] | 1110 | unsigned int outputSlotIndex = |
| 1111 | GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->outputSlotIndex()); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1112 | LayerBaseRawPtr sourceBaseLayer = GetBaseLayer(graph, sourceLayerIndex); |
Colm Donelan | 30aa371 | 2021-04-07 17:28:01 +0100 | [diff] [blame] | 1113 | const armnn::TensorInfo& tensorInfo = ToTensorInfo( |
| 1114 | sourceBaseLayer->outputSlots()->Get(outputSlotIndex)->tensorInfo()); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1115 | BindingPointInfo bindingInfo = {bindingId, tensorInfo}; |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1116 | m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo)); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1120 | void IDeserializer::DeserializerImpl::RegisterOutputSlots(GraphPtr graph, |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1121 | uint32_t layerIndex, |
| 1122 | IConnectableLayer* layer) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1123 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 1124 | if (layer == nullptr) |
| 1125 | { |
| 1126 | throw ParseException(fmt::format( |
| 1127 | "RegisterOutputSlots: pointer to layer with index [{0}] is null", layerIndex)); |
| 1128 | } |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1129 | CHECK_LAYERS(graph, 0, layerIndex); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1130 | LayerBaseRawPtr baseLayer = GetBaseLayer(graph, layerIndex); |
| 1131 | if (baseLayer->outputSlots()->size() != layer->GetNumOutputSlots()) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1132 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 1133 | throw ParseException(fmt::format("The number of outputslots ({0}) does not match the number expected ({1})" |
| 1134 | " for layer index: {2} {3}", |
| 1135 | baseLayer->outputSlots()->size(), |
| 1136 | layer->GetNumOutputSlots(), |
| 1137 | layerIndex, |
| 1138 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1141 | for (unsigned int i = 0; i < layer->GetNumOutputSlots(); ++i) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1142 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1143 | const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index(); |
| 1144 | armnn::IOutputSlot* outputSlot = &(layer->GetOutputSlot(slotIndex)); |
| 1145 | // layerIndex is not necessarily the same as baseLayer->index(). The latter is needed here |
| 1146 | RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1150 | void IDeserializer::DeserializerImpl::RegisterInputSlots(GraphPtr graph, |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1151 | uint32_t layerIndex, |
| 1152 | armnn::IConnectableLayer* layer, |
| 1153 | std::vector<unsigned int> ignoreSlots) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1154 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 1155 | if (layer == nullptr) |
| 1156 | { |
| 1157 | throw ParseException(fmt::format( |
| 1158 | "RegisterInputSlots: pointer to layer with index [{0}] is null", layerIndex)); |
| 1159 | } |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1160 | CHECK_LAYERS(graph, 0, layerIndex); |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1161 | LayerBaseRawPtr baseLayer = GetBaseLayer(graph, layerIndex); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1162 | |
| 1163 | if (baseLayer->inputSlots()->size() != (layer->GetNumInputSlots() - ignoreSlots.size())) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1164 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 1165 | throw ParseException(fmt::format("The number of inputslots ({0}) does not match the number expected ({1})" |
| 1166 | " for layer index:{2} {3}", |
| 1167 | baseLayer->inputSlots()->size(), |
| 1168 | layer->GetNumInputSlots(), |
| 1169 | layerIndex, |
| 1170 | CHECK_LOCATION().AsString())); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1173 | for (unsigned int i = 0; i < layer->GetNumInputSlots(); ++i) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1174 | { |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1175 | // Check if slot should be ignored. |
| 1176 | if (std::find(ignoreSlots.begin(), ignoreSlots.end(), i) == ignoreSlots.end()) |
| 1177 | { |
| 1178 | auto fbInputSlot = baseLayer->inputSlots()->Get(i); |
| 1179 | auto fbConnection = fbInputSlot->connection(); |
| 1180 | armnn::IInputSlot* inputSlot = &(layer->GetInputSlot(fbInputSlot->index())); |
Mike Kelly | 4cc341c | 2023-07-07 15:43:06 +0100 | [diff] [blame] | 1181 | |
| 1182 | // If the slot has an Overridden tensorInfo then extract it |
| 1183 | if (fbInputSlot->isOverridden()) |
| 1184 | { |
| 1185 | armnn::TensorInfo overriddenTensorInfo = ToTensorInfo(fbInputSlot->overriddenTensorInfo()); |
| 1186 | inputSlot->SetTensorInfo(overriddenTensorInfo); |
| 1187 | } |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 1188 | RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot); |
| 1189 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1193 | void IDeserializer::DeserializerImpl::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex, |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 1194 | uint32_t outputSlotIndex, |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1195 | armnn::IInputSlot* inputSlot) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1196 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1197 | if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end()) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1198 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1199 | m_GraphConnections[sourceLayerIndex] = Connections(); |
| 1200 | } |
| 1201 | |
| 1202 | Connections& connections = m_GraphConnections[sourceLayerIndex]; |
| 1203 | if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end()) |
| 1204 | { |
| 1205 | connections.inputSlots[outputSlotIndex] = {inputSlot}; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1206 | } |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 1207 | else |
| 1208 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1209 | connections.inputSlots[outputSlotIndex].push_back(inputSlot); |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 1210 | } |
| 1211 | } |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1212 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1213 | void IDeserializer::DeserializerImpl::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex, |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1214 | uint32_t outputSlotIndex, |
| 1215 | armnn::IOutputSlot* outputSlot) |
Nattapat Chaimanowong | d469faf | 2019-03-04 17:10:40 +0000 | [diff] [blame] | 1216 | { |
Nattapat Chaimanowong | af000a9 | 2019-05-16 16:32:35 +0100 | [diff] [blame] | 1217 | if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end()) |
| 1218 | { |
| 1219 | m_GraphConnections[sourceLayerIndex] = Connections(); |
| 1220 | } |
| 1221 | |
| 1222 | Connections& connections = m_GraphConnections[sourceLayerIndex]; |
| 1223 | if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end()) |
| 1224 | { |
| 1225 | throw ParseException("Same output slot index processed twice"); |
| 1226 | } |
| 1227 | |
| 1228 | connections.outputSlots[outputSlotIndex] = outputSlot; |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1231 | void IDeserializer::DeserializerImpl::ParseAbs(GraphPtr graph, unsigned int layerIndex) |
FinnWilliamsArm | 4ffcc8f | 2019-09-05 14:34:20 +0100 | [diff] [blame] | 1232 | { |
| 1233 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1234 | auto inputs = GetInputs(graph, layerIndex); |
| 1235 | CHECK_LOCATION(); |
| 1236 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1237 | |
| 1238 | auto outputs = GetOutputs(graph, layerIndex); |
| 1239 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1240 | |
| 1241 | auto layerName = GetLayerName(graph, layerIndex); |
| 1242 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1243 | armnn::ElementwiseUnaryDescriptor descriptor(armnn::UnaryOperation::Abs); |
| 1244 | IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str()); |
FinnWilliamsArm | 4ffcc8f | 2019-09-05 14:34:20 +0100 | [diff] [blame] | 1245 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1246 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1247 | |
| 1248 | RegisterInputSlots(graph, layerIndex, layer); |
| 1249 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1250 | } |
| 1251 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1252 | void IDeserializer::DeserializerImpl::ParseActivation(GraphPtr graph, unsigned int layerIndex) |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1253 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1254 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1255 | auto inputs = GetInputs(graph, layerIndex); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1256 | CHECK_LOCATION(); |
| 1257 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1258 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1259 | auto outputs = GetOutputs(graph, layerIndex); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1260 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1261 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1262 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer(); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 1263 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1264 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1265 | |
| 1266 | armnn::ActivationDescriptor descriptor; |
Tee Jung | 86bc3d8 | 2019-10-01 11:25:56 +0900 | [diff] [blame] | 1267 | descriptor.m_Function = ToActivationFunction(serializerDescriptor->activationFunction()); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1268 | descriptor.m_A = serializerDescriptor->a(); |
| 1269 | descriptor.m_B = serializerDescriptor->b(); |
| 1270 | |
| 1271 | IConnectableLayer* layer = m_Network->AddActivationLayer(descriptor, |
| 1272 | layerName.c_str()); |
| 1273 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1274 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1275 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1276 | RegisterInputSlots(graph, layerIndex, layer); |
| 1277 | RegisterOutputSlots(graph, layerIndex, layer); |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1280 | void IDeserializer::DeserializerImpl::ParseAdd(GraphPtr graph, unsigned int layerIndex) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1281 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1282 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1283 | auto inputs = GetInputs(graph, layerIndex); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1284 | CHECK_LOCATION(); |
| 1285 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1286 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1287 | auto outputs = GetOutputs(graph, layerIndex); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1288 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1289 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 1290 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 1291 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Add); |
| 1292 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1293 | |
| 1294 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1295 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1296 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1297 | RegisterInputSlots(graph, layerIndex, layer); |
| 1298 | RegisterOutputSlots(graph, layerIndex, layer); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1301 | void IDeserializer::DeserializerImpl::ParseArgMinMax(GraphPtr graph, unsigned int layerIndex) |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 1302 | { |
| 1303 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1304 | auto inputs = GetInputs(graph, layerIndex); |
| 1305 | CHECK_LOCATION(); |
| 1306 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1307 | |
| 1308 | auto outputs = GetOutputs(graph, layerIndex); |
| 1309 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1310 | |
| 1311 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer(); |
| 1312 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1313 | |
| 1314 | armnn::ArgMinMaxDescriptor descriptor; |
Tee Jung | 86bc3d8 | 2019-10-01 11:25:56 +0900 | [diff] [blame] | 1315 | descriptor.m_Function = ToArgMinMaxFunction(serializerDescriptor->argMinMaxFunction()); |
Narumol Prangnawarat | 0cfcf23 | 2019-09-09 17:16:24 +0100 | [diff] [blame] | 1316 | descriptor.m_Axis = serializerDescriptor->axis(); |
| 1317 | auto layerName = GetLayerName(graph, layerIndex); |
| 1318 | IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str()); |
| 1319 | |
| 1320 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1321 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1322 | |
| 1323 | RegisterInputSlots(graph, layerIndex, layer); |
| 1324 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1325 | } |
| 1326 | |
Samuel Yap | a04f4a1 | 2022-08-19 11:14:38 +0100 | [diff] [blame] | 1327 | void IDeserializer::DeserializerImpl::ParseBatchMatMul(GraphPtr graph, unsigned int layerIndex) |
| 1328 | { |
| 1329 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1330 | |
| 1331 | auto inputs = GetInputs(graph, layerIndex); |
| 1332 | CHECK_LOCATION(); |
| 1333 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1334 | |
| 1335 | auto outputs = GetOutputs(graph, layerIndex); |
| 1336 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1337 | |
| 1338 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchMatMulLayer(); |
| 1339 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1340 | |
| 1341 | armnn::BatchMatMulDescriptor descriptor(serializerDescriptor->transposeX(), |
| 1342 | serializerDescriptor->transposeY(), |
| 1343 | serializerDescriptor->adjointX(), |
| 1344 | serializerDescriptor->adjointY(), |
| 1345 | ToDataLayout(serializerDescriptor->dataLayoutX()), |
| 1346 | ToDataLayout(serializerDescriptor->dataLayoutY())); |
| 1347 | |
| 1348 | auto layerName = GetLayerName(graph, layerIndex); |
| 1349 | IConnectableLayer* layer = m_Network->AddBatchMatMulLayer(descriptor, layerName.c_str()); |
| 1350 | |
| 1351 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1352 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1353 | |
| 1354 | RegisterInputSlots(graph, layerIndex, layer); |
| 1355 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1356 | } |
| 1357 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1358 | void IDeserializer::DeserializerImpl::ParseBatchToSpaceNd(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1359 | { |
| 1360 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1361 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1362 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1363 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1364 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1365 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1366 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1367 | |
| 1368 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor(); |
| 1369 | auto flatBufferCrops = flatBufferDescriptor->crops(); |
| 1370 | auto flatBufferBlockShape = flatBufferDescriptor->blockShape(); |
| 1371 | |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 1372 | if (flatBufferCrops->size() % 2 != 0) |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1373 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 1374 | throw ParseException(fmt::format("The size of crops must be divisible by 2 {}", CHECK_LOCATION().AsString())); |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | std::vector<std::pair<unsigned int, unsigned int>> crops; |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 1378 | crops.reserve(flatBufferCrops->size() / 2); |
| 1379 | for (unsigned int i = 0; i < flatBufferCrops->size() - 1; i += 2) |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 1380 | { |
| 1381 | crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1)); |
| 1382 | } |
| 1383 | |
| 1384 | armnn::BatchToSpaceNdDescriptor descriptor; |
| 1385 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
| 1386 | descriptor.m_BlockShape = |
| 1387 | std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end()); |
| 1388 | descriptor.m_Crops = crops; |
| 1389 | |
| 1390 | auto layerName = GetLayerName(graph, layerIndex); |
| 1391 | IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str()); |
| 1392 | |
| 1393 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1394 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1395 | |
| 1396 | RegisterInputSlots(graph, layerIndex, layer); |
| 1397 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1398 | } |
| 1399 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1400 | void IDeserializer::DeserializerImpl::ParseBatchNormalization(GraphPtr graph, unsigned int layerIndex) |
ruoyan01 | 8e7fa23 | 2019-02-28 15:09:07 +0000 | [diff] [blame] | 1401 | { |
| 1402 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1403 | |
| 1404 | auto inputs = GetInputs(graph, layerIndex); |
| 1405 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1406 | |
| 1407 | auto outputs = GetOutputs(graph, layerIndex); |
| 1408 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1409 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 1410 | |
ruoyan01 | 5c7ab05 | 2019-03-04 14:48:02 +0000 | [diff] [blame] | 1411 | auto layerName = GetLayerName(graph, layerIndex); |
ruoyan01 | 8e7fa23 | 2019-02-28 15:09:07 +0000 | [diff] [blame] | 1412 | |
| 1413 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer(); |
| 1414 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1415 | |
| 1416 | armnn::BatchNormalizationDescriptor descriptor; |
| 1417 | descriptor.m_Eps = serializerDescriptor->eps(); |
| 1418 | descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout()); |
| 1419 | |
| 1420 | armnn::ConstTensor mean = ToConstTensor(serializerLayer->mean()); |
| 1421 | armnn::ConstTensor variance = ToConstTensor(serializerLayer->variance()); |
| 1422 | armnn::ConstTensor beta = ToConstTensor(serializerLayer->beta()); |
| 1423 | armnn::ConstTensor gamma = ToConstTensor(serializerLayer->gamma()); |
| 1424 | |
| 1425 | IConnectableLayer* layer = m_Network->AddBatchNormalizationLayer(descriptor, |
| 1426 | mean, |
| 1427 | variance, |
| 1428 | beta, |
| 1429 | gamma, |
| 1430 | layerName.c_str()); |
| 1431 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1432 | |
| 1433 | RegisterInputSlots(graph, layerIndex, layer); |
| 1434 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1435 | } |
| 1436 | |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 1437 | void IDeserializer::DeserializerImpl::ParseCast(GraphPtr graph, unsigned int layerIndex) |
| 1438 | { |
| 1439 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1440 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
| 1441 | CHECK_LOCATION(); |
| 1442 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1443 | |
| 1444 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
| 1445 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1446 | |
| 1447 | auto layerName = GetLayerName(graph, layerIndex); |
| 1448 | |
| 1449 | IConnectableLayer* layer = m_Network->AddCastLayer(layerName.c_str()); |
| 1450 | |
| 1451 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1452 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1453 | |
| 1454 | RegisterInputSlots(graph, layerIndex, layer); |
| 1455 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1456 | } |
| 1457 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1458 | void IDeserializer::DeserializerImpl::ParseConstant(GraphPtr graph, unsigned int layerIndex) |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 1459 | { |
| 1460 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1461 | CHECK_LOCATION(); |
| 1462 | |
| 1463 | auto outputs = GetOutputs(graph, layerIndex); |
| 1464 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1465 | |
| 1466 | auto layerName = GetLayerName(graph, layerIndex); |
| 1467 | |
| 1468 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer(); |
| 1469 | auto serializerInput = serializerLayer->input(); |
| 1470 | |
| 1471 | armnn::ConstTensor input = ToConstTensor(serializerInput); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1472 | IConnectableLayer* layer; |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 1473 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1474 | // Required for when Constant Layer is used as an inputs to DepthwiseConvolution2d Layer. |
| 1475 | // Running a model that was created before weights layout scheme version was added to our flatbuffers |
| 1476 | // file ensuring older models can still be read and executed. featureVersion weights layout scheme 1 |
| 1477 | // indicates a change in the depthwise weights layout within ArmNN from [M,I,H,W] --> [1,H,W,I*M] |
| 1478 | if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0) |
| 1479 | { |
| 1480 | // Permute weights [ H, W, M, I ] --> [ 1, H, W, I*M ] |
| 1481 | // Step1: [ M, I, H, W ] --> [ H, W, I, M] |
| 1482 | PermutationVector permutationVector = { 3, 2, 0, 1 }; |
| 1483 | armnn::TensorInfo weightsInfo = input.GetInfo(); |
| 1484 | std::unique_ptr<unsigned char[]> permuteBuffer(new unsigned char[weightsInfo.GetNumBytes()]); |
| 1485 | weightsInfo = armnnUtils::Permuted(weightsInfo, permutationVector); |
| 1486 | armnnUtils::Permute(weightsInfo.GetShape(), permutationVector, |
| 1487 | input.GetMemoryArea(), permuteBuffer.get(), |
| 1488 | GetDataTypeSize(weightsInfo.GetDataType())); |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 1489 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1490 | // Step2: Reshape [ H, W, I, M] --> [ 1, H, W, I*M ] |
| 1491 | auto weightsShape = weightsInfo.GetShape(); |
| 1492 | weightsInfo.SetShape({1, |
| 1493 | weightsShape[0], |
| 1494 | weightsShape[1], |
| 1495 | weightsShape[2]*weightsShape[3]}); |
Sadik Armagan | 361679d | 2022-08-02 09:17:23 +0100 | [diff] [blame] | 1496 | weightsInfo.SetConstant(true); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1497 | |
| 1498 | armnn::ConstTensor weightsPermuted(weightsInfo, permuteBuffer.get()); |
| 1499 | |
| 1500 | layer = m_Network->AddConstantLayer(weightsPermuted, layerName.c_str()); |
| 1501 | |
| 1502 | layer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo()); |
| 1503 | |
| 1504 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1505 | |
| 1506 | return; |
| 1507 | } |
| 1508 | else |
| 1509 | { |
| 1510 | layer = m_Network->AddConstantLayer(input, layerName.c_str()); |
| 1511 | |
| 1512 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
Sadik Armagan | 361679d | 2022-08-02 09:17:23 +0100 | [diff] [blame] | 1513 | outputTensorInfo.SetConstant(true); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1514 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1515 | } |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 1516 | |
| 1517 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1518 | } |
| 1519 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1520 | void IDeserializer::DeserializerImpl::ParseConvolution2d(GraphPtr graph, unsigned int layerIndex) |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1521 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1522 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1523 | auto inputs = GetInputs(graph, layerIndex); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1524 | CHECK_LOCATION(); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1525 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1526 | auto outputs = GetOutputs(graph, layerIndex); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1527 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1528 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1529 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer(); |
| 1530 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 1531 | auto layerName = GetLayerName(graph, layerIndex); |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1532 | auto flatbufferDescriptor = flatBufferLayer->descriptor(); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1533 | |
| 1534 | armnn::Convolution2dDescriptor descriptor; |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1535 | descriptor.m_PadLeft = flatbufferDescriptor->padLeft(); |
| 1536 | descriptor.m_PadRight = flatbufferDescriptor->padRight(); |
| 1537 | descriptor.m_PadTop = flatbufferDescriptor->padTop(); |
| 1538 | descriptor.m_PadBottom = flatbufferDescriptor->padBottom(); |
| 1539 | descriptor.m_StrideX = flatbufferDescriptor->strideX(); |
| 1540 | descriptor.m_StrideY = flatbufferDescriptor->strideY();; |
| 1541 | descriptor.m_DilationX = flatbufferDescriptor->dilationX(); |
| 1542 | descriptor.m_DilationY = flatbufferDescriptor->dilationY();; |
| 1543 | descriptor.m_BiasEnabled = flatbufferDescriptor->biasEnabled();; |
| 1544 | descriptor.m_DataLayout = ToDataLayout(flatbufferDescriptor->dataLayout()); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1545 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1546 | armnn::IConnectableLayer* layer; |
| 1547 | std::vector<unsigned int> ignoreSlots {}; |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1548 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1549 | armnn::ConstTensor biasTensor; |
| 1550 | // Weights and biases used to be always constant and were stored as members of the layer. This has changed and |
| 1551 | // they are now passed as inputs. If they are constant then they will be stored in a ConstantLayer. |
| 1552 | if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0) |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1553 | { |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1554 | // If the model stores weights and biases as members of the layer we have to read them from there |
| 1555 | // but add them to their own ConstantLayer for compatibility |
| 1556 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1557 | |
| 1558 | layer = m_Network->AddConvolution2dLayer(descriptor, |
| 1559 | layerName.c_str()); |
| 1560 | |
| 1561 | armnn::ConstTensor weightsTensor = ToConstTensor(flatBufferLayer->weights()); |
| 1562 | auto weightsLayer = m_Network->AddConstantLayer(weightsTensor); |
| 1563 | weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); |
| 1564 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.GetInfo()); |
| 1565 | ignoreSlots.emplace_back(1u); |
| 1566 | |
| 1567 | if (descriptor.m_BiasEnabled) |
| 1568 | { |
| 1569 | biasTensor = ToConstTensor(flatBufferLayer->biases()); |
| 1570 | auto biasLayer = m_Network->AddConstantLayer(biasTensor); |
| 1571 | biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u)); |
| 1572 | biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.GetInfo()); |
| 1573 | ignoreSlots.emplace_back(2u); |
| 1574 | } |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1575 | } |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1576 | else |
| 1577 | { |
| 1578 | layer = m_Network->AddConvolution2dLayer(descriptor, |
| 1579 | layerName.c_str()); |
| 1580 | uint32_t numInputs = descriptor.GetNumInputs(); |
| 1581 | CHECK_VALID_SIZE(inputs.size(), numInputs); |
| 1582 | } |
| 1583 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1584 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1585 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1586 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 1587 | RegisterInputSlots(graph, layerIndex, layer, ignoreSlots); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1588 | RegisterOutputSlots(graph, layerIndex, layer); |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1591 | void IDeserializer::DeserializerImpl::ParseConvolution3d(GraphPtr graph, unsigned int layerIndex) |
| 1592 | { |
| 1593 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1594 | auto inputs = GetInputs(graph, layerIndex); |
| 1595 | CHECK_LOCATION(); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1596 | |
| 1597 | auto outputs = GetOutputs(graph, layerIndex); |
| 1598 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1599 | |
| 1600 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution3dLayer(); |
| 1601 | auto layerName = GetLayerName(graph, layerIndex); |
| 1602 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1603 | |
| 1604 | armnn::Convolution3dDescriptor descriptor; |
| 1605 | descriptor.m_PadLeft = serializerDescriptor->padLeft(); |
| 1606 | descriptor.m_PadRight = serializerDescriptor->padRight(); |
| 1607 | descriptor.m_PadTop = serializerDescriptor->padTop(); |
| 1608 | descriptor.m_PadBottom = serializerDescriptor->padBottom(); |
| 1609 | descriptor.m_PadFront = serializerDescriptor->padFront(); |
| 1610 | descriptor.m_PadBack = serializerDescriptor->padBack(); |
| 1611 | descriptor.m_StrideX = serializerDescriptor->strideX(); |
| 1612 | descriptor.m_StrideY = serializerDescriptor->strideY(); |
| 1613 | descriptor.m_StrideZ = serializerDescriptor->strideZ(); |
| 1614 | descriptor.m_DilationX = serializerDescriptor->dilationX(); |
| 1615 | descriptor.m_DilationY = serializerDescriptor->dilationY(); |
| 1616 | descriptor.m_DilationZ = serializerDescriptor->dilationZ(); |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 1617 | descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled(); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1618 | descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout()); |
| 1619 | |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 1620 | uint32_t numInputs = descriptor.GetNumInputs(); |
| 1621 | CHECK_VALID_SIZE(inputs.size(), numInputs); |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1622 | |
Matthew Sloyan | 5d7b0a3 | 2021-10-18 13:07:49 +0100 | [diff] [blame] | 1623 | IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str()); |
| 1624 | |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1625 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1626 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1627 | |
| 1628 | RegisterInputSlots(graph, layerIndex, layer); |
| 1629 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1630 | } |
| 1631 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1632 | void IDeserializer::DeserializerImpl::ParseDepthToSpace(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | da9d2d3 | 2019-09-20 10:42:02 +0100 | [diff] [blame] | 1633 | { |
| 1634 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1635 | |
| 1636 | auto inputs = GetInputs(graph, layerIndex); |
| 1637 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1638 | |
| 1639 | auto outputs = GetOutputs(graph, layerIndex); |
| 1640 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1641 | |
| 1642 | auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor(); |
| 1643 | |
| 1644 | armnn::DepthToSpaceDescriptor descriptor; |
| 1645 | descriptor.m_BlockSize = fbDescriptor->blockSize(); |
| 1646 | descriptor.m_DataLayout = ToDataLayout(fbDescriptor->dataLayout()); |
| 1647 | |
| 1648 | auto layerName = GetLayerName(graph, layerIndex); |
| 1649 | IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str()); |
| 1650 | |
| 1651 | armnn::TensorInfo outputInfo = ToTensorInfo(outputs[0]); |
| 1652 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1653 | |
| 1654 | RegisterInputSlots(graph, layerIndex, layer); |
| 1655 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1656 | } |
| 1657 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1658 | void IDeserializer::DeserializerImpl::ParseDepthwiseConvolution2d(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1659 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1660 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1661 | auto inputs = GetInputs(graph, layerIndex); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1662 | CHECK_LOCATION(); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1663 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1664 | auto outputs = GetOutputs(graph, layerIndex); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1665 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1666 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1667 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer(); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 1668 | auto layerName = GetLayerName(graph, layerIndex); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1669 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 1670 | |
| 1671 | armnn::DepthwiseConvolution2dDescriptor descriptor; |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1672 | descriptor.m_PadLeft = serializerDescriptor->padLeft(); |
| 1673 | descriptor.m_PadRight = serializerDescriptor->padRight(); |
| 1674 | descriptor.m_PadTop = serializerDescriptor->padTop(); |
| 1675 | descriptor.m_PadBottom = serializerDescriptor->padBottom(); |
| 1676 | descriptor.m_StrideX = serializerDescriptor->strideX(); |
| 1677 | descriptor.m_StrideY = serializerDescriptor->strideY(); |
| 1678 | descriptor.m_DilationX = serializerDescriptor->dilationX(); |
| 1679 | descriptor.m_DilationY = serializerDescriptor->dilationY(); |
| 1680 | descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled(); |
| 1681 | descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout()); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1682 | |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1683 | IConnectableLayer* layer; |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1684 | std::vector<unsigned int> ignoreSlots {}; |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1685 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1686 | // Weights and biases used to be always constant and were stored as members of the layer. This has changed and |
| 1687 | // they are now passed as inputs. If they are constant then they will be stored in a ConstantLayer. |
| 1688 | if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0) |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1689 | { |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1690 | CHECK_VALID_SIZE(inputs.size(), 1); |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1691 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1692 | // If the model stores weights and biases as members of the layer we have to read them from there |
| 1693 | // but add them to their own ConstantLayer for compatibility |
| 1694 | armnn::ConstTensor weights = ToConstTensor(serializerLayer->weights()); |
| 1695 | ignoreSlots.emplace_back(1u); |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1696 | |
| 1697 | layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor, |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1698 | layerName.c_str()); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1699 | |
| 1700 | armnn::Optional<armnn::ConstTensor> optionalBiases = armnn::EmptyOptional(); |
| 1701 | if (descriptor.m_BiasEnabled) |
| 1702 | { |
| 1703 | armnn::ConstTensor biases = ToConstTensor(serializerLayer->biases()); |
| 1704 | ignoreSlots.emplace_back(2u); |
| 1705 | |
| 1706 | auto biasLayer = m_Network->AddConstantLayer(biases); |
| 1707 | biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u)); |
| 1708 | biasLayer->GetOutputSlot(0).SetTensorInfo(biases.GetInfo()); |
| 1709 | } |
| 1710 | |
| 1711 | if (this->GetFeatureVersions(graph).m_WeightsLayoutScheme <= 0) |
| 1712 | { |
| 1713 | // Permute weights [ H, W, M, I ] --> [ 1, H, W, I*M ] |
| 1714 | // Step1: [ M, I, H, W ] --> [ H, W, I, M] |
| 1715 | PermutationVector permutationVector = { 3, 2, 0, 1 }; |
| 1716 | armnn::TensorInfo weightsInfo = weights.GetInfo(); |
| 1717 | std::unique_ptr<unsigned char[]> permuteBuffer(new unsigned char[weightsInfo.GetNumBytes()]); |
| 1718 | weightsInfo = armnnUtils::Permuted(weightsInfo, permutationVector); |
| 1719 | armnnUtils::Permute(weightsInfo.GetShape(), permutationVector, |
| 1720 | weights.GetMemoryArea(), permuteBuffer.get(), |
| 1721 | GetDataTypeSize(weightsInfo.GetDataType())); |
| 1722 | |
| 1723 | // Step2: Reshape [ H, W, I, M] --> [ 1, H, W, I*M ] |
| 1724 | auto weightsShape = weightsInfo.GetShape(); |
| 1725 | weightsInfo.SetShape({1, |
| 1726 | weightsShape[0], |
| 1727 | weightsShape[1], |
| 1728 | weightsShape[2]*weightsShape[3]}); |
| 1729 | |
| 1730 | armnn::ConstTensor weightsPermuted(weightsInfo, permuteBuffer.get()); |
| 1731 | |
| 1732 | auto weightsLayer = m_Network->AddConstantLayer(weightsPermuted); |
| 1733 | weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); |
| 1734 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted.GetInfo()); |
| 1735 | } |
| 1736 | else |
| 1737 | { |
| 1738 | auto weightsLayer = m_Network->AddConstantLayer(weights); |
| 1739 | weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); |
| 1740 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weights.GetInfo()); |
| 1741 | } |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1742 | } |
| 1743 | else |
| 1744 | { |
| 1745 | layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor, |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1746 | layerName.c_str()); |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1747 | uint32_t numInputs = descriptor.GetNumInputs(); |
| 1748 | CHECK_VALID_SIZE(inputs.size(), numInputs); |
Jan Eilers | 53ef795 | 2021-06-02 12:01:25 +0100 | [diff] [blame] | 1749 | } |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1750 | |
| 1751 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1752 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1753 | |
Cathal Corbett | 0690265 | 2022-04-14 17:55:11 +0100 | [diff] [blame] | 1754 | RegisterInputSlots(graph, layerIndex, layer, ignoreSlots); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 1755 | RegisterOutputSlots(graph, layerIndex, layer); |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1758 | void IDeserializer::DeserializerImpl::ParseDetectionPostProcess(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 3e14a9d | 2019-03-18 12:37:06 +0000 | [diff] [blame] | 1759 | { |
| 1760 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1761 | auto inputs = GetInputs(graph, layerIndex); |
| 1762 | CHECK_LOCATION(); |
| 1763 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1764 | |
| 1765 | auto outputs = GetOutputs(graph, layerIndex); |
| 1766 | CHECK_VALID_SIZE(outputs.size(), 4); |
| 1767 | |
| 1768 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer(); |
| 1769 | auto layerName = GetLayerName(graph, layerIndex); |
| 1770 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 1771 | |
| 1772 | armnn::DetectionPostProcessDescriptor descriptor; |
| 1773 | descriptor.m_MaxDetections = flatBufferDescriptor->maxDetections(); |
| 1774 | descriptor.m_MaxClassesPerDetection = flatBufferDescriptor->maxClassesPerDetection(); |
| 1775 | descriptor.m_DetectionsPerClass = flatBufferDescriptor->detectionsPerClass(); |
| 1776 | descriptor.m_NmsScoreThreshold = flatBufferDescriptor->nmsScoreThreshold(); |
| 1777 | descriptor.m_NmsIouThreshold = flatBufferDescriptor->nmsIouThreshold(); |
| 1778 | descriptor.m_NumClasses = flatBufferDescriptor->numClasses(); |
| 1779 | descriptor.m_UseRegularNms = flatBufferDescriptor->useRegularNms(); |
| 1780 | descriptor.m_ScaleX = flatBufferDescriptor->scaleX(); |
| 1781 | descriptor.m_ScaleY = flatBufferDescriptor->scaleY(); |
| 1782 | descriptor.m_ScaleW = flatBufferDescriptor->scaleW(); |
| 1783 | descriptor.m_ScaleH = flatBufferDescriptor->scaleH(); |
| 1784 | |
| 1785 | armnn::ConstTensor anchors = ToConstTensor(flatBufferLayer->anchors()); |
| 1786 | |
| 1787 | IConnectableLayer* layer = m_Network->AddDetectionPostProcessLayer(descriptor, |
| 1788 | anchors, |
| 1789 | layerName.c_str()); |
| 1790 | |
| 1791 | for (unsigned int i = 0; i < 4; i++) |
| 1792 | { |
| 1793 | layer->GetOutputSlot(i).SetTensorInfo(ToTensorInfo(outputs[i])); |
| 1794 | } |
| 1795 | |
| 1796 | RegisterInputSlots(graph, layerIndex, layer); |
| 1797 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1798 | } |
| 1799 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1800 | void IDeserializer::DeserializerImpl::ParseDivision(GraphPtr graph, unsigned int layerIndex) |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 1801 | { |
| 1802 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1803 | auto inputs = GetInputs(graph, layerIndex); |
| 1804 | CHECK_LOCATION(); |
| 1805 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1806 | |
| 1807 | auto outputs = GetOutputs(graph, layerIndex); |
| 1808 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1809 | |
| 1810 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 1811 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Div); |
| 1812 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 1813 | |
| 1814 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1815 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1816 | |
| 1817 | RegisterInputSlots(graph, layerIndex, layer); |
| 1818 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1819 | } |
| 1820 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1821 | void IDeserializer::DeserializerImpl::ParseEqual(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 1822 | { |
| 1823 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1824 | auto inputs = GetInputs(graph, layerIndex); |
| 1825 | CHECK_LOCATION(); |
| 1826 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1827 | |
| 1828 | auto outputs = GetOutputs(graph, layerIndex); |
| 1829 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1830 | |
| 1831 | auto layerName = GetLayerName(graph, layerIndex); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 1832 | armnn::ComparisonDescriptor descriptor(armnn::ComparisonOperation::Equal); |
| 1833 | IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str()); |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 1834 | |
| 1835 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1836 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1837 | |
| 1838 | RegisterInputSlots(graph, layerIndex, layer); |
| 1839 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1840 | } |
| 1841 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1842 | void IDeserializer::DeserializerImpl::ParseFill(GraphPtr graph, unsigned int layerIndex) |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1843 | { |
| 1844 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1845 | auto inputs = GetInputs(graph, layerIndex); |
| 1846 | CHECK_LOCATION(); |
| 1847 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1848 | |
| 1849 | auto outputs = GetOutputs(graph, layerIndex); |
| 1850 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1851 | |
| 1852 | auto layerName = GetLayerName(graph, layerIndex); |
Sadik Armagan | fd0cae3 | 2021-11-08 17:18:31 +0000 | [diff] [blame] | 1853 | armnn::FillDescriptor descriptor; |
| 1854 | descriptor.m_Value = graph->layers()->Get(layerIndex)->layer_as_FillLayer()->descriptor()->value(); |
Keith Davis | 300ad56 | 2020-06-04 16:34:23 +0100 | [diff] [blame] | 1855 | IConnectableLayer* layer = m_Network->AddFillLayer(descriptor, layerName.c_str()); |
| 1856 | |
| 1857 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1858 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1859 | |
| 1860 | RegisterInputSlots(graph, layerIndex, layer); |
| 1861 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1862 | } |
| 1863 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1864 | void IDeserializer::DeserializerImpl::ParseGreater(GraphPtr graph, unsigned int layerIndex) |
Conor Kennedy | 79ffdf5 | 2019-03-01 14:24:54 +0000 | [diff] [blame] | 1865 | { |
| 1866 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1867 | auto inputs = GetInputs(graph, layerIndex); |
| 1868 | CHECK_LOCATION(); |
| 1869 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1870 | |
| 1871 | auto outputs = GetOutputs(graph, layerIndex); |
| 1872 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1873 | |
| 1874 | auto layerName = GetLayerName(graph, layerIndex); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 1875 | armnn::ComparisonDescriptor descriptor(armnn::ComparisonOperation::Greater); |
| 1876 | IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str()); |
Conor Kennedy | 79ffdf5 | 2019-03-01 14:24:54 +0000 | [diff] [blame] | 1877 | |
| 1878 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1879 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1880 | |
| 1881 | RegisterInputSlots(graph, layerIndex, layer); |
| 1882 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1883 | } |
| 1884 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1885 | void IDeserializer::DeserializerImpl::ParseInstanceNormalization(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | 781ced9 | 2019-10-03 11:15:39 +0100 | [diff] [blame] | 1886 | { |
| 1887 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1888 | |
| 1889 | auto inputs = GetInputs(graph, layerIndex); |
| 1890 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1891 | |
| 1892 | auto outputs = GetOutputs(graph, layerIndex); |
| 1893 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1894 | |
| 1895 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer(); |
| 1896 | auto fbDescriptor = fbLayer->descriptor(); |
| 1897 | |
| 1898 | armnn::InstanceNormalizationDescriptor descriptor; |
| 1899 | descriptor.m_Gamma = fbDescriptor->gamma(); |
| 1900 | descriptor.m_Beta = fbDescriptor->beta(); |
| 1901 | descriptor.m_Eps = fbDescriptor->eps(); |
| 1902 | descriptor.m_DataLayout = ToDataLayout(fbDescriptor->dataLayout()); |
| 1903 | |
| 1904 | const std::string layerName = GetLayerName(graph, layerIndex); |
| 1905 | const armnn::TensorInfo outputInfo = ToTensorInfo(outputs[0]); |
| 1906 | |
| 1907 | IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str()); |
| 1908 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1909 | |
| 1910 | RegisterInputSlots(graph, layerIndex, layer); |
| 1911 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1912 | } |
| 1913 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1914 | void IDeserializer::DeserializerImpl::ParseL2Normalization(GraphPtr graph, unsigned int layerIndex) |
Narumol Prangnawarat | 495701f | 2019-03-07 17:31:34 +0000 | [diff] [blame] | 1915 | { |
| 1916 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1917 | |
| 1918 | auto inputs = GetInputs(graph, layerIndex); |
| 1919 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1920 | |
| 1921 | auto outputs = GetOutputs(graph, layerIndex); |
| 1922 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1923 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 1924 | |
| 1925 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer(); |
| 1926 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 1927 | |
| 1928 | auto layerName = GetLayerName(graph, layerIndex); |
| 1929 | armnn::L2NormalizationDescriptor descriptor; |
| 1930 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
Ferran Balaguer | 0dcffec | 2019-06-18 16:25:06 +0100 | [diff] [blame] | 1931 | descriptor.m_Eps = flatBufferDescriptor->eps(); |
Narumol Prangnawarat | 495701f | 2019-03-07 17:31:34 +0000 | [diff] [blame] | 1932 | |
| 1933 | IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str()); |
| 1934 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 1935 | |
| 1936 | RegisterInputSlots(graph, layerIndex, layer); |
| 1937 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1938 | } |
| 1939 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1940 | void IDeserializer::DeserializerImpl::ParseLogicalBinary(GraphPtr graph, unsigned int layerIndex) |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1941 | { |
| 1942 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1943 | CHECK_LOCATION(); |
| 1944 | |
| 1945 | auto inputs = GetInputs(graph, layerIndex); |
| 1946 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1947 | |
| 1948 | auto outputs = GetOutputs(graph, layerIndex); |
| 1949 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1950 | |
| 1951 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_LogicalBinaryLayer(); |
| 1952 | auto fbDescriptor = fbLayer->descriptor(); |
| 1953 | |
| 1954 | armnn::LogicalBinaryDescriptor descriptor; |
| 1955 | descriptor.m_Operation = ToLogicalBinaryOperation(fbDescriptor->operation()); |
| 1956 | |
| 1957 | const std::string& layerName = GetLayerName(graph, layerIndex); |
| 1958 | IConnectableLayer* layer = m_Network->AddLogicalBinaryLayer(descriptor, layerName.c_str()); |
| 1959 | |
| 1960 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1961 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1962 | |
| 1963 | RegisterInputSlots(graph, layerIndex, layer); |
| 1964 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1965 | } |
| 1966 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1967 | void IDeserializer::DeserializerImpl::ParseLogSoftmax(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1968 | { |
| 1969 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1970 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1971 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1972 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 1973 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1974 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Sadik Armagan | 2625785 | 2019-10-14 13:00:47 +0100 | [diff] [blame] | 1975 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 1976 | |
| 1977 | armnn::LogSoftmaxDescriptor descriptor; |
| 1978 | descriptor.m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta(); |
| 1979 | descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis(); |
| 1980 | auto layerName = GetLayerName(graph, layerIndex); |
| 1981 | |
| 1982 | IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str()); |
| 1983 | |
| 1984 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 1985 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 1986 | |
| 1987 | RegisterInputSlots(graph, layerIndex, layer); |
| 1988 | RegisterOutputSlots(graph, layerIndex, layer); |
| 1989 | } |
| 1990 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 1991 | void IDeserializer::DeserializerImpl::ParseMinimum(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 1992 | { |
| 1993 | CHECK_LAYERS(graph, 0, layerIndex); |
| 1994 | auto inputs = GetInputs(graph, layerIndex); |
| 1995 | CHECK_LOCATION(); |
| 1996 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 1997 | |
| 1998 | auto outputs = GetOutputs(graph, layerIndex); |
| 1999 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2000 | |
| 2001 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2002 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Minimum); |
| 2003 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 2004 | |
| 2005 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2006 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2007 | |
| 2008 | RegisterInputSlots(graph, layerIndex, layer); |
| 2009 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2010 | } |
| 2011 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2012 | void IDeserializer::DeserializerImpl::ParseMaximum(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame] | 2013 | { |
| 2014 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2015 | auto inputs = GetInputs(graph, layerIndex); |
| 2016 | CHECK_LOCATION(); |
| 2017 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 2018 | |
| 2019 | auto outputs = GetOutputs(graph, layerIndex); |
| 2020 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2021 | |
| 2022 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2023 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Maximum); |
| 2024 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame] | 2025 | |
| 2026 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2027 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2028 | |
| 2029 | RegisterInputSlots(graph, layerIndex, layer); |
| 2030 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2031 | } |
| 2032 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 2033 | const armnnSerializer::OriginsDescriptor* GetOriginsDescriptor(const armnnSerializer::SerializedGraph* graph, |
| 2034 | unsigned int layerIndex) |
| 2035 | { |
| 2036 | auto layerType = graph->layers()->Get(layerIndex)->layer_type(); |
| 2037 | |
| 2038 | switch (layerType) |
| 2039 | { |
| 2040 | case Layer::Layer_ConcatLayer: |
| 2041 | return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor(); |
| 2042 | case Layer::Layer_MergerLayer: |
| 2043 | return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor(); |
| 2044 | default: |
| 2045 | throw armnn::Exception("unknown layer type, should be concat or merger"); |
| 2046 | } |
| 2047 | } |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 2048 | void IDeserializer::DeserializerImpl::ParseChannelShuffle(GraphPtr graph, unsigned int layerIndex) |
| 2049 | { |
| 2050 | CHECK_LAYERS(graph, 0, layerIndex); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 2051 | |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 2052 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
| 2053 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2054 | |
| 2055 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
| 2056 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2057 | |
| 2058 | armnn::ChannelShuffleDescriptor descriptor; |
| 2059 | descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->axis(); |
| 2060 | descriptor.m_NumGroups = |
| 2061 | graph->layers()->Get(layerIndex)->layer_as_ChannelShuffleLayer()->descriptor()->numGroups(); |
| 2062 | |
| 2063 | auto layerName = GetLayerName(graph, layerIndex); |
| 2064 | IConnectableLayer* layer = m_Network->AddChannelShuffleLayer(descriptor, layerName.c_str()); |
| 2065 | |
| 2066 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2067 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2068 | |
| 2069 | RegisterInputSlots(graph, layerIndex, layer); |
| 2070 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2071 | } |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2072 | void IDeserializer::DeserializerImpl::ParseComparison(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | e80ebd1 | 2019-10-17 16:11:54 +0100 | [diff] [blame] | 2073 | { |
| 2074 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2075 | CHECK_LOCATION(); |
| 2076 | |
| 2077 | auto inputs = GetInputs(graph, layerIndex); |
| 2078 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 2079 | |
| 2080 | auto outputs = GetOutputs(graph, layerIndex); |
| 2081 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2082 | |
| 2083 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer(); |
| 2084 | auto fbDescriptor = fbLayer->descriptor(); |
| 2085 | |
| 2086 | armnn::ComparisonDescriptor descriptor; |
| 2087 | descriptor.m_Operation = ToComparisonOperation(fbDescriptor->operation()); |
| 2088 | |
| 2089 | const std::string& layerName = GetLayerName(graph, layerIndex); |
| 2090 | IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str()); |
| 2091 | |
| 2092 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2093 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2094 | |
| 2095 | RegisterInputSlots(graph, layerIndex, layer); |
| 2096 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2097 | } |
| 2098 | |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2099 | void IDeserializer::DeserializerImpl::ParseElementwiseBinary(GraphPtr graph, unsigned int layerIndex) |
| 2100 | { |
| 2101 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2102 | CHECK_LOCATION(); |
| 2103 | |
| 2104 | auto inputs = GetInputs(graph, layerIndex); |
| 2105 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 2106 | |
| 2107 | auto outputs = GetOutputs(graph, layerIndex); |
| 2108 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2109 | |
| 2110 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseBinaryLayer(); |
| 2111 | auto fbDescriptor = fbLayer->descriptor(); |
| 2112 | |
| 2113 | armnn::ElementwiseBinaryDescriptor descriptor; |
| 2114 | descriptor.m_Operation = ToElementwiseBinaryOperation(fbDescriptor->operation()); |
| 2115 | |
| 2116 | const std::string& layerName = GetLayerName(graph, layerIndex); |
| 2117 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
| 2118 | |
| 2119 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2120 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2121 | |
| 2122 | RegisterInputSlots(graph, layerIndex, layer); |
| 2123 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2124 | } |
| 2125 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2126 | void IDeserializer::DeserializerImpl::ParseElementwiseUnary(GraphPtr graph, unsigned int layerIndex) |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 2127 | { |
| 2128 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2129 | CHECK_LOCATION(); |
| 2130 | |
| 2131 | auto inputs = GetInputs(graph, layerIndex); |
| 2132 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2133 | |
| 2134 | auto outputs = GetOutputs(graph, layerIndex); |
| 2135 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2136 | |
| 2137 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer(); |
| 2138 | auto fbDescriptor = fbLayer->descriptor(); |
| 2139 | |
| 2140 | armnn::ElementwiseUnaryDescriptor descriptor; |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2141 | descriptor.m_Operation = ToElementwiseUnaryOperation(fbDescriptor->operation()); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 2142 | |
| 2143 | const std::string& layerName = GetLayerName(graph, layerIndex); |
| 2144 | IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str()); |
| 2145 | |
| 2146 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2147 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2148 | |
| 2149 | RegisterInputSlots(graph, layerIndex, layer); |
| 2150 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2151 | } |
| 2152 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2153 | void IDeserializer::DeserializerImpl::ParseConcat(GraphPtr graph, unsigned int layerIndex) |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2154 | { |
| 2155 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2156 | CHECK_LOCATION(); |
| 2157 | |
| 2158 | auto outputs = GetOutputs(graph, layerIndex); |
| 2159 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2160 | |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2161 | auto layerName = GetLayerName(graph, layerIndex); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 2162 | auto originsDescriptor = GetOriginsDescriptor(graph, layerIndex); |
| 2163 | unsigned int numViews = originsDescriptor->numViews(); |
| 2164 | unsigned int numDimensions = originsDescriptor->numDimensions(); |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2165 | |
| 2166 | // can now check the number of inputs == number of views |
| 2167 | auto inputs = GetInputs(graph, layerIndex); |
| 2168 | CHECK_VALID_SIZE(inputs.size(), numViews); |
| 2169 | |
| 2170 | armnn::OriginsDescriptor descriptor(numViews, numDimensions); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 2171 | auto originsPtr = originsDescriptor->viewOrigins(); |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2172 | for (unsigned int v = 0; v < numViews; ++v) |
| 2173 | { |
| 2174 | auto originPtr = originsPtr->Get(v); |
| 2175 | for (unsigned int d = 0; d < numDimensions; ++d) |
| 2176 | { |
| 2177 | uint32_t value = originPtr->data()->Get(d); |
| 2178 | descriptor.SetViewOriginCoord(v, d, value); |
| 2179 | } |
| 2180 | } |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 2181 | descriptor.SetConcatAxis(originsDescriptor->concatAxis()); |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2182 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 2183 | IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str()); |
Jim Flynn | ac25a1b | 2019-02-28 10:40:49 +0000 | [diff] [blame] | 2184 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2185 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2186 | |
| 2187 | RegisterInputSlots(graph, layerIndex, layer); |
| 2188 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2189 | } |
| 2190 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2191 | void IDeserializer::DeserializerImpl::ParseMultiplication(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 2192 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2193 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2194 | auto inputs = GetInputs(graph, layerIndex); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 2195 | CHECK_LOCATION(); |
| 2196 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 2197 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2198 | auto outputs = GetOutputs(graph, layerIndex); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 2199 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2200 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2201 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 2202 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Mul); |
| 2203 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 2204 | |
| 2205 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2206 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2207 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2208 | RegisterInputSlots(graph, layerIndex, layer); |
| 2209 | RegisterOutputSlots(graph, layerIndex, layer); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2212 | void IDeserializer::DeserializerImpl::ParseFloor(GraphPtr graph, unsigned int layerIndex) |
Finn Williams | dd2ba7e | 2019-03-01 11:51:52 +0000 | [diff] [blame] | 2213 | { |
| 2214 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2215 | CHECK_LOCATION(); |
| 2216 | |
| 2217 | auto inputs = GetInputs(graph, layerIndex); |
| 2218 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2219 | |
| 2220 | auto outputs = GetOutputs(graph, layerIndex); |
| 2221 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2222 | |
| 2223 | auto layerName = GetLayerName(graph, layerIndex); |
| 2224 | |
| 2225 | armnn::IConnectableLayer* layer; |
| 2226 | |
Nattapat Chaimanowong | c192f35 | 2019-03-05 17:35:28 +0000 | [diff] [blame] | 2227 | layer = m_Network->AddFloorLayer(layerName.c_str()); |
Finn Williams | dd2ba7e | 2019-03-01 11:51:52 +0000 | [diff] [blame] | 2228 | |
| 2229 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2230 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2231 | |
| 2232 | RegisterInputSlots(graph, layerIndex, layer); |
| 2233 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2234 | } |
| 2235 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2236 | void IDeserializer::DeserializerImpl::ParseFullyConnected(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2237 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2238 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2239 | auto inputs = GetInputs(graph, layerIndex); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2240 | CHECK_LOCATION(); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2241 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2242 | auto outputs = GetOutputs(graph, layerIndex); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2243 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2244 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2245 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer(); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2246 | auto layerName = GetLayerName(graph, layerIndex); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2247 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 2248 | |
| 2249 | armnn::FullyConnectedDescriptor fullyConnectedDescriptor; |
| 2250 | fullyConnectedDescriptor.m_BiasEnabled = flatBufferDescriptor->biasEnabled(); |
| 2251 | fullyConnectedDescriptor.m_TransposeWeightMatrix = flatBufferDescriptor->transposeWeightsMatrix(); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 2252 | fullyConnectedDescriptor.m_ConstantWeights = flatBufferDescriptor->constantWeights(); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2253 | |
| 2254 | armnn::IConnectableLayer* layer; |
| 2255 | std::vector<unsigned int> ignoreSlots {}; |
| 2256 | |
| 2257 | // Weights and biases used to be always constant and were stored as members of the layer. This has changed and |
| 2258 | // they are now passed as inputs. If they are constant then they will be stored in a ConstantLayer. |
| 2259 | if (this->GetFeatureVersions(graph).m_ConstTensorsAsInputs <= 0) |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2260 | { |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2261 | // If the model stores weights and biases as members of the layer we have to read them from there |
| 2262 | // but add them to their own ConstantLayer for compatibility |
| 2263 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2264 | layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor, |
| 2265 | layerName.c_str()); |
| 2266 | |
| 2267 | armnn::ConstTensor weightsTensor = ToConstTensor(flatBufferLayer->weights()); |
| 2268 | auto weightsLayer = m_Network->AddConstantLayer(weightsTensor); |
| 2269 | weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); |
| 2270 | weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsTensor.GetInfo()); |
| 2271 | ignoreSlots.emplace_back(1u); |
| 2272 | |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 2273 | if (fullyConnectedDescriptor.m_BiasEnabled) |
| 2274 | { |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2275 | armnn::ConstTensor biasTensor = ToConstTensor(flatBufferLayer->biases()); |
| 2276 | auto biasLayer = m_Network->AddConstantLayer(biasTensor); |
| 2277 | biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2u)); |
| 2278 | biasLayer->GetOutputSlot(0).SetTensorInfo(biasTensor.GetInfo()); |
| 2279 | ignoreSlots.emplace_back(2u); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 2280 | } |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2281 | } |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2282 | else |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 2283 | { |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2284 | layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor, |
| 2285 | layerName.c_str()); |
| 2286 | uint32_t numInputs = fullyConnectedDescriptor.GetNumInputs(); |
| 2287 | CHECK_VALID_SIZE(inputs.size(), numInputs); |
Sadik Armagan | f0a6dec | 2021-03-25 07:46:55 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2290 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2291 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2292 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 2293 | RegisterInputSlots(graph, layerIndex, layer, ignoreSlots); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2294 | RegisterOutputSlots(graph, layerIndex, layer); |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2297 | void IDeserializer::DeserializerImpl::ParsePad(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2298 | { |
| 2299 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2300 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2301 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2302 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2303 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2304 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2305 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2306 | |
| 2307 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor(); |
| 2308 | auto flatBufferPadList = flatBufferDescriptor->padList(); |
Matthew Sloyan | 2e5d0b2 | 2021-10-21 14:05:31 +0100 | [diff] [blame] | 2309 | auto paddingMode = flatBufferDescriptor->paddingMode(); |
David Monahan | 3475781 | 2019-06-19 11:47:21 +0100 | [diff] [blame] | 2310 | float padValue = flatBufferDescriptor->padValue(); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2311 | |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 2312 | if (flatBufferPadList->size() % 2 != 0) |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2313 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 2314 | throw ParseException(fmt::format("The size of the pad list must be divisible by 2 {}", |
| 2315 | CHECK_LOCATION().AsString())); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | std::vector<std::pair<unsigned int, unsigned int>> padList; |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 2319 | padList.reserve(flatBufferPadList->size() / 2); |
| 2320 | for (unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2) |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2321 | { |
| 2322 | padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1)); |
| 2323 | } |
| 2324 | |
Matthew Sloyan | 2e5d0b2 | 2021-10-21 14:05:31 +0100 | [diff] [blame] | 2325 | armnn::PadDescriptor descriptor(padList, padValue, ToPaddingMode(paddingMode)); |
Nattapat Chaimanowong | ebb0f9c | 2019-03-01 12:14:06 +0000 | [diff] [blame] | 2326 | |
| 2327 | auto layerName = GetLayerName(graph, layerIndex); |
| 2328 | IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str()); |
| 2329 | |
| 2330 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2331 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2332 | |
| 2333 | RegisterInputSlots(graph, layerIndex, layer); |
| 2334 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2335 | } |
| 2336 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2337 | void IDeserializer::DeserializerImpl::ParsePermute(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2338 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2339 | CHECK_LAYERS(graph, 0, layerIndex); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2340 | |
| 2341 | auto dimsMapping = |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2342 | graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings(); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2343 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2344 | auto inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2345 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2346 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2347 | auto outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2348 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2349 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 2350 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2351 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 2352 | const armnn::PermuteDescriptor descriptor(armnn::PermutationVector(dimsMapping->data(), dimsMapping->size())); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2353 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2354 | IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str()); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2355 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2356 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2357 | RegisterInputSlots(graph, layerIndex, layer); |
| 2358 | RegisterOutputSlots(graph, layerIndex, layer); |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2361 | armnn::Pooling2dDescriptor IDeserializer::DeserializerImpl::GetPooling2dDescriptor(Pooling2dDescriptor pooling2dDesc, |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 2362 | unsigned int layerIndex) |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2363 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2364 | IgnoreUnused(layerIndex); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2365 | armnn::Pooling2dDescriptor desc; |
| 2366 | |
| 2367 | switch (pooling2dDesc->poolType()) |
| 2368 | { |
| 2369 | case PoolingAlgorithm_Average: |
| 2370 | { |
| 2371 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2372 | break; |
| 2373 | } |
| 2374 | case PoolingAlgorithm_Max: |
| 2375 | { |
| 2376 | desc.m_PoolType = armnn::PoolingAlgorithm::Max; |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2377 | break; |
| 2378 | } |
Teresa Charlin | 4c600de | 2021-03-11 21:59:43 +0000 | [diff] [blame] | 2379 | case PoolingAlgorithm_L2: |
| 2380 | { |
| 2381 | desc.m_PoolType = armnn::PoolingAlgorithm::L2; |
| 2382 | break; |
| 2383 | } |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2384 | default: |
| 2385 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2386 | throw ParseException("Unsupported pooling algorithm"); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | switch (pooling2dDesc->outputShapeRounding()) |
| 2391 | { |
| 2392 | case OutputShapeRounding_Floor: |
| 2393 | { |
| 2394 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Floor; |
| 2395 | break; |
| 2396 | } |
| 2397 | case OutputShapeRounding_Ceiling: |
| 2398 | { |
| 2399 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Ceiling; |
| 2400 | break; |
| 2401 | } |
| 2402 | default: |
| 2403 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2404 | throw ParseException("Unsupported output shape rounding"); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | switch (pooling2dDesc->paddingMethod()) |
| 2409 | { |
| 2410 | case PaddingMethod_Exclude: |
| 2411 | { |
| 2412 | desc.m_PaddingMethod = armnn::PaddingMethod::Exclude; |
| 2413 | break; |
| 2414 | } |
| 2415 | case PaddingMethod_IgnoreValue: |
| 2416 | { |
| 2417 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 2418 | break; |
| 2419 | } |
| 2420 | default: |
| 2421 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2422 | throw ParseException("Unsupported padding method"); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | switch (pooling2dDesc->dataLayout()) |
| 2427 | { |
| 2428 | case DataLayout_NCHW: |
| 2429 | { |
| 2430 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 2431 | break; |
| 2432 | } |
| 2433 | case DataLayout_NHWC: |
| 2434 | { |
| 2435 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 2436 | break; |
| 2437 | } |
| 2438 | default: |
| 2439 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2440 | throw ParseException("Unsupported data layout"); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | desc.m_PadRight = pooling2dDesc->padRight(); |
| 2445 | desc.m_PadLeft = pooling2dDesc->padLeft(); |
| 2446 | desc.m_PadBottom = pooling2dDesc->padBottom(); |
| 2447 | desc.m_PadTop = pooling2dDesc->padTop(); |
| 2448 | desc.m_StrideX = pooling2dDesc->strideX(); |
| 2449 | desc.m_StrideY = pooling2dDesc->strideY(); |
| 2450 | desc.m_PoolWidth = pooling2dDesc->poolWidth(); |
| 2451 | desc.m_PoolHeight = pooling2dDesc->poolHeight(); |
| 2452 | |
| 2453 | return desc; |
| 2454 | } |
| 2455 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2456 | armnn::Pooling3dDescriptor IDeserializer::DeserializerImpl::GetPooling3dDescriptor(Pooling3dDescriptor pooling3dDesc, |
| 2457 | unsigned int layerIndex) |
| 2458 | { |
| 2459 | IgnoreUnused(layerIndex); |
| 2460 | armnn::Pooling3dDescriptor desc; |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2461 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2462 | switch (pooling3dDesc->poolType()) |
| 2463 | { |
| 2464 | case PoolingAlgorithm_Average: |
| 2465 | { |
| 2466 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 2467 | break; |
| 2468 | } |
| 2469 | case PoolingAlgorithm_Max: |
| 2470 | { |
| 2471 | desc.m_PoolType = armnn::PoolingAlgorithm::Max; |
| 2472 | break; |
| 2473 | } |
| 2474 | case PoolingAlgorithm_L2: |
| 2475 | { |
| 2476 | desc.m_PoolType = armnn::PoolingAlgorithm::L2; |
| 2477 | break; |
| 2478 | } |
| 2479 | default: |
| 2480 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2481 | throw ParseException("Unsupported pooling algorithm"); |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | switch (pooling3dDesc->outputShapeRounding()) |
| 2486 | { |
| 2487 | case OutputShapeRounding_Floor: |
| 2488 | { |
| 2489 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Floor; |
| 2490 | break; |
| 2491 | } |
| 2492 | case OutputShapeRounding_Ceiling: |
| 2493 | { |
| 2494 | desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Ceiling; |
| 2495 | break; |
| 2496 | } |
| 2497 | default: |
| 2498 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2499 | throw ParseException("Unsupported output shape rounding"); |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | switch (pooling3dDesc->paddingMethod()) |
| 2504 | { |
| 2505 | case PaddingMethod_Exclude: |
| 2506 | { |
| 2507 | desc.m_PaddingMethod = armnn::PaddingMethod::Exclude; |
| 2508 | break; |
| 2509 | } |
| 2510 | case PaddingMethod_IgnoreValue: |
| 2511 | { |
| 2512 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 2513 | break; |
| 2514 | } |
| 2515 | default: |
| 2516 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2517 | throw ParseException("Unsupported padding method"); |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | switch (pooling3dDesc->dataLayout()) |
| 2522 | { |
| 2523 | case DataLayout_NCDHW: |
| 2524 | { |
| 2525 | desc.m_DataLayout = armnn::DataLayout::NCDHW; |
| 2526 | break; |
| 2527 | } |
| 2528 | case DataLayout_NDHWC: |
| 2529 | { |
| 2530 | desc.m_DataLayout = armnn::DataLayout::NDHWC; |
| 2531 | break; |
| 2532 | } |
| 2533 | default: |
| 2534 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2535 | throw ParseException("Unsupported data layout"); |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | desc.m_PadRight = pooling3dDesc->padRight(); |
| 2540 | desc.m_PadLeft = pooling3dDesc->padLeft(); |
| 2541 | desc.m_PadBottom = pooling3dDesc->padBottom(); |
| 2542 | desc.m_PadTop = pooling3dDesc->padTop(); |
| 2543 | desc.m_PadFront = pooling3dDesc->padFront(); |
| 2544 | desc.m_PadBack = pooling3dDesc->padBack(); |
| 2545 | desc.m_StrideX = pooling3dDesc->strideX(); |
| 2546 | desc.m_StrideY = pooling3dDesc->strideY(); |
| 2547 | desc.m_StrideZ = pooling3dDesc->strideZ(); |
| 2548 | desc.m_PoolWidth = pooling3dDesc->poolWidth(); |
| 2549 | desc.m_PoolHeight = pooling3dDesc->poolHeight(); |
| 2550 | desc.m_PoolDepth = pooling3dDesc->poolDepth(); |
| 2551 | |
| 2552 | return desc; |
| 2553 | } |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2554 | |
| 2555 | void IDeserializer::DeserializerImpl::ParsePooling2d(GraphPtr graph, unsigned int layerIndex) |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2556 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2557 | CHECK_LAYERS(graph, 0, layerIndex); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2558 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2559 | auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor(); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2560 | auto inputs = GetInputs(graph, layerIndex); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2561 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2562 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2563 | auto outputs = GetOutputs(graph, layerIndex); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2564 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2565 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 2566 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2567 | auto pooling2dDescriptor = GetPooling2dDescriptor(pooling2dDes, layerIndex); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2568 | auto layerName = GetLayerName(graph, layerIndex); |
| 2569 | IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str()); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2570 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2571 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2572 | RegisterInputSlots(graph, layerIndex, layer); |
| 2573 | RegisterOutputSlots(graph, layerIndex, layer); |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
Tamas Nyiri | d998a1c | 2021-11-05 14:55:33 +0000 | [diff] [blame] | 2576 | void IDeserializer::DeserializerImpl::ParsePooling3d(GraphPtr graph, unsigned int layerIndex) |
| 2577 | { |
| 2578 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2579 | |
| 2580 | auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor(); |
| 2581 | auto inputs = GetInputs(graph, layerIndex); |
| 2582 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2583 | |
| 2584 | auto outputs = GetOutputs(graph, layerIndex); |
| 2585 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2586 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 2587 | |
| 2588 | auto pooling3dDescriptor = GetPooling3dDescriptor(pooling3dDes, layerIndex); |
| 2589 | auto layerName = GetLayerName(graph, layerIndex); |
| 2590 | IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str()); |
| 2591 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2592 | |
| 2593 | RegisterInputSlots(graph, layerIndex, layer); |
| 2594 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2595 | } |
| 2596 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2597 | void IDeserializer::DeserializerImpl::ParseQuantize(GraphPtr graph, unsigned int layerIndex) |
Derek Lamberti | 87acb27 | 2019-03-27 16:51:31 +0000 | [diff] [blame] | 2598 | { |
| 2599 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2600 | |
| 2601 | auto inputs = GetInputs(graph, layerIndex); |
| 2602 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2603 | |
| 2604 | auto outputs = GetOutputs(graph, layerIndex); |
| 2605 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2606 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 2607 | |
| 2608 | auto layerName = GetLayerName(graph, layerIndex); |
| 2609 | IConnectableLayer* layer = m_Network->AddQuantizeLayer(layerName.c_str()); |
| 2610 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 2611 | |
| 2612 | RegisterInputSlots(graph, layerIndex, layer); |
| 2613 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2614 | } |
| 2615 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2616 | armnn::TensorInfo IDeserializer::DeserializerImpl::OutputShapeOfReshape(const armnn::TensorInfo& inputTensorInfo, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2617 | const std::vector<uint32_t>& targetDimsIn) |
| 2618 | { |
| 2619 | std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end()); |
| 2620 | const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1); |
| 2621 | |
| 2622 | if (stretchDim != targetDimsIn.end()) |
| 2623 | { |
| 2624 | if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end()) |
| 2625 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 2626 | throw ParseException(fmt::format("At most one component of shape can be -1 {}", |
| 2627 | CHECK_LOCATION().AsString())); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | auto targetNumElements = |
Matthew Sloyan | 0663d66 | 2020-09-14 11:47:26 +0100 | [diff] [blame] | 2631 | armnn::numeric_cast<unsigned int>( |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2632 | std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>())); |
| 2633 | |
| 2634 | auto stretchIndex = static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim)); |
Tianle Cheng | 2077348 | 2023-10-03 12:01:11 +0100 | [diff] [blame] | 2635 | if (targetNumElements == 0) |
| 2636 | { |
| 2637 | if (inputTensorInfo.GetNumElements() == 0) |
| 2638 | { |
| 2639 | outputDims[stretchIndex] = 0; |
| 2640 | } |
| 2641 | else |
| 2642 | { |
| 2643 | throw ParseException( |
| 2644 | fmt::format("Input to reshape is a tensor with elements, but the requested shape has 0. {}", |
| 2645 | CHECK_LOCATION().AsString())); |
| 2646 | } |
| 2647 | } |
| 2648 | else |
| 2649 | { |
| 2650 | outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements; |
| 2651 | } |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | TensorShape outputShape = TensorShape(static_cast<unsigned int>(outputDims.size()), outputDims.data()); |
| 2655 | |
| 2656 | armnn::TensorInfo reshapeInfo = inputTensorInfo; |
| 2657 | reshapeInfo.SetShape(outputShape); |
| 2658 | |
| 2659 | return reshapeInfo; |
| 2660 | } |
| 2661 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2662 | void IDeserializer::DeserializerImpl::ParseRank(GraphPtr graph, unsigned int layerIndex) |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2663 | { |
| 2664 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2665 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2666 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2667 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2668 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2669 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2670 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2671 | |
| 2672 | auto layerName = GetLayerName(graph, layerIndex); |
| 2673 | IConnectableLayer* layer = m_Network->AddRankLayer( layerName.c_str()); |
| 2674 | |
| 2675 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2676 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2677 | |
| 2678 | RegisterInputSlots(graph, layerIndex, layer); |
| 2679 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2680 | } |
| 2681 | |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2682 | void IDeserializer::DeserializerImpl::ParseReduce(GraphPtr graph, unsigned int layerIndex) |
| 2683 | { |
| 2684 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2685 | CHECK_LOCATION(); |
| 2686 | |
| 2687 | auto inputs = GetInputs(graph, layerIndex); |
| 2688 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2689 | |
| 2690 | auto outputs = GetOutputs(graph, layerIndex); |
| 2691 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2692 | |
| 2693 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ReduceLayer(); |
| 2694 | auto fbDescriptor = fbLayer->descriptor(); |
| 2695 | auto flatBufferAxis = fbDescriptor->axis(); |
| 2696 | |
| 2697 | armnn::ReduceDescriptor descriptor; |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2698 | descriptor.m_KeepDims = fbDescriptor->keepDims(); |
| 2699 | descriptor.m_vAxis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end()); |
| 2700 | descriptor.m_ReduceOperation = ToReduceOperation(fbDescriptor->reduceOperation()); |
| 2701 | |
| 2702 | const std::string& layerName = GetLayerName(graph, layerIndex); |
| 2703 | IConnectableLayer* layer = m_Network->AddReduceLayer(descriptor, layerName.c_str()); |
| 2704 | |
| 2705 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2706 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2707 | |
| 2708 | RegisterInputSlots(graph, layerIndex, layer); |
| 2709 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2710 | } |
| 2711 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2712 | void IDeserializer::DeserializerImpl::ParseReshape(GraphPtr graph, unsigned int layerIndex) |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2713 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2714 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2715 | auto inputs = GetInputs(graph, layerIndex); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2716 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2717 | auto outputs = GetOutputs(graph, layerIndex); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2718 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2719 | |
| 2720 | armnn::TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]); |
| 2721 | armnn::TensorInfo actualOutputTensorInfo = ToTensorInfo(outputs[0]); |
| 2722 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2723 | const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape(); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2724 | std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size()); |
| 2725 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2726 | armnn::TensorInfo reshapeOutputTensorInfo = DeserializerImpl::OutputShapeOfReshape(inputTensorInfo, outputDims); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2727 | const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape(); |
| 2728 | |
| 2729 | const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(), |
| 2730 | outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size()); |
| 2731 | |
| 2732 | if (inputs.size() > 1 && !CheckShape(reshapeOutputTensorShape, expectedDims)) |
| 2733 | { |
| 2734 | std::stringstream ss; |
| 2735 | ss << "New shape defined in reshape parameters " |
| 2736 | << reshapeOutputTensorShape |
| 2737 | << " does not equal output shape " |
| 2738 | << actualOutputTensorInfo.GetShape() |
| 2739 | << ": " |
| 2740 | << CHECK_LOCATION().AsString(); |
| 2741 | throw ParseException(ss.str()); |
| 2742 | } |
| 2743 | |
| 2744 | armnn::ReshapeDescriptor reshapeDesc; |
| 2745 | reshapeDesc.m_TargetShape = reshapeOutputTensorShape; |
| 2746 | |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2747 | auto layerName = GetLayerName(graph, layerIndex); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2748 | IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str()); |
| 2749 | layer->GetOutputSlot(0).SetTensorInfo(reshapeOutputTensorInfo); |
| 2750 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2751 | RegisterInputSlots(graph, layerIndex, layer); |
| 2752 | RegisterOutputSlots(graph, layerIndex, layer); |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2755 | void IDeserializer::DeserializerImpl::ParseResize(GraphPtr graph, unsigned int layerIndex) |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2756 | { |
| 2757 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2758 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2759 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2760 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2761 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2762 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2763 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2764 | |
| 2765 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor(); |
| 2766 | |
| 2767 | armnn::ResizeDescriptor descriptor; |
| 2768 | descriptor.m_TargetWidth = flatBufferDescriptor->targetWidth(); |
| 2769 | descriptor.m_TargetHeight = flatBufferDescriptor->targetHeight(); |
| 2770 | descriptor.m_Method = ToResizeMethod(flatBufferDescriptor->method()); |
| 2771 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
David Monahan | 4a0c9b9 | 2020-05-30 09:48:39 +0100 | [diff] [blame] | 2772 | descriptor.m_AlignCorners = flatBufferDescriptor->alignCorners(); |
| 2773 | descriptor.m_HalfPixelCenters = flatBufferDescriptor->halfPixelCenters(); |
FinnWilliamsArm | 6fb339a | 2019-06-28 15:07:10 +0100 | [diff] [blame] | 2774 | |
| 2775 | auto layerName = GetLayerName(graph, layerIndex); |
| 2776 | IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str()); |
| 2777 | |
| 2778 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2779 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2780 | |
| 2781 | RegisterInputSlots(graph, layerIndex, layer); |
| 2782 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2783 | } |
| 2784 | |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 2785 | void IDeserializer::DeserializerImpl::ParseReverseV2(GraphPtr graph, unsigned int layerIndex) |
| 2786 | { |
| 2787 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2788 | |
| 2789 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 2790 | CHECK_VALID_SIZE(inputs.size(), 2); |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 2791 | |
| 2792 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
| 2793 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2794 | |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 2795 | auto layerName = GetLayerName(graph, layerIndex); |
Tracy Narine | bb8d759 | 2023-07-13 16:50:54 +0100 | [diff] [blame] | 2796 | IConnectableLayer* layer = m_Network->AddReverseV2Layer(layerName.c_str()); |
Tracy Narine | 944fb50 | 2023-07-04 15:08:57 +0100 | [diff] [blame] | 2797 | |
| 2798 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2799 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2800 | |
| 2801 | RegisterInputSlots(graph, layerIndex, layer); |
| 2802 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2803 | } |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2804 | |
| 2805 | /// @Note The ResizeBiliniar operation was deprecated and removed in favor of the Resize operation. |
| 2806 | /// This function is kept for backwards compatibility. |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2807 | void IDeserializer::DeserializerImpl::ParseResizeBilinear(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2808 | { |
| 2809 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2810 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2811 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2812 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2813 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2814 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2815 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2816 | |
| 2817 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor(); |
| 2818 | |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 2819 | armnn::ResizeDescriptor descriptor; |
| 2820 | descriptor.m_TargetWidth = flatBufferDescriptor->targetWidth(); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2821 | descriptor.m_TargetHeight = flatBufferDescriptor->targetHeight(); |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 2822 | descriptor.m_Method = armnn::ResizeMethod::Bilinear; |
| 2823 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
David Monahan | 4a0c9b9 | 2020-05-30 09:48:39 +0100 | [diff] [blame] | 2824 | descriptor.m_AlignCorners = flatBufferDescriptor->alignCorners(); |
| 2825 | descriptor.m_HalfPixelCenters = flatBufferDescriptor->halfPixelCenters(); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2826 | |
| 2827 | auto layerName = GetLayerName(graph, layerIndex); |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 2828 | IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str()); |
Nattapat Chaimanowong | 6522cdc | 2019-03-01 16:14:13 +0000 | [diff] [blame] | 2829 | |
| 2830 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2831 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2832 | |
| 2833 | RegisterInputSlots(graph, layerIndex, layer); |
| 2834 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2835 | } |
| 2836 | |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 2837 | void IDeserializer::DeserializerImpl::ParseShape(GraphPtr graph, unsigned int layerIndex) |
| 2838 | { |
| 2839 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2840 | |
| 2841 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
| 2842 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2843 | |
| 2844 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
| 2845 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2846 | |
| 2847 | auto layerName = GetLayerName(graph, layerIndex); |
| 2848 | IConnectableLayer* layer = m_Network->AddShapeLayer( layerName.c_str()); |
| 2849 | |
| 2850 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2851 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2852 | |
| 2853 | RegisterInputSlots(graph, layerIndex, layer); |
| 2854 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2855 | } |
| 2856 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2857 | void IDeserializer::DeserializerImpl::ParseSoftmax(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2858 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2859 | CHECK_LAYERS(graph, 0, layerIndex); |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2860 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2861 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2862 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2863 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2864 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2865 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2866 | |
| 2867 | armnn::SoftmaxDescriptor descriptor; |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2868 | descriptor.m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta(); |
Sadik Armagan | fd0cae3 | 2021-11-08 17:18:31 +0000 | [diff] [blame] | 2869 | descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->axis(); |
Éanna Ó Catháin | 633f859 | 2019-02-25 16:26:29 +0000 | [diff] [blame] | 2870 | auto layerName = GetLayerName(graph, layerIndex); |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2871 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2872 | IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str()); |
| 2873 | |
| 2874 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2875 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2876 | |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 2877 | RegisterInputSlots(graph, layerIndex, layer); |
| 2878 | RegisterOutputSlots(graph, layerIndex, layer); |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 2879 | } |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 2880 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2881 | void IDeserializer::DeserializerImpl::ParseSpaceToBatchNd(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2882 | { |
| 2883 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2884 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2885 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2886 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2887 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2888 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2889 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2890 | |
| 2891 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor(); |
| 2892 | auto flatBufferPadList = flatBufferDescriptor->padList(); |
| 2893 | auto flatBufferBlockShape = flatBufferDescriptor->blockShape(); |
| 2894 | |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 2895 | if (flatBufferPadList->size() % 2 != 0) |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2896 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 2897 | throw ParseException(fmt::format("The size of the pad list must be divisible by 2 {}", |
| 2898 | CHECK_LOCATION().AsString())); |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | std::vector<std::pair<unsigned int, unsigned int>> padList; |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 2902 | padList.reserve(flatBufferPadList->size() / 2); |
| 2903 | for (unsigned int i = 0; i < flatBufferPadList->size() - 1; i += 2) |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 2904 | { |
| 2905 | padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1)); |
| 2906 | } |
| 2907 | |
| 2908 | armnn::SpaceToBatchNdDescriptor descriptor; |
| 2909 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
| 2910 | descriptor.m_BlockShape = |
| 2911 | std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end()); |
| 2912 | descriptor.m_PadList = padList; |
| 2913 | |
| 2914 | auto layerName = GetLayerName(graph, layerIndex); |
| 2915 | IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str()); |
| 2916 | |
| 2917 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2918 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2919 | |
| 2920 | RegisterInputSlots(graph, layerIndex, layer); |
| 2921 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2922 | } |
| 2923 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2924 | void IDeserializer::DeserializerImpl::ParseSpaceToDepth(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2925 | { |
| 2926 | CHECK_LAYERS(graph, 0, layerIndex); |
| 2927 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2928 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2929 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 2930 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2931 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Aron Virginas-Tar | aa06714 | 2019-06-11 16:01:44 +0100 | [diff] [blame] | 2932 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 2933 | |
| 2934 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor(); |
| 2935 | |
| 2936 | armnn::SpaceToDepthDescriptor descriptor; |
| 2937 | descriptor.m_BlockSize = flatBufferDescriptor->blockSize(); |
| 2938 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
| 2939 | |
| 2940 | auto layerName = GetLayerName(graph, layerIndex); |
| 2941 | IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str()); |
| 2942 | |
| 2943 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 2944 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 2945 | |
| 2946 | RegisterInputSlots(graph, layerIndex, layer); |
| 2947 | RegisterOutputSlots(graph, layerIndex, layer); |
| 2948 | } |
| 2949 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 2950 | armnn::NormalizationDescriptor IDeserializer::DeserializerImpl::GetNormalizationDescriptor( |
| 2951 | NormalizationDescriptorPtr normalizationDescriptor, |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 2952 | unsigned int layerIndex) |
| 2953 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2954 | IgnoreUnused(layerIndex); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 2955 | armnn::NormalizationDescriptor desc; |
| 2956 | |
| 2957 | switch (normalizationDescriptor->normChannelType()) |
| 2958 | { |
| 2959 | case NormalizationAlgorithmChannel_Across: |
| 2960 | { |
| 2961 | desc.m_NormChannelType = armnn::NormalizationAlgorithmChannel::Across; |
| 2962 | break; |
| 2963 | } |
| 2964 | case NormalizationAlgorithmChannel_Within: |
| 2965 | { |
| 2966 | desc.m_NormChannelType = armnn::NormalizationAlgorithmChannel::Within; |
| 2967 | break; |
| 2968 | } |
| 2969 | default: |
| 2970 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2971 | throw ParseException("Unsupported normalization channel type"); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | switch (normalizationDescriptor->normMethodType()) |
| 2976 | { |
| 2977 | case NormalizationAlgorithmMethod_LocalBrightness: |
| 2978 | { |
| 2979 | desc.m_NormMethodType = armnn::NormalizationAlgorithmMethod::LocalBrightness; |
| 2980 | break; |
| 2981 | } |
| 2982 | case NormalizationAlgorithmMethod_LocalContrast: |
| 2983 | { |
| 2984 | desc.m_NormMethodType = armnn::NormalizationAlgorithmMethod::LocalContrast; |
| 2985 | break; |
| 2986 | } |
| 2987 | default: |
| 2988 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 2989 | throw ParseException("Unsupported normalization method type"); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | switch (normalizationDescriptor->dataLayout()) |
| 2994 | { |
| 2995 | case DataLayout_NCHW: |
| 2996 | { |
| 2997 | desc.m_DataLayout = armnn::DataLayout::NCHW; |
| 2998 | break; |
| 2999 | } |
| 3000 | case DataLayout_NHWC: |
| 3001 | { |
| 3002 | desc.m_DataLayout = armnn::DataLayout::NHWC; |
| 3003 | break; |
| 3004 | } |
| 3005 | default: |
| 3006 | { |
Jim Flynn | b53f52a | 2023-09-17 10:00:25 +0100 | [diff] [blame] | 3007 | throw ParseException("Unsupported data layout"); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | desc.m_Alpha = normalizationDescriptor->alpha(); |
| 3012 | desc.m_Beta = normalizationDescriptor->beta(); |
| 3013 | desc.m_K = normalizationDescriptor->k(); |
| 3014 | desc.m_NormSize = normalizationDescriptor->normSize(); |
| 3015 | |
| 3016 | return desc; |
| 3017 | } |
| 3018 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3019 | void IDeserializer::DeserializerImpl::ParseNormalization(GraphPtr graph, unsigned int layerIndex) |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 3020 | { |
| 3021 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3022 | |
| 3023 | auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor(); |
| 3024 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3025 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 3026 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3027 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3028 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nina Drozd | 5772878 | 2019-02-27 10:53:27 +0000 | [diff] [blame] | 3029 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3030 | |
| 3031 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 3032 | |
| 3033 | auto normalizationDescriptor = GetNormalizationDescriptor(normalizationDes, layerIndex); |
| 3034 | auto layerName = GetLayerName(graph, layerIndex); |
| 3035 | |
| 3036 | IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str()); |
| 3037 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 3038 | |
| 3039 | RegisterInputSlots(graph, layerIndex, layer); |
| 3040 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3041 | } |
| 3042 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3043 | void IDeserializer::DeserializerImpl::ParseRsqrt(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | 8b42a38 | 2019-03-01 14:24:49 +0000 | [diff] [blame] | 3044 | { |
| 3045 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3046 | auto inputs = GetInputs(graph, layerIndex); |
| 3047 | CHECK_LOCATION(); |
| 3048 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3049 | |
| 3050 | auto outputs = GetOutputs(graph, layerIndex); |
| 3051 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3052 | |
| 3053 | auto layerName = GetLayerName(graph, layerIndex); |
Sadik Armagan | 8b42a38 | 2019-03-01 14:24:49 +0000 | [diff] [blame] | 3054 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 3055 | armnn::ElementwiseUnaryDescriptor descriptor(armnn::UnaryOperation::Rsqrt); |
| 3056 | IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str()); |
Sadik Armagan | 8b42a38 | 2019-03-01 14:24:49 +0000 | [diff] [blame] | 3057 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3058 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3059 | |
| 3060 | RegisterInputSlots(graph, layerIndex, layer); |
| 3061 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3062 | } |
| 3063 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3064 | void IDeserializer::DeserializerImpl::ParseSlice(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 3065 | { |
| 3066 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3067 | |
| 3068 | auto inputs = GetInputs(graph, layerIndex); |
| 3069 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3070 | |
| 3071 | auto outputs = GetOutputs(graph, layerIndex); |
| 3072 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3073 | |
| 3074 | auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor(); |
| 3075 | |
| 3076 | auto fbBegin = fbDescriptor->begin(); |
| 3077 | auto fbSize = fbDescriptor->size(); |
| 3078 | |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 3079 | if (fbBegin->size() != fbSize->size()) |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 3080 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 3081 | throw ParseException(fmt::format("Begin and size descriptors must have the same length {}", |
| 3082 | CHECK_LOCATION().AsString())); |
Aron Virginas-Tar | 2fda80b | 2019-09-18 13:36:52 +0100 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | armnn::SliceDescriptor descriptor; |
| 3086 | descriptor.m_Begin.insert(descriptor.m_Begin.end(), fbBegin->begin(), fbBegin->end()); |
| 3087 | descriptor.m_Size.insert(descriptor.m_Size.end(), fbSize->begin(), fbSize->end()); |
| 3088 | |
| 3089 | auto layerName = GetLayerName(graph, layerIndex); |
| 3090 | IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str()); |
| 3091 | |
| 3092 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3093 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3094 | |
| 3095 | RegisterInputSlots(graph, layerIndex, layer); |
| 3096 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3097 | } |
| 3098 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3099 | void IDeserializer::DeserializerImpl::ParseStridedSlice(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 3100 | { |
| 3101 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3102 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3103 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 3104 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3105 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3106 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 3107 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3108 | |
| 3109 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor(); |
| 3110 | |
| 3111 | auto flatBufferBegin = flatBufferDescriptor->begin(); |
| 3112 | auto flatBufferEnd = flatBufferDescriptor->end(); |
| 3113 | auto flatBufferStride = flatBufferDescriptor->stride(); |
| 3114 | |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 3115 | if (!(flatBufferBegin->size() == flatBufferEnd->size() && |
| 3116 | flatBufferBegin->size() == flatBufferStride->size())) |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 3117 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 3118 | throw ParseException(fmt::format("The size of the begin, end, and stride must be equal {}", |
| 3119 | CHECK_LOCATION().AsString())); |
Nattapat Chaimanowong | b348521 | 2019-03-04 12:35:39 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end()); |
| 3123 | std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end()); |
| 3124 | std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end()); |
| 3125 | |
| 3126 | armnn::StridedSliceDescriptor descriptor(begin, end, stride); |
| 3127 | descriptor.m_BeginMask = flatBufferDescriptor->beginMask(); |
| 3128 | descriptor.m_EndMask = flatBufferDescriptor->endMask(); |
| 3129 | descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask(); |
| 3130 | descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask(); |
| 3131 | descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask(); |
| 3132 | descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); |
| 3133 | |
| 3134 | auto layerName = GetLayerName(graph, layerIndex); |
| 3135 | IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str()); |
| 3136 | |
| 3137 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3138 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3139 | |
| 3140 | RegisterInputSlots(graph, layerIndex, layer); |
| 3141 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3142 | } |
| 3143 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3144 | void IDeserializer::DeserializerImpl::ParseSubtraction(GraphPtr graph, unsigned int layerIndex) |
Conor Kennedy | da1f975 | 2019-03-01 14:37:12 +0000 | [diff] [blame] | 3145 | { |
| 3146 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3147 | auto inputs = GetInputs(graph, layerIndex); |
| 3148 | CHECK_LOCATION(); |
| 3149 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3150 | |
| 3151 | auto outputs = GetOutputs(graph, layerIndex); |
| 3152 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3153 | |
| 3154 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 3ec3077 | 2023-03-08 13:47:17 +0000 | [diff] [blame] | 3155 | armnn::ElementwiseBinaryDescriptor descriptor(armnn::BinaryOperation::Sub); |
| 3156 | IConnectableLayer* layer = m_Network->AddElementwiseBinaryLayer(descriptor, layerName.c_str()); |
Conor Kennedy | da1f975 | 2019-03-01 14:37:12 +0000 | [diff] [blame] | 3157 | |
| 3158 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3159 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3160 | |
| 3161 | RegisterInputSlots(graph, layerIndex, layer); |
| 3162 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3163 | } |
| 3164 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3165 | void IDeserializer::DeserializerImpl::ParseGather(GraphPtr graph, unsigned int layerIndex) |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3166 | { |
| 3167 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3168 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3169 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3170 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3171 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3172 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3173 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3174 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 3175 | armnn::GatherDescriptor descriptor; |
| 3176 | descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_GatherLayer()->descriptor()->axis(); |
| 3177 | |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3178 | auto layerName = GetLayerName(graph, layerIndex); |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 3179 | IConnectableLayer* layer = m_Network->AddGatherLayer(descriptor, layerName.c_str()); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3180 | |
| 3181 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3182 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3183 | |
| 3184 | RegisterInputSlots(graph, layerIndex, layer); |
| 3185 | RegisterOutputSlots(graph, layerIndex, layer); |
Saoirse Stewart | a1ed73a | 2019-03-04 13:40:12 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
Teresa Charlin | 6966bfa | 2022-04-25 17:14:50 +0100 | [diff] [blame] | 3188 | void IDeserializer::DeserializerImpl::ParseGatherNd(GraphPtr graph, unsigned int layerIndex) |
| 3189 | { |
| 3190 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3191 | |
| 3192 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
| 3193 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3194 | |
| 3195 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
| 3196 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3197 | |
| 3198 | auto layerName = GetLayerName(graph, layerIndex); |
| 3199 | IConnectableLayer* layer = m_Network->AddGatherNdLayer(layerName.c_str()); |
| 3200 | |
| 3201 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3202 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3203 | |
| 3204 | RegisterInputSlots(graph, layerIndex, layer); |
| 3205 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3206 | } |
| 3207 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3208 | void IDeserializer::DeserializerImpl::ParseMean(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | ac97c8c | 2019-03-04 17:44:21 +0000 | [diff] [blame] | 3209 | { |
| 3210 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3211 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3212 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Sadik Armagan | ac97c8c | 2019-03-04 17:44:21 +0000 | [diff] [blame] | 3213 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3214 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3215 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Sadik Armagan | ac97c8c | 2019-03-04 17:44:21 +0000 | [diff] [blame] | 3216 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3217 | |
| 3218 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor(); |
| 3219 | auto flatBufferAxis = flatBufferDescriptor->axis(); |
| 3220 | auto flatBufferKeepDims = flatBufferDescriptor->keepDims(); |
| 3221 | |
| 3222 | armnn::MeanDescriptor descriptor; |
| 3223 | descriptor.m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end()); |
| 3224 | descriptor.m_KeepDims = flatBufferKeepDims; |
| 3225 | |
| 3226 | auto layerName = GetLayerName(graph, layerIndex); |
| 3227 | IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str()); |
| 3228 | |
| 3229 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3230 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3231 | |
| 3232 | RegisterInputSlots(graph, layerIndex, layer); |
| 3233 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3234 | } |
| 3235 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3236 | void IDeserializer::DeserializerImpl::ParseSplitter(GraphPtr graph, unsigned int layerIndex) |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 3237 | { |
| 3238 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3239 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3240 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 3241 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3242 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3243 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 3244 | |
| 3245 | auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor(); |
| 3246 | auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes(); |
| 3247 | auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins(); |
| 3248 | auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins(); |
| 3249 | uint32_t numViews = flatBufferOriginsDescriptor->numViews(); |
| 3250 | uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions(); |
| 3251 | |
| 3252 | // Check numViews and numDimensions corresponds to the ones already serialized ... |
| 3253 | // numViews == flatBufferViewSizes.size(); |
| 3254 | // foreach: numDimensions == flatBufferViewSizes[x].size(); |
| 3255 | |
| 3256 | armnn::ViewsDescriptor viewsDescriptor(numViews, numDimensions); |
| 3257 | for(unsigned int vIdx = 0; vIdx < numViews; ++vIdx) |
| 3258 | { |
| 3259 | for (unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx) |
| 3260 | { |
| 3261 | viewsDescriptor.SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx)); |
| 3262 | viewsDescriptor.SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx)); |
| 3263 | } |
| 3264 | } |
| 3265 | |
Mike Kelly | 363b572 | 2023-10-11 14:25:50 +0100 | [diff] [blame] | 3266 | if (flatBufferViewsDescriptor->hasAxis()) |
| 3267 | { |
| 3268 | viewsDescriptor.SetAxis(flatBufferViewsDescriptor->axis()); |
| 3269 | } |
| 3270 | |
Jim Flynn | 18ce338 | 2019-03-08 11:08:30 +0000 | [diff] [blame] | 3271 | auto layerName = GetLayerName(graph, layerIndex); |
| 3272 | IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str()); |
| 3273 | |
| 3274 | // I could have as many outputs as views ... |
| 3275 | for(unsigned int vIdx = 0; vIdx < numViews; ++vIdx) |
| 3276 | { |
| 3277 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[vIdx]); |
| 3278 | layer->GetOutputSlot(vIdx).SetTensorInfo(outputTensorInfo); |
| 3279 | } |
| 3280 | |
| 3281 | RegisterInputSlots(graph, layerIndex, layer); |
| 3282 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3283 | } |
| 3284 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3285 | armnn::LstmDescriptor IDeserializer::DeserializerImpl::GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor) |
Jim Flynn | 11af375 | 2019-03-19 17:22:29 +0000 | [diff] [blame] | 3286 | { |
| 3287 | armnn::LstmDescriptor desc; |
| 3288 | |
| 3289 | desc.m_ActivationFunc = lstmDescriptor->activationFunc(); |
| 3290 | desc.m_ClippingThresCell = lstmDescriptor->clippingThresCell(); |
| 3291 | desc.m_ClippingThresProj = lstmDescriptor->clippingThresProj(); |
| 3292 | desc.m_CifgEnabled = lstmDescriptor->cifgEnabled(); |
| 3293 | desc.m_PeepholeEnabled = lstmDescriptor->peepholeEnabled(); |
| 3294 | desc.m_ProjectionEnabled = lstmDescriptor->projectionEnabled(); |
Jan Eilers | f8c6297 | 2019-07-17 11:07:49 +0100 | [diff] [blame] | 3295 | desc.m_LayerNormEnabled = lstmDescriptor->layerNormEnabled(); |
Jim Flynn | 11af375 | 2019-03-19 17:22:29 +0000 | [diff] [blame] | 3296 | |
| 3297 | return desc; |
| 3298 | } |
| 3299 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3300 | void IDeserializer::DeserializerImpl::ParseLstm(GraphPtr graph, unsigned int layerIndex) |
Jim Flynn | 11af375 | 2019-03-19 17:22:29 +0000 | [diff] [blame] | 3301 | { |
| 3302 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3303 | |
| 3304 | auto inputs = GetInputs(graph, layerIndex); |
| 3305 | CHECK_VALID_SIZE(inputs.size(), 3); |
| 3306 | |
| 3307 | auto outputs = GetOutputs(graph, layerIndex); |
| 3308 | CHECK_VALID_SIZE(outputs.size(), 4); |
| 3309 | |
| 3310 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer(); |
| 3311 | auto layerName = GetLayerName(graph, layerIndex); |
| 3312 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 3313 | auto flatBufferInputParams = flatBufferLayer->inputParams(); |
| 3314 | |
| 3315 | auto lstmDescriptor = GetLstmDescriptor(flatBufferDescriptor); |
| 3316 | |
| 3317 | armnn::LstmInputParams lstmInputParams; |
| 3318 | |
| 3319 | armnn::ConstTensor inputToForgetWeights = ToConstTensor(flatBufferInputParams->inputToForgetWeights()); |
| 3320 | armnn::ConstTensor inputToCellWeights = ToConstTensor(flatBufferInputParams->inputToCellWeights()); |
| 3321 | armnn::ConstTensor inputToOutputWeights = ToConstTensor(flatBufferInputParams->inputToOutputWeights()); |
| 3322 | armnn::ConstTensor recurrentToForgetWeights = ToConstTensor(flatBufferInputParams->recurrentToForgetWeights()); |
| 3323 | armnn::ConstTensor recurrentToCellWeights = ToConstTensor(flatBufferInputParams->recurrentToCellWeights()); |
| 3324 | armnn::ConstTensor recurrentToOutputWeights = ToConstTensor(flatBufferInputParams->recurrentToOutputWeights()); |
| 3325 | armnn::ConstTensor forgetGateBias = ToConstTensor(flatBufferInputParams->forgetGateBias()); |
| 3326 | armnn::ConstTensor cellBias = ToConstTensor(flatBufferInputParams->cellBias()); |
| 3327 | armnn::ConstTensor outputGateBias = ToConstTensor(flatBufferInputParams->outputGateBias()); |
| 3328 | |
| 3329 | lstmInputParams.m_InputToForgetWeights = &inputToForgetWeights; |
| 3330 | lstmInputParams.m_InputToCellWeights = &inputToCellWeights; |
| 3331 | lstmInputParams.m_InputToOutputWeights = &inputToOutputWeights; |
| 3332 | lstmInputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeights; |
| 3333 | lstmInputParams.m_RecurrentToCellWeights = &recurrentToCellWeights; |
| 3334 | lstmInputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeights; |
| 3335 | lstmInputParams.m_ForgetGateBias = &forgetGateBias; |
| 3336 | lstmInputParams.m_CellBias = &cellBias; |
| 3337 | lstmInputParams.m_OutputGateBias = &outputGateBias; |
| 3338 | |
| 3339 | armnn::ConstTensor inputToInputWeights; |
| 3340 | armnn::ConstTensor recurrentToInputWeights; |
| 3341 | armnn::ConstTensor cellToInputWeights; |
| 3342 | armnn::ConstTensor inputGateBias; |
| 3343 | if (!lstmDescriptor.m_CifgEnabled) |
| 3344 | { |
| 3345 | inputToInputWeights = ToConstTensor(flatBufferInputParams->inputToInputWeights()); |
| 3346 | recurrentToInputWeights = ToConstTensor(flatBufferInputParams->recurrentToInputWeights()); |
| 3347 | cellToInputWeights = ToConstTensor(flatBufferInputParams->cellToInputWeights()); |
| 3348 | inputGateBias = ToConstTensor(flatBufferInputParams->inputGateBias()); |
| 3349 | |
| 3350 | lstmInputParams.m_InputToInputWeights = &inputToInputWeights; |
| 3351 | lstmInputParams.m_RecurrentToInputWeights = &recurrentToInputWeights; |
| 3352 | lstmInputParams.m_CellToInputWeights = &cellToInputWeights; |
| 3353 | lstmInputParams.m_InputGateBias = &inputGateBias; |
| 3354 | } |
| 3355 | |
| 3356 | armnn::ConstTensor projectionWeights; |
| 3357 | armnn::ConstTensor projectionBias; |
| 3358 | if (lstmDescriptor.m_ProjectionEnabled) |
| 3359 | { |
| 3360 | projectionWeights = ToConstTensor(flatBufferInputParams->projectionWeights()); |
| 3361 | projectionBias = ToConstTensor(flatBufferInputParams->projectionBias()); |
| 3362 | |
| 3363 | lstmInputParams.m_ProjectionWeights = &projectionWeights; |
| 3364 | lstmInputParams.m_ProjectionBias = &projectionBias; |
| 3365 | } |
| 3366 | |
| 3367 | armnn::ConstTensor cellToForgetWeights; |
| 3368 | armnn::ConstTensor cellToOutputWeights; |
| 3369 | if (lstmDescriptor.m_PeepholeEnabled) |
| 3370 | { |
| 3371 | cellToForgetWeights = ToConstTensor(flatBufferInputParams->cellToForgetWeights()); |
| 3372 | cellToOutputWeights = ToConstTensor(flatBufferInputParams->cellToOutputWeights()); |
| 3373 | |
| 3374 | lstmInputParams.m_CellToForgetWeights = &cellToForgetWeights; |
| 3375 | lstmInputParams.m_CellToOutputWeights = &cellToOutputWeights; |
| 3376 | } |
| 3377 | |
Jan Eilers | f8c6297 | 2019-07-17 11:07:49 +0100 | [diff] [blame] | 3378 | armnn::ConstTensor inputLayerNormWeights; |
| 3379 | armnn::ConstTensor forgetLayerNormWeights; |
| 3380 | armnn::ConstTensor cellLayerNormWeights; |
| 3381 | armnn::ConstTensor outputLayerNormWeights; |
| 3382 | if (lstmDescriptor.m_LayerNormEnabled) |
| 3383 | { |
| 3384 | if (!lstmDescriptor.m_CifgEnabled) |
| 3385 | { |
| 3386 | inputLayerNormWeights = ToConstTensor(flatBufferInputParams->inputLayerNormWeights()); |
| 3387 | lstmInputParams.m_InputLayerNormWeights = &inputLayerNormWeights; |
| 3388 | } |
| 3389 | forgetLayerNormWeights = ToConstTensor(flatBufferInputParams->forgetLayerNormWeights()); |
| 3390 | cellLayerNormWeights = ToConstTensor(flatBufferInputParams->cellLayerNormWeights()); |
| 3391 | outputLayerNormWeights = ToConstTensor(flatBufferInputParams->outputLayerNormWeights()); |
| 3392 | |
| 3393 | lstmInputParams.m_ForgetLayerNormWeights = &forgetLayerNormWeights; |
| 3394 | lstmInputParams.m_CellLayerNormWeights = &cellLayerNormWeights; |
| 3395 | lstmInputParams.m_OutputLayerNormWeights = &outputLayerNormWeights; |
| 3396 | } |
| 3397 | |
Jim Flynn | 11af375 | 2019-03-19 17:22:29 +0000 | [diff] [blame] | 3398 | IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str()); |
| 3399 | |
| 3400 | armnn::TensorInfo outputTensorInfo1 = ToTensorInfo(outputs[0]); |
| 3401 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo1); |
| 3402 | |
| 3403 | armnn::TensorInfo outputTensorInfo2 = ToTensorInfo(outputs[1]); |
| 3404 | layer->GetOutputSlot(1).SetTensorInfo(outputTensorInfo2); |
| 3405 | |
| 3406 | armnn::TensorInfo outputTensorInfo3 = ToTensorInfo(outputs[2]); |
| 3407 | layer->GetOutputSlot(2).SetTensorInfo(outputTensorInfo3); |
| 3408 | |
| 3409 | armnn::TensorInfo outputTensorInfo4 = ToTensorInfo(outputs[3]); |
| 3410 | layer->GetOutputSlot(3).SetTensorInfo(outputTensorInfo4); |
| 3411 | |
| 3412 | RegisterInputSlots(graph, layerIndex, layer); |
| 3413 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3414 | } |
| 3415 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3416 | armnn::QLstmDescriptor IDeserializer::DeserializerImpl::GetQLstmDescriptor(QLstmDescriptorPtr qLstmDescriptor) |
James Conroy | 8d33318 | 2020-05-13 10:27:58 +0100 | [diff] [blame] | 3417 | { |
| 3418 | armnn::QLstmDescriptor desc; |
| 3419 | |
| 3420 | desc.m_CifgEnabled = qLstmDescriptor->cifgEnabled(); |
| 3421 | desc.m_PeepholeEnabled = qLstmDescriptor->peepholeEnabled(); |
| 3422 | desc.m_ProjectionEnabled = qLstmDescriptor->projectionEnabled(); |
| 3423 | desc.m_LayerNormEnabled = qLstmDescriptor->layerNormEnabled(); |
| 3424 | |
| 3425 | desc.m_CellClip = qLstmDescriptor->cellClip(); |
| 3426 | desc.m_ProjectionClip = qLstmDescriptor->projectionClip(); |
| 3427 | |
| 3428 | desc.m_InputIntermediateScale = qLstmDescriptor->inputIntermediateScale(); |
| 3429 | desc.m_ForgetIntermediateScale = qLstmDescriptor->forgetIntermediateScale(); |
| 3430 | desc.m_CellIntermediateScale = qLstmDescriptor->cellIntermediateScale(); |
| 3431 | desc.m_OutputIntermediateScale = qLstmDescriptor->outputIntermediateScale(); |
| 3432 | |
| 3433 | desc.m_HiddenStateScale = qLstmDescriptor->hiddenStateScale(); |
| 3434 | desc.m_HiddenStateZeroPoint = qLstmDescriptor->hiddenStateZeroPoint(); |
| 3435 | |
| 3436 | return desc; |
| 3437 | } |
| 3438 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3439 | void IDeserializer::DeserializerImpl::ParseQLstm(GraphPtr graph, unsigned int layerIndex) |
James Conroy | 8d33318 | 2020-05-13 10:27:58 +0100 | [diff] [blame] | 3440 | { |
| 3441 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3442 | |
| 3443 | auto inputs = GetInputs(graph, layerIndex); |
| 3444 | CHECK_VALID_SIZE(inputs.size(), 3); |
| 3445 | |
| 3446 | auto outputs = GetOutputs(graph, layerIndex); |
| 3447 | CHECK_VALID_SIZE(outputs.size(), 3); |
| 3448 | |
| 3449 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QLstmLayer(); |
| 3450 | auto layerName = GetLayerName(graph, layerIndex); |
| 3451 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 3452 | auto flatBufferInputParams = flatBufferLayer->inputParams(); |
| 3453 | |
| 3454 | auto qLstmDescriptor = GetQLstmDescriptor(flatBufferDescriptor); |
| 3455 | armnn::LstmInputParams qLstmInputParams; |
| 3456 | |
| 3457 | // Mandatory params |
| 3458 | armnn::ConstTensor inputToForgetWeights = ToConstTensor(flatBufferInputParams->inputToForgetWeights()); |
| 3459 | armnn::ConstTensor inputToCellWeights = ToConstTensor(flatBufferInputParams->inputToCellWeights()); |
| 3460 | armnn::ConstTensor inputToOutputWeights = ToConstTensor(flatBufferInputParams->inputToOutputWeights()); |
| 3461 | armnn::ConstTensor recurrentToForgetWeights = ToConstTensor(flatBufferInputParams->recurrentToForgetWeights()); |
| 3462 | armnn::ConstTensor recurrentToCellWeights = ToConstTensor(flatBufferInputParams->recurrentToCellWeights()); |
| 3463 | armnn::ConstTensor recurrentToOutputWeights = ToConstTensor(flatBufferInputParams->recurrentToOutputWeights()); |
| 3464 | armnn::ConstTensor forgetGateBias = ToConstTensor(flatBufferInputParams->forgetGateBias()); |
| 3465 | armnn::ConstTensor cellBias = ToConstTensor(flatBufferInputParams->cellBias()); |
| 3466 | armnn::ConstTensor outputGateBias = ToConstTensor(flatBufferInputParams->outputGateBias()); |
| 3467 | |
| 3468 | qLstmInputParams.m_InputToForgetWeights = &inputToForgetWeights; |
| 3469 | qLstmInputParams.m_InputToCellWeights = &inputToCellWeights; |
| 3470 | qLstmInputParams.m_InputToOutputWeights = &inputToOutputWeights; |
| 3471 | qLstmInputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeights; |
| 3472 | qLstmInputParams.m_RecurrentToCellWeights = &recurrentToCellWeights; |
| 3473 | qLstmInputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeights; |
| 3474 | qLstmInputParams.m_ForgetGateBias = &forgetGateBias; |
| 3475 | qLstmInputParams.m_CellBias = &cellBias; |
| 3476 | qLstmInputParams.m_OutputGateBias = &outputGateBias; |
| 3477 | |
| 3478 | // Optional CIFG params |
| 3479 | armnn::ConstTensor inputToInputWeights; |
| 3480 | armnn::ConstTensor recurrentToInputWeights; |
| 3481 | armnn::ConstTensor inputGateBias; |
| 3482 | |
| 3483 | if (!qLstmDescriptor.m_CifgEnabled) |
| 3484 | { |
| 3485 | inputToInputWeights = ToConstTensor(flatBufferInputParams->inputToInputWeights()); |
| 3486 | recurrentToInputWeights = ToConstTensor(flatBufferInputParams->recurrentToInputWeights()); |
| 3487 | inputGateBias = ToConstTensor(flatBufferInputParams->inputGateBias()); |
| 3488 | |
| 3489 | qLstmInputParams.m_InputToInputWeights = &inputToInputWeights; |
| 3490 | qLstmInputParams.m_RecurrentToInputWeights = &recurrentToInputWeights; |
| 3491 | qLstmInputParams.m_InputGateBias = &inputGateBias; |
| 3492 | } |
| 3493 | |
| 3494 | // Optional projection params |
| 3495 | armnn::ConstTensor projectionWeights; |
| 3496 | armnn::ConstTensor projectionBias; |
| 3497 | |
| 3498 | if (qLstmDescriptor.m_ProjectionEnabled) |
| 3499 | { |
| 3500 | projectionWeights = ToConstTensor(flatBufferInputParams->projectionWeights()); |
| 3501 | projectionBias = ToConstTensor(flatBufferInputParams->projectionBias()); |
| 3502 | |
| 3503 | qLstmInputParams.m_ProjectionWeights = &projectionWeights; |
| 3504 | qLstmInputParams.m_ProjectionBias = &projectionBias; |
| 3505 | } |
| 3506 | |
| 3507 | // Optional peephole params |
| 3508 | armnn::ConstTensor cellToInputWeights; |
| 3509 | armnn::ConstTensor cellToForgetWeights; |
| 3510 | armnn::ConstTensor cellToOutputWeights; |
| 3511 | |
| 3512 | if (qLstmDescriptor.m_PeepholeEnabled) |
| 3513 | { |
| 3514 | if (!qLstmDescriptor.m_CifgEnabled) |
| 3515 | { |
| 3516 | cellToInputWeights = ToConstTensor(flatBufferInputParams->cellToInputWeights()); |
| 3517 | qLstmInputParams.m_CellToInputWeights = &cellToInputWeights; |
| 3518 | } |
| 3519 | |
| 3520 | cellToForgetWeights = ToConstTensor(flatBufferInputParams->cellToForgetWeights()); |
| 3521 | cellToOutputWeights = ToConstTensor(flatBufferInputParams->cellToOutputWeights()); |
| 3522 | |
| 3523 | qLstmInputParams.m_CellToForgetWeights = &cellToForgetWeights; |
| 3524 | qLstmInputParams.m_CellToOutputWeights = &cellToOutputWeights; |
| 3525 | } |
| 3526 | |
| 3527 | // Optional layer norm params |
| 3528 | armnn::ConstTensor inputLayerNormWeights; |
| 3529 | armnn::ConstTensor forgetLayerNormWeights; |
| 3530 | armnn::ConstTensor cellLayerNormWeights; |
| 3531 | armnn::ConstTensor outputLayerNormWeights; |
| 3532 | |
| 3533 | if (qLstmDescriptor.m_LayerNormEnabled) |
| 3534 | { |
| 3535 | if (!qLstmDescriptor.m_CifgEnabled) |
| 3536 | { |
| 3537 | inputLayerNormWeights = ToConstTensor(flatBufferInputParams->inputLayerNormWeights()); |
| 3538 | qLstmInputParams.m_InputLayerNormWeights = &inputLayerNormWeights; |
| 3539 | } |
| 3540 | |
| 3541 | forgetLayerNormWeights = ToConstTensor(flatBufferInputParams->forgetLayerNormWeights()); |
| 3542 | cellLayerNormWeights = ToConstTensor(flatBufferInputParams->cellLayerNormWeights()); |
| 3543 | outputLayerNormWeights = ToConstTensor(flatBufferInputParams->outputLayerNormWeights()); |
| 3544 | |
| 3545 | qLstmInputParams.m_ForgetLayerNormWeights = &forgetLayerNormWeights; |
| 3546 | qLstmInputParams.m_CellLayerNormWeights = &cellLayerNormWeights; |
| 3547 | qLstmInputParams.m_OutputLayerNormWeights = &outputLayerNormWeights; |
| 3548 | } |
| 3549 | |
| 3550 | IConnectableLayer* layer = m_Network->AddQLstmLayer(qLstmDescriptor, qLstmInputParams, layerName.c_str()); |
| 3551 | |
| 3552 | armnn::TensorInfo outputStateOutInfo = ToTensorInfo(outputs[0]); |
| 3553 | layer->GetOutputSlot(0).SetTensorInfo(outputStateOutInfo); |
| 3554 | |
| 3555 | armnn::TensorInfo cellStateOutInfo = ToTensorInfo(outputs[1]); |
| 3556 | layer->GetOutputSlot(1).SetTensorInfo(cellStateOutInfo); |
| 3557 | |
| 3558 | armnn::TensorInfo outputInfo = ToTensorInfo(outputs[2]); |
| 3559 | layer->GetOutputSlot(2).SetTensorInfo(outputInfo); |
| 3560 | |
| 3561 | RegisterInputSlots(graph, layerIndex, layer); |
| 3562 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3563 | } |
| 3564 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3565 | void IDeserializer::DeserializerImpl::ParseQuantizedLstm(GraphPtr graph, unsigned int layerIndex) |
Jan Eilers | 5b01a89 | 2019-07-23 09:47:43 +0100 | [diff] [blame] | 3566 | { |
| 3567 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3568 | |
| 3569 | auto inputs = GetInputs(graph, layerIndex); |
| 3570 | CHECK_VALID_SIZE(inputs.size(), 3); |
| 3571 | |
| 3572 | auto outputs = GetOutputs(graph, layerIndex); |
| 3573 | CHECK_VALID_SIZE(outputs.size(), 2); |
| 3574 | |
| 3575 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer(); |
| 3576 | auto layerName = GetLayerName(graph, layerIndex); |
| 3577 | auto flatBufferInputParams = flatBufferLayer->inputParams(); |
| 3578 | |
| 3579 | armnn::QuantizedLstmInputParams lstmInputParams; |
| 3580 | |
| 3581 | armnn::ConstTensor inputToInputWeights = ToConstTensor(flatBufferInputParams->inputToInputWeights()); |
| 3582 | armnn::ConstTensor inputToForgetWeights = ToConstTensor(flatBufferInputParams->inputToForgetWeights()); |
| 3583 | armnn::ConstTensor inputToCellWeights = ToConstTensor(flatBufferInputParams->inputToCellWeights()); |
| 3584 | armnn::ConstTensor inputToOutputWeights = ToConstTensor(flatBufferInputParams->inputToOutputWeights()); |
| 3585 | armnn::ConstTensor recurrentToInputWeights = ToConstTensor(flatBufferInputParams->recurrentToInputWeights()); |
| 3586 | armnn::ConstTensor recurrentToForgetWeights = ToConstTensor(flatBufferInputParams->recurrentToForgetWeights()); |
| 3587 | armnn::ConstTensor recurrentToCellWeights = ToConstTensor(flatBufferInputParams->recurrentToCellWeights()); |
| 3588 | armnn::ConstTensor recurrentToOutputWeights = ToConstTensor(flatBufferInputParams->recurrentToOutputWeights()); |
| 3589 | armnn::ConstTensor inputGateBias = ToConstTensor(flatBufferInputParams->inputGateBias()); |
| 3590 | armnn::ConstTensor forgetGateBias = ToConstTensor(flatBufferInputParams->forgetGateBias()); |
| 3591 | armnn::ConstTensor cellBias = ToConstTensor(flatBufferInputParams->cellBias()); |
| 3592 | armnn::ConstTensor outputGateBias = ToConstTensor(flatBufferInputParams->outputGateBias()); |
| 3593 | |
| 3594 | lstmInputParams.m_InputToInputWeights = &inputToInputWeights; |
| 3595 | lstmInputParams.m_InputToForgetWeights = &inputToForgetWeights; |
| 3596 | lstmInputParams.m_InputToCellWeights = &inputToCellWeights; |
| 3597 | lstmInputParams.m_InputToOutputWeights = &inputToOutputWeights; |
| 3598 | lstmInputParams.m_RecurrentToInputWeights = &recurrentToInputWeights; |
| 3599 | lstmInputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeights; |
| 3600 | lstmInputParams.m_RecurrentToCellWeights = &recurrentToCellWeights; |
| 3601 | lstmInputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeights; |
| 3602 | lstmInputParams.m_InputGateBias = &inputGateBias; |
| 3603 | lstmInputParams.m_ForgetGateBias = &forgetGateBias; |
| 3604 | lstmInputParams.m_CellBias = &cellBias; |
| 3605 | lstmInputParams.m_OutputGateBias = &outputGateBias; |
| 3606 | |
| 3607 | IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str()); |
| 3608 | |
| 3609 | armnn::TensorInfo outputTensorInfo1 = ToTensorInfo(outputs[0]); |
| 3610 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo1); |
| 3611 | |
| 3612 | armnn::TensorInfo outputTensorInfo2 = ToTensorInfo(outputs[1]); |
| 3613 | layer->GetOutputSlot(1).SetTensorInfo(outputTensorInfo2); |
| 3614 | |
| 3615 | RegisterInputSlots(graph, layerIndex, layer); |
| 3616 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3617 | } |
| 3618 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3619 | void IDeserializer::DeserializerImpl::ParseDequantize(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 3620 | { |
| 3621 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3622 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3623 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 3624 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3625 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3626 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 3627 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3628 | |
| 3629 | const std::string layerName = GetLayerName(graph, layerIndex); |
| 3630 | IConnectableLayer* layer = m_Network->AddDequantizeLayer(layerName.c_str()); |
| 3631 | |
| 3632 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3633 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3634 | |
| 3635 | RegisterInputSlots(graph, layerIndex, layer); |
| 3636 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3637 | } |
| 3638 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3639 | void IDeserializer::DeserializerImpl::ParseMerge(GraphPtr graph, unsigned int layerIndex) |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 3640 | { |
| 3641 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3642 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3643 | TensorRawPtrVector inputs = GetInputs(graph, layerIndex); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 3644 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3645 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3646 | TensorRawPtrVector outputs = GetOutputs(graph, layerIndex); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 3647 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3648 | |
| 3649 | const std::string layerName = GetLayerName(graph, layerIndex); |
| 3650 | IConnectableLayer* layer = m_Network->AddMergeLayer(layerName.c_str()); |
| 3651 | |
| 3652 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3653 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3654 | |
| 3655 | RegisterInputSlots(graph, layerIndex, layer); |
| 3656 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3657 | } |
| 3658 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3659 | void IDeserializer::DeserializerImpl::ParseSwitch(GraphPtr graph, unsigned int layerIndex) |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 3660 | { |
| 3661 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3662 | auto inputs = GetInputs(graph, layerIndex); |
| 3663 | CHECK_LOCATION(); |
| 3664 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3665 | |
| 3666 | auto outputs = GetOutputs(graph, layerIndex); |
| 3667 | CHECK_VALID_SIZE(outputs.size(), 2); |
| 3668 | |
| 3669 | auto layerName = GetLayerName(graph, layerIndex); |
| 3670 | IConnectableLayer* layer = m_Network->AddSwitchLayer(layerName.c_str()); |
| 3671 | |
| 3672 | armnn::TensorInfo output0TensorInfo = ToTensorInfo(outputs[0]); |
| 3673 | layer->GetOutputSlot(0).SetTensorInfo(output0TensorInfo); |
| 3674 | |
| 3675 | armnn::TensorInfo output1TensorInfo = ToTensorInfo(outputs[1]); |
| 3676 | layer->GetOutputSlot(1).SetTensorInfo(output1TensorInfo); |
| 3677 | |
| 3678 | RegisterInputSlots(graph, layerIndex, layer); |
| 3679 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3680 | } |
| 3681 | |
David Monahan | 616b22f | 2023-07-25 12:08:10 +0100 | [diff] [blame] | 3682 | void IDeserializer::DeserializerImpl::ParseTile(GraphPtr graph, unsigned int layerIndex) |
| 3683 | { |
| 3684 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3685 | auto inputs = GetInputs(graph, layerIndex); |
| 3686 | CHECK_LOCATION(); |
| 3687 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3688 | |
| 3689 | auto outputs = GetOutputs(graph, layerIndex); |
| 3690 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3691 | |
| 3692 | auto TileLayer = graph->layers()->Get(layerIndex)->layer_as_TileLayer(); |
| 3693 | auto layerName = GetLayerName(graph, layerIndex); |
| 3694 | auto flatBufferDescriptor = TileLayer->descriptor(); |
| 3695 | auto flatBufferMultiples = flatBufferDescriptor->m_Multiples(); |
| 3696 | |
| 3697 | armnn::TileDescriptor tileDescriptor; |
| 3698 | tileDescriptor.m_Multiples = std::vector<unsigned int>(flatBufferMultiples->begin(), flatBufferMultiples->end()); |
| 3699 | |
| 3700 | IConnectableLayer* layer = m_Network->AddTileLayer(tileDescriptor, layerName.c_str()); |
| 3701 | |
| 3702 | armnn::TensorInfo output0TensorInfo = ToTensorInfo(outputs[0]); |
| 3703 | layer->GetOutputSlot(0).SetTensorInfo(output0TensorInfo); |
| 3704 | |
| 3705 | RegisterInputSlots(graph, layerIndex, layer); |
| 3706 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3707 | } |
| 3708 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3709 | void IDeserializer::DeserializerImpl::ParsePrelu(GraphPtr graph, unsigned int layerIndex) |
Ellen Norris-Thompson | 5198247 | 2019-06-19 11:46:21 +0100 | [diff] [blame] | 3710 | { |
| 3711 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3712 | auto inputs = GetInputs(graph, layerIndex); |
| 3713 | CHECK_LOCATION(); |
| 3714 | CHECK_VALID_SIZE(inputs.size(), 2); |
| 3715 | |
| 3716 | auto outputs = GetOutputs(graph, layerIndex); |
| 3717 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3718 | |
| 3719 | auto layerName = GetLayerName(graph, layerIndex); |
| 3720 | IConnectableLayer* layer = m_Network->AddPreluLayer(layerName.c_str()); |
| 3721 | |
| 3722 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3723 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3724 | |
| 3725 | RegisterInputSlots(graph, layerIndex, layer); |
| 3726 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3727 | } |
| 3728 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3729 | void IDeserializer::DeserializerImpl::ParseTranspose(GraphPtr graph, unsigned int layerIndex) |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 3730 | { |
| 3731 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3732 | |
| 3733 | auto dimsMapping = graph->layers()->Get(layerIndex)->layer_as_TransposeLayer()->descriptor()->dimMappings(); |
| 3734 | |
| 3735 | auto inputs = GetInputs(graph, layerIndex); |
| 3736 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3737 | |
| 3738 | auto outputs = GetOutputs(graph, layerIndex); |
| 3739 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3740 | auto outputInfo = ToTensorInfo(outputs[0]); |
| 3741 | |
| 3742 | auto layerName = GetLayerName(graph, layerIndex); |
Mike Kelly | 51b8c31 | 2022-05-24 11:34:02 +0100 | [diff] [blame] | 3743 | const armnn::TransposeDescriptor descriptor(armnn::PermutationVector(dimsMapping->data(), dimsMapping->size())); |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 3744 | |
| 3745 | IConnectableLayer* layer = m_Network->AddTransposeLayer(descriptor, layerName.c_str()); |
| 3746 | layer->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 3747 | |
| 3748 | RegisterInputSlots(graph, layerIndex, layer); |
| 3749 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3750 | } |
| 3751 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3752 | void IDeserializer::DeserializerImpl::ParseTransposeConvolution2d(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | cb54930 | 2019-06-21 13:53:38 +0100 | [diff] [blame] | 3753 | { |
| 3754 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3755 | |
| 3756 | auto inputs = GetInputs(graph, layerIndex); |
| 3757 | CHECK_VALID_SIZE(inputs.size(), 1); |
| 3758 | |
| 3759 | auto outputs = GetOutputs(graph, layerIndex); |
| 3760 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3761 | |
| 3762 | auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer(); |
| 3763 | auto layerName = GetLayerName(graph, layerIndex); |
| 3764 | auto serializerDescriptor = serializerLayer->descriptor(); |
| 3765 | |
| 3766 | armnn::TransposeConvolution2dDescriptor descriptor; |
| 3767 | descriptor.m_PadLeft = serializerDescriptor->padLeft(); |
| 3768 | descriptor.m_PadRight = serializerDescriptor->padRight(); |
| 3769 | descriptor.m_PadTop = serializerDescriptor->padTop(); |
| 3770 | descriptor.m_PadBottom = serializerDescriptor->padBottom(); |
| 3771 | descriptor.m_StrideX = serializerDescriptor->strideX(); |
| 3772 | descriptor.m_StrideY = serializerDescriptor->strideY();; |
| 3773 | descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled();; |
| 3774 | descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout()); |
| 3775 | |
| 3776 | // weights & biases |
| 3777 | armnn::ConstTensor weights = ToConstTensor(serializerLayer->weights()); |
| 3778 | armnn::Optional<armnn::ConstTensor> optionalBiases; |
| 3779 | if (descriptor.m_BiasEnabled) |
| 3780 | { |
| 3781 | armnn::ConstTensor biases = ToConstTensor(serializerLayer->biases()); |
| 3782 | optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases); |
| 3783 | } |
| 3784 | |
| 3785 | IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor, |
| 3786 | weights, |
| 3787 | optionalBiases, |
| 3788 | layerName.c_str()); |
| 3789 | |
| 3790 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3791 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3792 | |
| 3793 | RegisterInputSlots(graph, layerIndex, layer); |
| 3794 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3795 | } |
| 3796 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3797 | void IDeserializer::DeserializerImpl::ParseStack(GraphPtr graph, unsigned int layerIndex) |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 3798 | { |
| 3799 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3800 | auto inputs = GetInputs(graph, layerIndex); |
| 3801 | |
| 3802 | auto outputs = GetOutputs(graph, layerIndex); |
| 3803 | CHECK_VALID_SIZE(outputs.size(), 1); |
| 3804 | |
| 3805 | auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor(); |
| 3806 | unsigned int axis = flatBufferDescriptor->axis(); |
| 3807 | unsigned int numInputs = flatBufferDescriptor->numInputs(); |
| 3808 | CHECK_VALID_SIZE(inputs.size(), numInputs); |
| 3809 | |
| 3810 | auto flatBufferInputShape = flatBufferDescriptor->inputShape(); |
| 3811 | std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(), |
| 3812 | flatBufferInputShape->begin() + flatBufferInputShape->size()); |
| 3813 | |
| 3814 | TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data()); |
| 3815 | armnn::StackDescriptor descriptor(axis, numInputs, inputShape); |
| 3816 | |
| 3817 | for (unsigned int i=0; i<inputs.size(); ++i) |
| 3818 | { |
Matthew Bentham | 75ae2b0 | 2019-09-19 12:04:13 +0100 | [diff] [blame] | 3819 | armnn::TensorShape inputShape = ToTensorInfo(inputs[i]).GetShape(); |
Matthew Jackson | b5433ee | 2019-07-11 15:54:20 +0100 | [diff] [blame] | 3820 | if (descriptor.m_InputShape != inputShape) |
| 3821 | { |
| 3822 | std::stringstream ss; |
| 3823 | ss << "Shape of input " |
| 3824 | << i |
| 3825 | << " " |
| 3826 | << inputShape |
| 3827 | << " does not equal defined input shape " |
| 3828 | << descriptor.m_InputShape |
| 3829 | << ": " |
| 3830 | << CHECK_LOCATION().AsString(); |
| 3831 | throw ParseException(ss.str()); |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | auto layerName = GetLayerName(graph, layerIndex); |
| 3836 | IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str()); |
| 3837 | |
| 3838 | armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); |
| 3839 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 3840 | |
| 3841 | RegisterInputSlots(graph, layerIndex, layer); |
| 3842 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3843 | } |
| 3844 | |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 3845 | void IDeserializer::DeserializerImpl::ParseStandIn(GraphPtr graph, unsigned int layerIndex) |
Aron Virginas-Tar | 85121a2 | 2019-10-23 10:41:35 +0100 | [diff] [blame] | 3846 | { |
| 3847 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3848 | |
| 3849 | auto inputs = GetInputs(graph, layerIndex); |
| 3850 | auto outputs = GetOutputs(graph, layerIndex); |
| 3851 | |
| 3852 | auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer(); |
| 3853 | auto fbDescriptor = fbLayer->descriptor(); |
| 3854 | |
| 3855 | armnn::StandInDescriptor descriptor; |
| 3856 | descriptor.m_NumInputs = fbDescriptor->numInputs(); |
| 3857 | descriptor.m_NumOutputs = fbDescriptor->numOutputs(); |
| 3858 | |
| 3859 | CHECK_VALID_SIZE(inputs.size(), descriptor.m_NumInputs); |
| 3860 | CHECK_VALID_SIZE(outputs.size(), descriptor.m_NumOutputs); |
| 3861 | |
| 3862 | const std::string layerName = GetLayerName(graph, layerIndex); |
| 3863 | armnn::IConnectableLayer* layer = m_Network->AddStandInLayer(descriptor, layerName.c_str()); |
| 3864 | |
| 3865 | for (unsigned int i = 0u; i < descriptor.m_NumOutputs; ++i) |
| 3866 | { |
| 3867 | armnn::TensorInfo outputInfo = ToTensorInfo(outputs[i]); |
| 3868 | layer->GetOutputSlot(i).SetTensorInfo(outputInfo); |
| 3869 | } |
| 3870 | |
| 3871 | RegisterInputSlots(graph, layerIndex, layer); |
| 3872 | RegisterOutputSlots(graph, layerIndex, layer); |
| 3873 | } |
| 3874 | |
Narumol Prangnawarat | a0162e1 | 2021-07-23 14:47:49 +0100 | [diff] [blame] | 3875 | armnn::UnidirectionalSequenceLstmDescriptor IDeserializer::DeserializerImpl::GetUnidirectionalSequenceLstmDescriptor( |
| 3876 | UnidirectionalSequenceLstmDescriptorPtr descriptor) |
| 3877 | { |
| 3878 | armnn::UnidirectionalSequenceLstmDescriptor desc; |
| 3879 | |
| 3880 | desc.m_ActivationFunc = descriptor->activationFunc(); |
| 3881 | desc.m_ClippingThresCell = descriptor->clippingThresCell(); |
| 3882 | desc.m_ClippingThresProj = descriptor->clippingThresProj(); |
| 3883 | desc.m_CifgEnabled = descriptor->cifgEnabled(); |
| 3884 | desc.m_PeepholeEnabled = descriptor->peepholeEnabled(); |
| 3885 | desc.m_ProjectionEnabled = descriptor->projectionEnabled(); |
| 3886 | desc.m_LayerNormEnabled = descriptor->layerNormEnabled(); |
| 3887 | desc.m_TimeMajor = descriptor->timeMajor(); |
| 3888 | |
| 3889 | return desc; |
| 3890 | } |
| 3891 | |
| 3892 | void IDeserializer::DeserializerImpl::ParseUnidirectionalSequenceLstm(GraphPtr graph, unsigned int layerIndex) |
| 3893 | { |
| 3894 | CHECK_LAYERS(graph, 0, layerIndex); |
| 3895 | |
| 3896 | auto inputs = GetInputs(graph, layerIndex); |
| 3897 | CHECK_VALID_SIZE(inputs.size(), 3); |
| 3898 | |
| 3899 | auto outputs = GetOutputs(graph, layerIndex); |
Mike Kelly | 1299496 | 2022-04-21 11:57:09 +0100 | [diff] [blame] | 3900 | CHECK_VALID_SIZE(outputs.size(), 3); |
Narumol Prangnawarat | a0162e1 | 2021-07-23 14:47:49 +0100 | [diff] [blame] | 3901 | |
| 3902 | auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_UnidirectionalSequenceLstmLayer(); |
| 3903 | auto layerName = GetLayerName(graph, layerIndex); |
| 3904 | auto flatBufferDescriptor = flatBufferLayer->descriptor(); |
| 3905 | auto flatBufferInputParams = flatBufferLayer->inputParams(); |
| 3906 | |
| 3907 | auto descriptor = GetUnidirectionalSequenceLstmDescriptor(flatBufferDescriptor); |
| 3908 | |
| 3909 | armnn::LstmInputParams lstmInputParams; |
| 3910 | |
| 3911 | armnn::ConstTensor inputToForgetWeights = ToConstTensor(flatBufferInputParams->inputToForgetWeights()); |
| 3912 | armnn::ConstTensor inputToCellWeights = ToConstTensor(flatBufferInputParams->inputToCellWeights()); |
| 3913 | armnn::ConstTensor inputToOutputWeights = ToConstTensor(flatBufferInputParams->inputToOutputWeights()); |
| 3914 | armnn::ConstTensor recurrentToForgetWeights = ToConstTensor(flatBufferInputParams->recurrentToForgetWeights()); |
| 3915 | armnn::ConstTensor recurrentToCellWeights = ToConstTensor(flatBufferInputParams->recurrentToCellWeights()); |
| 3916 | armnn::ConstTensor recurrentToOutputWeights = ToConstTensor(flatBufferInputParams->recurrentToOutputWeights()); |
| 3917 | armnn::ConstTensor forgetGateBias = ToConstTensor(flatBufferInputParams->forgetGateBias()); |
| 3918 | armnn::ConstTensor cellBias = ToConstTensor(flatBufferInputParams->cellBias()); |
| 3919 | armnn::ConstTensor outputGateBias = ToConstTensor(flatBufferInputParams->outputGateBias()); |
| 3920 | |
| 3921 | lstmInputParams.m_InputToForgetWeights = &inputToForgetWeights; |
| 3922 | lstmInputParams.m_InputToCellWeights = &inputToCellWeights; |
| 3923 | lstmInputParams.m_InputToOutputWeights = &inputToOutputWeights; |
| 3924 | lstmInputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeights; |
| 3925 | lstmInputParams.m_RecurrentToCellWeights = &recurrentToCellWeights; |
| 3926 | lstmInputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeights; |
| 3927 | lstmInputParams.m_ForgetGateBias = &forgetGateBias; |
| 3928 | lstmInputParams.m_CellBias = &cellBias; |
| 3929 | lstmInputParams.m_OutputGateBias = &outputGateBias; |
| 3930 | |
| 3931 | armnn::ConstTensor inputToInputWeights; |
| 3932 | armnn::ConstTensor recurrentToInputWeights; |
| 3933 | armnn::ConstTensor cellToInputWeights; |
| 3934 | armnn::ConstTensor inputGateBias; |
| 3935 | if (!descriptor.m_CifgEnabled) |
| 3936 | { |
| 3937 | inputToInputWeights = ToConstTensor(flatBufferInputParams->inputToInputWeights()); |
| 3938 | recurrentToInputWeights = ToConstTensor(flatBufferInputParams->recurrentToInputWeights()); |
| 3939 | inputGateBias = ToConstTensor(flatBufferInputParams->inputGateBias()); |
| 3940 | |
| 3941 | lstmInputParams.m_InputToInputWeights = &inputToInputWeights; |
| 3942 | lstmInputParams.m_RecurrentToInputWeights = &recurrentToInputWeights; |
| 3943 | lstmInputParams.m_InputGateBias = &inputGateBias; |
| 3944 | |
| 3945 | if (descriptor.m_PeepholeEnabled) |
| 3946 | { |
| 3947 | cellToInputWeights = ToConstTensor(flatBufferInputParams->cellToInputWeights()); |
| 3948 | lstmInputParams.m_CellToInputWeights = &cellToInputWeights; |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | armnn::ConstTensor projectionWeights; |
| 3953 | armnn::ConstTensor projectionBias; |
| 3954 | if (descriptor.m_ProjectionEnabled) |
| 3955 | { |
| 3956 | projectionWeights = ToConstTensor(flatBufferInputParams->projectionWeights()); |
| 3957 | projectionBias = ToConstTensor(flatBufferInputParams->projectionBias()); |
| 3958 | |
| 3959 | lstmInputParams.m_ProjectionWeights = &projectionWeights; |
| 3960 | lstmInputParams.m_ProjectionBias = &projectionBias; |
| 3961 | } |
| 3962 | |
| 3963 | armnn::ConstTensor cellToForgetWeights; |
| 3964 | armnn::ConstTensor cellToOutputWeights; |
| 3965 | if (descriptor.m_PeepholeEnabled) |
| 3966 | { |
| 3967 | cellToForgetWeights = ToConstTensor(flatBufferInputParams->cellToForgetWeights()); |
| 3968 | cellToOutputWeights = ToConstTensor(flatBufferInputParams->cellToOutputWeights()); |
| 3969 | |
| 3970 | lstmInputParams.m_CellToForgetWeights = &cellToForgetWeights; |
| 3971 | lstmInputParams.m_CellToOutputWeights = &cellToOutputWeights; |
| 3972 | } |
| 3973 | |
| 3974 | armnn::ConstTensor inputLayerNormWeights; |
| 3975 | armnn::ConstTensor forgetLayerNormWeights; |
| 3976 | armnn::ConstTensor cellLayerNormWeights; |
| 3977 | armnn::ConstTensor outputLayerNormWeights; |
| 3978 | if (descriptor.m_LayerNormEnabled) |
| 3979 | { |
| 3980 | if (!descriptor.m_CifgEnabled) |
| 3981 | { |
| 3982 | inputLayerNormWeights = ToConstTensor(flatBufferInputParams->inputLayerNormWeights()); |
| 3983 | lstmInputParams.m_InputLayerNormWeights = &inputLayerNormWeights; |
| 3984 | } |
| 3985 | forgetLayerNormWeights = ToConstTensor(flatBufferInputParams->forgetLayerNormWeights()); |
| 3986 | cellLayerNormWeights = ToConstTensor(flatBufferInputParams->cellLayerNormWeights()); |
| 3987 | outputLayerNormWeights = ToConstTensor(flatBufferInputParams->outputLayerNormWeights()); |
| 3988 | |
| 3989 | lstmInputParams.m_ForgetLayerNormWeights = &forgetLayerNormWeights; |
| 3990 | lstmInputParams.m_CellLayerNormWeights = &cellLayerNormWeights; |
| 3991 | lstmInputParams.m_OutputLayerNormWeights = &outputLayerNormWeights; |
| 3992 | } |
| 3993 | |
| 3994 | IConnectableLayer* layer = m_Network->AddUnidirectionalSequenceLstmLayer(descriptor, |
| 3995 | lstmInputParams, |
| 3996 | layerName.c_str()); |
| 3997 | |
Mike Kelly | 1299496 | 2022-04-21 11:57:09 +0100 | [diff] [blame] | 3998 | armnn::TensorInfo outputTensorInfo0 = ToTensorInfo(outputs[0]); |
| 3999 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo0); |
| 4000 | |
| 4001 | armnn::TensorInfo outputTensorInfo1 = ToTensorInfo(outputs[1]); |
| 4002 | layer->GetOutputSlot(1).SetTensorInfo(outputTensorInfo1); |
| 4003 | |
| 4004 | armnn::TensorInfo outputTensorInfo2 = ToTensorInfo(outputs[2]); |
| 4005 | layer->GetOutputSlot(2).SetTensorInfo(outputTensorInfo2); |
Narumol Prangnawarat | a0162e1 | 2021-07-23 14:47:49 +0100 | [diff] [blame] | 4006 | |
| 4007 | RegisterInputSlots(graph, layerIndex, layer); |
| 4008 | RegisterOutputSlots(graph, layerIndex, layer); |
| 4009 | } |
| 4010 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 4011 | } // namespace armnnDeserializer |