ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mio::tflite Namespace Reference

Functions

::tflite::BuiltinOperator builtin_code_neutral (const ::tflite::OperatorCode *opcode)
 
bool is_valid (const ::tflite::OperatorCode *opcode)
 
bool is_custom (const ::tflite::OperatorCode *opcode)
 
std::string opcode_name (const ::tflite::OperatorCode *opcode)
 
const char * tensor_type (const ::tflite::Tensor *tensor)
 
const char * tensor_name (const ::tflite::Tensor *tensor)
 

Function Documentation

◆ builtin_code_neutral()

tflite::BuiltinOperator mio::tflite::builtin_code_neutral ( const ::tflite::OperatorCode *  opcode)

This will provide v3/v3a format neutral BuiltinOperator

This function referenced https://github.com/tensorflow/tensorflow/blob/7d12007d7800d3714a02e05059f3ea602d1aec78/tensorflow/lite/schema/schema_utils.cc

Definition at line 33 of file Helper.cpp.

34{
35 assert(opcode != nullptr);
36 return std::max(opcode->builtin_code(),
37 static_cast<::tflite::BuiltinOperator>(opcode->deprecated_builtin_code()));
38}

Referenced by tflinspect::Reader::builtin_code(), tflchef::TFliteImport::builtin_code(), tflread::Reader::builtin_code(), is_custom(), opcode_name(), and tflchef::TFliteImport::opcode_name().

◆ is_custom()

bool mio::tflite::is_custom ( const ::tflite::OperatorCode *  opcode)

Definition at line 55 of file Helper.cpp.

56{
57 ::tflite::BuiltinOperator code = builtin_code_neutral(opcode);
58 return (code == ::tflite::BuiltinOperator_CUSTOM);
59}

References builtin_code_neutral().

Referenced by opcode_name(), and tflchef::TFliteImport::opcode_name().

◆ is_valid()

bool mio::tflite::is_valid ( const ::tflite::OperatorCode *  opcode)

Definition at line 40 of file Helper.cpp.

41{
42 // Valid Range : 0 <= deprecated_builtin_code <= 127
43 const int8_t deprecated_builtin_code = opcode->deprecated_builtin_code();
44 if (deprecated_builtin_code < 0)
45 return false;
46
47 const ::tflite::BuiltinOperator builtin_code = opcode->builtin_code();
48 if (!(::tflite::BuiltinOperator_MIN <= builtin_code &&
49 builtin_code <= ::tflite::BuiltinOperator_MAX))
50 return false;
51
52 return true;
53}

Referenced by opcode_name(), tflinspect::Reader::opcode_name(), tflchef::TFliteImport::opcode_name(), and tflread::Reader::opcode_name().

◆ opcode_name()

std::string mio::tflite::opcode_name ( const ::tflite::OperatorCode *  opcode)

Definition at line 61 of file Helper.cpp.

62{
63 assert(opcode);
64
65 if (!is_valid(opcode))
66 {
67 std::ostringstream oss;
68 oss << "(invalid)";
69 return oss.str();
70 }
71
72 if (is_custom(opcode))
73 {
74 if (!opcode->custom_code())
75 return "(invalid custom)";
76
77 std::string custom_op = "CUSTOM(";
78 custom_op += opcode->custom_code()->c_str();
79 custom_op += ")";
80 return custom_op;
81 }
82
83 ::tflite::BuiltinOperator code = builtin_code_neutral(opcode);
84 return ::tflite::EnumNameBuiltinOperator(code);
85}

References builtin_code_neutral(), is_custom(), and is_valid().

Referenced by tfldump::dump_model(), tflinspect::Reader::opcode_name(), and tflread::Reader::opcode_name().

◆ tensor_name()

const char * mio::tflite::tensor_name ( const ::tflite::Tensor *  tensor)

Definition at line 92 of file Helper.cpp.

93{
94 static const char *kEmptyTensorName = "(noname)";
95
96 auto name = tensor->name();
97 if (name)
98 return name->c_str();
99
100 return kEmptyTensorName;
101}

Referenced by tfldump::dump_sub_graph(), tflchef::generate_recipe(), tflchef::set_inputs(), and tflchef::set_outputs().

◆ tensor_type()

const char * mio::tflite::tensor_type ( const ::tflite::Tensor *  tensor)

Definition at line 87 of file Helper.cpp.

88{
89 return ::tflite::EnumNameTensorType(tensor->type());
90}

Referenced by tfldump::dump_sub_graph().