ArmNN  NotReleased
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 3566 of file TfParser.cpp.

References CHECK_LOCATION.

3569 {
3570  FILE* fd = fopen(graphFile, "rb");
3571 
3572  if (fd == nullptr)
3573  {
3574  throw FileNotFoundException(
3575  boost::str(
3576  boost::format(
3577  "Graph file %1% failed to open %2%")
3578  % graphFile
3579  % CHECK_LOCATION().AsString()));
3580  }
3581 
3582  // Parses the file into a message.
3583  tensorflow::GraphDef graphDef;
3584 
3585  google::protobuf::io::FileInputStream inStream(fileno(fd));
3586  google::protobuf::io::CodedInputStream codedStream(&inStream);
3587  codedStream.SetTotalBytesLimit(INT_MAX, INT_MAX);
3588  bool success = graphDef.ParseFromCodedStream(&codedStream);
3589  fclose(fd);
3590 
3591  if (!success)
3592  {
3593  throw ParseException(
3594  boost::str(
3595  boost::format(
3596  "Failed to parse protobuf file %1% %2%")
3597  % graphFile
3598  % CHECK_LOCATION().AsString()));
3599  }
3600 
3601  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3602 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

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

References CHECK_LOCATION.

3549 {
3550  // Parses the string into a message.
3551  tensorflow::GraphDef graphDef;
3552  bool success = google::protobuf::TextFormat::ParseFromString(protoText, &graphDef);
3553 
3554  if (!success)
3555  {
3556  throw ParseException(
3557  boost::str(
3558  boost::format(
3559  "Failed to parse graph file %1%")
3560  % CHECK_LOCATION().AsString()));
3561  }
3562 
3563  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3564 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

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

References CHECK_LOCATION.

3514 {
3515  FILE* fd = fopen(graphFile, "r");
3516 
3517  if (fd == nullptr)
3518  {
3519  throw FileNotFoundException(
3520  boost::str(
3521  boost::format(
3522  "Graph file %1% failed to open %2%")
3523  % graphFile
3524  % CHECK_LOCATION().AsString()));
3525  }
3526 
3527  // Parses the file into a message.
3528  tensorflow::GraphDef graphDef;
3529  auto input = new google::protobuf::io::FileInputStream(fileno(fd));
3530  bool success = google::protobuf::TextFormat::Parse(input, &graphDef);
3531  delete input;
3532  fclose(fd);
3533 
3534  if (!success)
3535  {
3536  throw ParseException(
3537  boost::str(
3538  boost::format(
3539  "Failed to parse graph file %1%")
3540  % CHECK_LOCATION().AsString()));
3541  }
3542 
3543  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3544 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169

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

3646 {
3647  return GetBindingInfo(name, "input", m_NetworkInputsBindingInfo);
3648 }

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

References CHECK_LOCATION, and IConnectableLayer::GetName().

3651 {
3652  return GetBindingInfo(name, "output", m_NetworkOutputsBindingInfo);
3653 }

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: