Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 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 |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include "armnn/Types.hpp" |
| 8 | #include "armnn/Tensor.hpp" |
| 9 | #include "armnn/INetwork.hpp" |
| 10 | |
| 11 | #include <map> |
| 12 | #include <memory> |
| 13 | #include <unordered_map> |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace armnnTfParser |
| 17 | { |
| 18 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 19 | using BindingPointInfo = armnn::BindingPointInfo; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 20 | |
| 21 | class ITfParser; |
| 22 | using ITfParserPtr = std::unique_ptr<ITfParser, void(*)(ITfParser* parser)>; |
| 23 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | /// Parses a directed acyclic graph from a tensorflow protobuf file. |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 25 | class ITfParser |
| 26 | { |
| 27 | public: |
| 28 | static ITfParser* CreateRaw(); |
| 29 | static ITfParserPtr Create(); |
| 30 | static void Destroy(ITfParser* parser); |
| 31 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 32 | /// Create the network from a protobuf text file on the disk. |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 33 | armnn::INetworkPtr CreateNetworkFromTextFile( |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 34 | const char* graphFile, |
| 35 | const std::map<std::string, armnn::TensorShape>& inputShapes, |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 36 | const std::vector<std::string>& requestedOutputs); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 37 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | /// Create the network from a protobuf binary file on the disk. |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 39 | armnn::INetworkPtr CreateNetworkFromBinaryFile( |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 40 | const char* graphFile, |
| 41 | const std::map<std::string, armnn::TensorShape>& inputShapes, |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 42 | const std::vector<std::string>& requestedOutputs); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | /// Create the network directly from protobuf text in a string. Useful for debugging/testing. |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 45 | armnn::INetworkPtr CreateNetworkFromString( |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 46 | const char* protoText, |
| 47 | const std::map<std::string, armnn::TensorShape>& inputShapes, |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 48 | const std::vector<std::string>& requestedOutputs); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 49 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 50 | /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name. |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 51 | BindingPointInfo GetNetworkInputBindingInfo(const std::string& name) const; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 52 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name. |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 54 | BindingPointInfo GetNetworkOutputBindingInfo(const std::string& name) const; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 55 | |
Kevin May | 7d96b16 | 2021-02-03 17:38:41 +0000 | [diff] [blame] | 56 | private: |
| 57 | template <typename T> |
| 58 | friend class ParsedConstTfOperation; |
| 59 | friend class ParsedMatMulTfOperation; |
| 60 | friend class ParsedMulTfOperation; |
| 61 | friend class ParsedTfOperation; |
| 62 | friend class SingleLayerParsedTfOperation; |
| 63 | friend class DeferredSingleLayerParsedTfOperation; |
| 64 | friend class ParsedIdentityTfOperation; |
| 65 | |
| 66 | template <template<typename> class OperatorType, typename T> |
| 67 | friend struct MakeTfOperation; |
| 68 | |
| 69 | |
| 70 | ITfParser(); |
| 71 | ~ITfParser(); |
| 72 | |
| 73 | struct TfParserImpl; |
| 74 | std::unique_ptr<TfParserImpl> pTfParserImpl; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } |