ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tflinspect::Reader Class Reference

Loads TF lite file and provides helpers to access attributes. More...

#include <Reader.h>

Public Member Functions

 Reader (const tflite::Model *model)
 
 Reader ()=delete
 
const std::vector< const tflite::OperatorCode * > & opcodes ()
 
const TFliteBuffers_tbuffers ()
 
const TFliteTensors_ttensors ()
 
const TFliteOperators_toperators ()
 
const std::vector< int32_t > & inputs () const
 
const std::vector< int32_t > & outputs () const
 
uint32_t num_subgraph () const
 
size_t buffer_info (uint32_t buf_idx, const uint8_t **buff_data)
 
tflite::BuiltinOperator builtin_code (const tflite::Operator *op) const
 
std::string opcode_name (const tflite::Operator *op) const
 
bool select_subgraph (uint32_t subgraph)
 

Detailed Description

Loads TF lite file and provides helpers to access attributes.

Definition at line 42 of file Reader.h.

Constructor & Destructor Documentation

◆ Reader() [1/2]

tflinspect::Reader::Reader ( const tflite::Model *  model)

Definition at line 28 of file Reader.cpp.

29{
30 _subgraphs = model->subgraphs();
31 _buffers = model->buffers();
32
33 auto opcodes = model->operator_codes();
34 for (const ::tflite::OperatorCode *opcode : *opcodes)
35 {
36 _op_codes.push_back(opcode);
37 }
38}
const std::vector< const tflite::OperatorCode * > & opcodes()
Definition Reader.h:56

References opcodes().

◆ Reader() [2/2]

tflinspect::Reader::Reader ( )
delete

Member Function Documentation

◆ buffer_info()

size_t tflinspect::Reader::buffer_info ( uint32_t  buf_idx,
const uint8_t **  buff_data 
)

Definition at line 40 of file Reader.cpp.

41{
42 if (buff_data != nullptr)
43 {
44 *buff_data = nullptr;
45 }
46
47 if (buf_idx == 0)
48 return 0;
49
50 if (auto *buffer = (*_buffers)[buf_idx])
51 {
52 if (auto *array = buffer->data())
53 {
54 if (size_t size = array->size())
55 {
56 if (buff_data != nullptr)
57 {
58 *buff_data = reinterpret_cast<const uint8_t *>(array->data());
59 }
60 return size;
61 }
62 }
63 }
64
65 return 0;
66}
int32_t size[5]
Definition Slice.cpp:35

References size.

◆ buffers()

const TFliteBuffers_t * tflinspect::Reader::buffers ( )
inline

Definition at line 57 of file Reader.h.

57{ return _buffers; }

◆ builtin_code()

tflite::BuiltinOperator tflinspect::Reader::builtin_code ( const tflite::Operator *  op) const

Definition at line 68 of file Reader.cpp.

69{
70 uint32_t index = op->opcode_index();
71 assert(index < _op_codes.size());
72 const tflite::OperatorCode *opcode = _op_codes.at(index);
73
75}
::tflite::BuiltinOperator builtin_code_neutral(const ::tflite::OperatorCode *opcode)
Definition Helper.cpp:33
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References mio::tflite::builtin_code_neutral().

Referenced by tflinspect::DumpConv2DWeight::run().

◆ inputs()

const std::vector< int32_t > & tflinspect::Reader::inputs ( ) const
inline

Definition at line 60 of file Reader.h.

60{ return _inputs; }

Referenced by validate_onnx2circle.OnnxRunner::feed_random_inputs(), and package.infer.session::set_inputs().

◆ num_subgraph()

uint32_t tflinspect::Reader::num_subgraph ( ) const
inline

Definition at line 63 of file Reader.h.

63{ return _subgraphs->size(); }
uoffset_t size() const

References flatbuffers::Vector< T >::size().

Referenced by tflinspect::DumpOperators::run(), tflinspect::DumpConv2DWeight::run(), and tflinspect::DumpOperatorVersion::run().

◆ opcode_name()

std::string tflinspect::Reader::opcode_name ( const tflite::Operator *  op) const

Definition at line 77 of file Reader.cpp.

78{
79 uint32_t index = op->opcode_index();
80 assert(index < _op_codes.size());
81 const tflite::OperatorCode *opcode = _op_codes.at(index);
82
83 if (!mio::tflite::is_valid(opcode))
84 {
85 std::ostringstream oss;
86 oss << "(invalid: " << index << ")";
87 return oss.str();
88 }
89
90 return mio::tflite::opcode_name(opcode);
91}
std::string opcode_name(const ::tflite::OperatorCode *opcode)
Definition Helper.cpp:61
bool is_valid(const ::tflite::OperatorCode *opcode)
Definition Helper.cpp:40

References mio::tflite::is_valid(), and mio::tflite::opcode_name().

Referenced by tflinspect::DumpOperators::run(), tflinspect::DumpConv2DWeight::run(), and tflinspect::DumpOperatorVersion::run().

◆ opcodes()

const std::vector< const tflite::OperatorCode * > & tflinspect::Reader::opcodes ( )
inline

Definition at line 56 of file Reader.h.

56{ return _op_codes; }

Referenced by Reader(), and tflinspect::DumpOperatorVersion::run().

◆ operators()

const TFliteOperators_t * tflinspect::Reader::operators ( )
inline

Definition at line 59 of file Reader.h.

59{ return _operators; }

Referenced by tflinspect::DumpOperators::run(), tflinspect::DumpConv2DWeight::run(), and tflinspect::DumpOperatorVersion::run().

◆ outputs()

const std::vector< int32_t > & tflinspect::Reader::outputs ( ) const
inline

◆ select_subgraph()

bool tflinspect::Reader::select_subgraph ( uint32_t  subgraph)

Definition at line 93 of file Reader.cpp.

94{
95 _tensors = nullptr;
96 _operators = nullptr;
97
98 _inputs.clear();
99 _outputs.clear();
100
101 if (_subgraphs->size() <= sgindex)
102 {
103 assert(false);
104 return false;
105 }
106
107 const tflite::SubGraph *subgraph = (*_subgraphs)[sgindex];
108
109 _tensors = subgraph->tensors();
110 _operators = subgraph->operators();
111
112 _inputs = as_index_vector(subgraph->inputs());
113 _outputs = as_index_vector(subgraph->outputs());
114
115 return true;
116}
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Reader.h:29

References tflinspect::as_index_vector(), and flatbuffers::Vector< T >::size().

Referenced by tflinspect::DumpOperators::run(), tflinspect::DumpConv2DWeight::run(), and tflinspect::DumpOperatorVersion::run().

◆ tensors()

const TFliteTensors_t * tflinspect::Reader::tensors ( )
inline

Definition at line 58 of file Reader.h.

58{ return _tensors; }

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