ArmNN
 20.05
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 3614 of file TfParser.cpp.

References CHECK_LOCATION.

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

References CHECK_LOCATION.

3597 {
3598  // Parses the string into a message.
3599  tensorflow::GraphDef graphDef;
3600  bool success = google::protobuf::TextFormat::ParseFromString(protoText, &graphDef);
3601 
3602  if (!success)
3603  {
3604  throw ParseException(
3605  boost::str(
3606  boost::format(
3607  "Failed to parse graph file %1%")
3608  % CHECK_LOCATION().AsString()));
3609  }
3610 
3611  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3612 }
#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 3559 of file TfParser.cpp.

References CHECK_LOCATION.

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

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

◆ 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 3698 of file TfParser.cpp.

References CHECK_LOCATION, and IConnectableLayer::GetName().

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

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: