ArmNN
 20.02
TfParser Class Reference

#include <TfParser.hpp>

Inheritance diagram for TfParser:
ITfParser

Public Member Functions

virtual armnn::INetworkPtr CreateNetworkFromTextFile (const char *graphFile, const std::map< std::string, armnn::TensorShape > &inputShapes, const std::vector< std::string > &requestedOutputs) override
 Creates the network from a protobuf text file on the disk. More...
 
virtual armnn::INetworkPtr CreateNetworkFromBinaryFile (const char *graphFile, const std::map< std::string, armnn::TensorShape > &inputShapes, const std::vector< std::string > &requestedOutputs) override
 Creates the network from a protobuf binary file on the disk. More...
 
virtual armnn::INetworkPtr CreateNetworkFromString (const char *protoText, const std::map< std::string, armnn::TensorShape > &inputShapes, const std::vector< std::string > &requestedOutputs) override
 Creates the network directly from protobuf text in a string. Useful for debugging/testing. More...
 
virtual BindingPointInfo GetNetworkInputBindingInfo (const std::string &name) const override
 Retrieves binding info (layer id and tensor info) for the network input identified by the given layer name. More...
 
virtual BindingPointInfo GetNetworkOutputBindingInfo (const std::string &name) const override
 Retrieves binding info (layer id and tensor info) for the network output identified by the given layer name. More...
 
 TfParser ()
 

Friends

template<typename T >
class ParsedConstTfOperation
 
class ParsedMatMulTfOperation
 
class ParsedMulTfOperation
 

Additional Inherited Members

- Static Public Member Functions inherited from ITfParser
static ITfParserCreateRaw ()
 
static ITfParserPtr Create ()
 
static void Destroy (ITfParser *parser)
 
- Protected Member Functions inherited from ITfParser
virtual ~ITfParser ()
 

Detailed Description

Definition at line 64 of file TfParser.hpp.

Constructor & Destructor Documentation

◆ TfParser()

Member Function Documentation

◆ CreateNetworkFromBinaryFile()

INetworkPtr CreateNetworkFromBinaryFile ( const char *  graphFile,
const std::map< std::string, armnn::TensorShape > &  inputShapes,
const std::vector< std::string > &  requestedOutputs 
)
overridevirtual

Creates the network from a protobuf binary file on the disk.

Implements ITfParser.

Definition at line 3615 of file TfParser.cpp.

References CHECK_LOCATION.

3618 {
3619  FILE* fd = fopen(graphFile, "rb");
3620 
3621  if (fd == nullptr)
3622  {
3623  throw FileNotFoundException(
3624  boost::str(
3625  boost::format(
3626  "Graph file %1% failed to open %2%")
3627  % graphFile
3628  % CHECK_LOCATION().AsString()));
3629  }
3630 
3631  // Parses the file into a message.
3632  tensorflow::GraphDef graphDef;
3633 
3634  google::protobuf::io::FileInputStream inStream(fileno(fd));
3635  google::protobuf::io::CodedInputStream codedStream(&inStream);
3636  codedStream.SetTotalBytesLimit(INT_MAX, INT_MAX);
3637  bool success = graphDef.ParseFromCodedStream(&codedStream);
3638  fclose(fd);
3639 
3640  if (!success)
3641  {
3642  throw ParseException(
3643  boost::str(
3644  boost::format(
3645  "Failed to parse protobuf file %1% %2%")
3646  % graphFile
3647  % CHECK_LOCATION().AsString()));
3648  }
3649 
3650  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3651 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ CreateNetworkFromString()

INetworkPtr CreateNetworkFromString ( const char *  protoText,
const std::map< std::string, armnn::TensorShape > &  inputShapes,
const std::vector< std::string > &  requestedOutputs 
)
overridevirtual

Creates the network directly from protobuf text in a string. Useful for debugging/testing.

Implements ITfParser.

Definition at line 3595 of file TfParser.cpp.

References CHECK_LOCATION.

3598 {
3599  // Parses the string into a message.
3600  tensorflow::GraphDef graphDef;
3601  bool success = google::protobuf::TextFormat::ParseFromString(protoText, &graphDef);
3602 
3603  if (!success)
3604  {
3605  throw ParseException(
3606  boost::str(
3607  boost::format(
3608  "Failed to parse graph file %1%")
3609  % CHECK_LOCATION().AsString()));
3610  }
3611 
3612  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3613 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ CreateNetworkFromTextFile()

INetworkPtr CreateNetworkFromTextFile ( const char *  graphFile,
const std::map< std::string, armnn::TensorShape > &  inputShapes,
const std::vector< std::string > &  requestedOutputs 
)
overridevirtual

Creates the network from a protobuf text file on the disk.

Implements ITfParser.

Definition at line 3560 of file TfParser.cpp.

References CHECK_LOCATION.

3563 {
3564  FILE* fd = fopen(graphFile, "r");
3565 
3566  if (fd == nullptr)
3567  {
3568  throw FileNotFoundException(
3569  boost::str(
3570  boost::format(
3571  "Graph file %1% failed to open %2%")
3572  % graphFile
3573  % CHECK_LOCATION().AsString()));
3574  }
3575 
3576  // Parses the file into a message.
3577  tensorflow::GraphDef graphDef;
3578  auto input = new google::protobuf::io::FileInputStream(fileno(fd));
3579  bool success = google::protobuf::TextFormat::Parse(input, &graphDef);
3580  delete input;
3581  fclose(fd);
3582 
3583  if (!success)
3584  {
3585  throw ParseException(
3586  boost::str(
3587  boost::format(
3588  "Failed to parse graph file %1%")
3589  % CHECK_LOCATION().AsString()));
3590  }
3591 
3592  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3593 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ GetNetworkInputBindingInfo()

BindingPointInfo GetNetworkInputBindingInfo ( const std::string &  name) const
overridevirtual

Retrieves binding info (layer id and tensor info) for the network input identified by the given layer name.

Implements ITfParser.

Definition at line 3694 of file TfParser.cpp.

3695 {
3696  return GetBindingInfo(name, "input", m_NetworkInputsBindingInfo);
3697 }

◆ GetNetworkOutputBindingInfo()

BindingPointInfo GetNetworkOutputBindingInfo ( const std::string &  name) const
overridevirtual

Retrieves binding info (layer id and tensor info) for the network output identified by the given layer name.

Implements ITfParser.

Definition at line 3699 of file TfParser.cpp.

References CHECK_LOCATION, and IConnectableLayer::GetName().

3700 {
3701  return GetBindingInfo(name, "output", m_NetworkOutputsBindingInfo);
3702 }

Friends And Related Function Documentation

◆ ParsedConstTfOperation

friend class ParsedConstTfOperation
friend

Definition at line 96 of file TfParser.hpp.

Referenced by TfParser::TfParser().

◆ ParsedMatMulTfOperation

friend class ParsedMatMulTfOperation
friend

Definition at line 97 of file TfParser.hpp.

Referenced by armnnTfParser::OutputShapeOfSqueeze().

◆ ParsedMulTfOperation

friend class ParsedMulTfOperation
friend

Definition at line 98 of file TfParser.hpp.

Referenced by armnnTfParser::OutputShapeOfSqueeze().


The documentation for this class was generated from the following files: