1 // 2 // Copyright © 2017,2022 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 #pragma once 6 7 #include <armnn/INetwork.hpp> 8 #include <armnn/Tensor.hpp> 9 10 #include <memory> 11 #include <vector> 12 #include <map> 13 14 namespace armnnOnnxParser 15 { 16 17 using BindingPointInfo = armnn::BindingPointInfo; 18 19 class OnnxParserImpl; 20 class IOnnxParser; 21 using IOnnxParserPtr = std::unique_ptr<IOnnxParser, void(*)(IOnnxParser* parser)>; 22 23 class IOnnxParser 24 { 25 public: 26 static IOnnxParser* CreateRaw(); 27 static IOnnxParserPtr Create(); 28 static void Destroy(IOnnxParser* parser); 29 30 /// Create the network from a protobuf binary vector 31 armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent); 32 33 /// Create the network from a protobuf binary vector, with inputShapes specified 34 armnn::INetworkPtr CreateNetworkFromBinary(const std::vector<uint8_t>& binaryContent, 35 const std::map<std::string, armnn::TensorShape>& inputShapes); 36 37 /// Create the network from a protobuf binary file on disk 38 armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile); 39 40 /// Create the network from a protobuf text file on disk 41 armnn::INetworkPtr CreateNetworkFromTextFile(const char* graphFile); 42 43 /// Create the network directly from protobuf text in a string. Useful for debugging/testing 44 armnn::INetworkPtr CreateNetworkFromString(const std::string& protoText); 45 46 /// Create the network from a protobuf binary file on disk, with inputShapes specified 47 armnn::INetworkPtr CreateNetworkFromBinaryFile(const char* graphFile, 48 const std::map<std::string, armnn::TensorShape>& inputShapes); 49 50 /// Create the network from a protobuf text file on disk, with inputShapes specified 51 armnn::INetworkPtr CreateNetworkFromTextFile(const char* graphFile, 52 const std::map<std::string, armnn::TensorShape>& inputShapes); 53 54 /// Create the network directly from protobuf text in a string, with inputShapes specified. 55 /// Useful for debugging/testing 56 armnn::INetworkPtr CreateNetworkFromString(const std::string& protoText, 57 const std::map<std::string, armnn::TensorShape>& inputShapes); 58 59 /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name 60 BindingPointInfo GetNetworkInputBindingInfo(const std::string& name) const; 61 62 /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name 63 BindingPointInfo GetNetworkOutputBindingInfo(const std::string& name) const; 64 65 private: 66 IOnnxParser(); 67 ~IOnnxParser(); 68 69 std::unique_ptr<OnnxParserImpl> pOnnxParserImpl; 70 }; 71 72 } 73