ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tflimport::TflOpCodeContext Class Reference

Class that holds operator codes and related methods. More...

#include <Context.h>

Public Member Functions

 TflOpCodeContext (const flatbuffers::Vector< flatbuffers::Offset< tflite::OperatorCode > > *opcodes)
 
tflite::BuiltinOperator builtin_code (const tflite::Operator *op) const
 Returns BuiltinOperator value of the operator.
 
std::string opcode_name (const tflite::Operator *op) const
 Returns human readable name of the operator code of the operator.
 

Static Public Member Functions

static bool is_valid (const tflite::OperatorCode *opcode)
 
static bool is_custom (const tflite::OperatorCode *opcode)
 

Detailed Description

Class that holds operator codes and related methods.

Definition at line 56 of file Context.h.

Constructor & Destructor Documentation

◆ TflOpCodeContext()

tflimport::TflOpCodeContext::TflOpCodeContext ( const flatbuffers::Vector< flatbuffers::Offset< tflite::OperatorCode > > *  opcodes)

Definition at line 50 of file Context.cpp.

52{
53 for (const tflite::OperatorCode *opcode : *opcodes)
54 {
55 _opcodes.push_back(opcode);
56 }
57}

Member Function Documentation

◆ builtin_code()

tflite::BuiltinOperator tflimport::TflOpCodeContext::builtin_code ( const tflite::Operator *  op) const

Returns BuiltinOperator value of the operator.

Definition at line 59 of file Context.cpp.

60{
61 uint32_t index = op->opcode_index();
62 assert(index < _opcodes.size());
63 const tflite::OperatorCode *opcode = _opcodes.at(index);
64 return opcode->builtin_code();
65}
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

◆ is_custom()

bool tflimport::TflOpCodeContext::is_custom ( const tflite::OperatorCode *  opcode)
static

Definition at line 98 of file Context.cpp.

99{
100 tflite::BuiltinOperator code = opcode->builtin_code();
101 return (code == tflite::BuiltinOperator_CUSTOM);
102}
Code * code(const SessionID &sess)
Definition Session.cpp:54

Referenced by opcode_name().

◆ is_valid()

bool tflimport::TflOpCodeContext::is_valid ( const tflite::OperatorCode *  opcode)
static

Definition at line 92 of file Context.cpp.

93{
94 tflite::BuiltinOperator code = opcode->builtin_code();
95 return (tflite::BuiltinOperator_MIN <= code && code <= tflite::BuiltinOperator_MAX);
96}

Referenced by opcode_name().

◆ opcode_name()

std::string tflimport::TflOpCodeContext::opcode_name ( const tflite::Operator *  op) const

Returns human readable name of the operator code of the operator.

Note
TF lite InterpreterBuilder sets an error state and returns error code for invalid opcode. Here we just return human readable message as this method returns a name for the operator code.

Definition at line 67 of file Context.cpp.

68{
69 uint32_t index = op->opcode_index();
70 assert(index < _opcodes.size());
71 const tflite::OperatorCode *opcode = _opcodes.at(index);
72
73 if (!is_valid(opcode))
74 {
75 std::ostringstream oss;
76 oss << "(invalid: " << index << ")";
77 return oss.str();
78 }
79
80 if (is_custom(opcode))
81 {
82 if (!opcode->custom_code())
83 return "(invalid custom)";
84
85 return opcode->custom_code()->c_str();
86 }
87
88 tflite::BuiltinOperator code = opcode->builtin_code();
89 return EnumNameBuiltinOperator(code);
90}
static bool is_custom(const tflite::OperatorCode *opcode)
Definition Context.cpp:98
static bool is_valid(const tflite::OperatorCode *opcode)
Definition Context.cpp:92

References is_custom(), and is_valid().


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