ArmNN
 20.11
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 3548 of file TfParser.cpp.

References CHECK_LOCATION.

3551 {
3552  FILE* fd = fopen(graphFile, "rb");
3553 
3554  if (fd == nullptr)
3555  {
3556  throw FileNotFoundException(
3557  fmt::format("Graph file {} failed to open {}",
3558  graphFile,
3559  CHECK_LOCATION().AsString()));
3560  }
3561 
3562  // Parses the file into a message.
3563  tensorflow::GraphDef graphDef;
3564 
3565  google::protobuf::io::FileInputStream inStream(fileno(fd));
3566  google::protobuf::io::CodedInputStream codedStream(&inStream);
3567  codedStream.SetTotalBytesLimit(INT_MAX);
3568  bool success = graphDef.ParseFromCodedStream(&codedStream);
3569  fclose(fd);
3570 
3571  if (!success)
3572  {
3573  throw ParseException(
3574  fmt::format("Failed to parse protobuf file {} {}",
3575  graphFile,
3576  CHECK_LOCATION().AsString()));
3577  }
3578 
3579  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3580 }
#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 3530 of file TfParser.cpp.

References CHECK_LOCATION.

3533 {
3534  // Parses the string into a message.
3535  tensorflow::GraphDef graphDef;
3536  bool success = google::protobuf::TextFormat::ParseFromString(protoText, &graphDef);
3537 
3538  if (!success)
3539  {
3540  throw ParseException(
3541  fmt::format("Failed to parse graph file {}",
3542  CHECK_LOCATION().AsString()));
3543  }
3544 
3545  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3546 }
#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 3499 of file TfParser.cpp.

References CHECK_LOCATION.

3502 {
3503  FILE* fd = fopen(graphFile, "r");
3504 
3505  if (fd == nullptr)
3506  {
3507  throw FileNotFoundException(
3508  fmt::format("Graph file {} failed to open {}",
3509  graphFile,
3510  CHECK_LOCATION().AsString()));
3511  }
3512 
3513  // Parses the file into a message.
3514  tensorflow::GraphDef graphDef;
3515  auto input = new google::protobuf::io::FileInputStream(fileno(fd));
3516  bool success = google::protobuf::TextFormat::Parse(input, &graphDef);
3517  delete input;
3518  fclose(fd);
3519 
3520  if (!success)
3521  {
3522  throw ParseException(
3523  fmt::format("Failed to parse graph file {}",
3524  CHECK_LOCATION().AsString()));
3525  }
3526 
3527  return CreateNetworkFromGraphDef(graphDef, inputShapes, requestedOutputs);
3528 }
#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 3621 of file TfParser.cpp.

3622 {
3623  return GetBindingInfo(name, "input", m_NetworkInputsBindingInfo);
3624 }

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

References CHECK_LOCATION, and IConnectableLayer::GetName().

3627 {
3628  return GetBindingInfo(name, "output", m_NetworkOutputsBindingInfo);
3629 }

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: