telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include "armnn/Types.hpp" |
| 8 | #include "armnn/NetworkFwd.hpp" |
| 9 | #include "armnn/Tensor.hpp" |
| 10 | #include "armnn/INetwork.hpp" |
Aron Virginas-Tar | c975f92 | 2019-10-23 17:38:17 +0100 | [diff] [blame] | 11 | #include "armnn/Optional.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
| 14 | #include <map> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace armnnTfLiteParser |
| 18 | { |
| 19 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 20 | using BindingPointInfo = armnn::BindingPointInfo; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 22 | class TfLiteParserImpl; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 23 | class ITfLiteParser; |
| 24 | using ITfLiteParserPtr = std::unique_ptr<ITfLiteParser, void(*)(ITfLiteParser* parser)>; |
| 25 | |
| 26 | class ITfLiteParser |
| 27 | { |
| 28 | public: |
Aron Virginas-Tar | c975f92 | 2019-10-23 17:38:17 +0100 | [diff] [blame] | 29 | struct TfLiteParserOptions |
| 30 | { |
| 31 | TfLiteParserOptions() |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 32 | : m_StandInLayerForUnsupported(false), |
| 33 | m_InferAndValidate(false) {} |
Aron Virginas-Tar | c975f92 | 2019-10-23 17:38:17 +0100 | [diff] [blame] | 34 | |
| 35 | bool m_StandInLayerForUnsupported; |
Sadik Armagan | d109a4d | 2020-07-28 10:42:13 +0100 | [diff] [blame] | 36 | bool m_InferAndValidate; |
Aron Virginas-Tar | c975f92 | 2019-10-23 17:38:17 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | static ITfLiteParser* CreateRaw(const armnn::Optional<TfLiteParserOptions>& options = armnn::EmptyOptional()); |
| 40 | static ITfLiteParserPtr Create(const armnn::Optional<TfLiteParserOptions>& options = armnn::EmptyOptional()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | static void Destroy(ITfLiteParser* parser); |
| 42 | |
| 43 | /// Create the network from a flatbuffers binary file on disk |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 44 | armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | |
| 46 | /// Create the network from a flatbuffers binary |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 47 | armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t> & binaryContent); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 48 | |
| 49 | /// Retrieve binding info (layer id and tensor info) for the network input identified by |
| 50 | /// the given layer name and subgraph id |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 51 | BindingPointInfo GetNetworkInputBindingInfo(size_t subgraphId, |
| 52 | const std::string& name) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | |
| 54 | /// Retrieve binding info (layer id and tensor info) for the network output identified by |
| 55 | /// the given layer name and subgraph id |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 56 | BindingPointInfo GetNetworkOutputBindingInfo(size_t subgraphId, |
| 57 | const std::string& name) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 58 | |
| 59 | /// Return the number of subgraphs in the parsed model |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 60 | size_t GetSubgraphCount() const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | |
| 62 | /// Return the input tensor names for a given subgraph |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 63 | std::vector<std::string> GetSubgraphInputTensorNames(size_t subgraphId) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | |
| 65 | /// Return the output tensor names for a given subgraph |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 66 | std::vector<std::string> GetSubgraphOutputTensorNames(size_t subgraphId) const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 67 | |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 68 | private: |
| 69 | ITfLiteParser(const armnn::Optional<TfLiteParserOptions>& options = armnn::EmptyOptional()); |
| 70 | ~ITfLiteParser(); |
| 71 | |
| 72 | std::unique_ptr<TfLiteParserImpl> pTfLiteParserImpl; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } |