ArmNN
 20.08
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 3616 of file TfParser.cpp.

References CHECK_LOCATION.

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

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

References CHECK_LOCATION.

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

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

References CHECK_LOCATION.

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

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

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

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

References CHECK_LOCATION, and IConnectableLayer::GetName().

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

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: