ONE - On-device Neural Engine
Loading...
Searching...
No Matches
tflchef::TFliteImport Class Reference

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

#include <TFliteImport.h>

Collaboration diagram for tflchef::TFliteImport:

Public Member Functions

 TFliteImport (const tflite::Model *model)
 
 TFliteImport ()=delete
 
bool select_sub_graph (uint32_t subgraph)
 
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
 
tflite::BuiltinOperator builtin_code (const tflite::Operator *op) const
 
std::string opcode_name (const tflite::Operator *op) const
 
size_t buffer_info (const tflite::Tensor *tensor, const uint8_t **buff_data)
 
- Public Member Functions inherited from souschef::TensorFiller
virtual ~TensorFiller ()=default
 
void set_tensor_filler (uint32_t tensor_index)
 This will record the tensor by index, if it needs filler option, such as kernel, bias.
 
void set_tensor_filler (uint32_t tensor_index, std::vector< int32_t > &expvalues)
 This will store int32 filler values such as reshape information for the tensor.
 
void set_tensor_filler (uint32_t tensor_index, std::vector< float > &expvalues)
 
bool get_tensor_filler (uint32_t tensor_index)
 This will return true if the tensor by index, needs a filler option.
 
bool get_tensor_filler (uint32_t tensor_index, std::vector< int32_t > &expvalues)
 This will return true if the tensor by index, needs a int array filler option.
 
bool get_tensor_filler (uint32_t tensor_index, std::vector< float > &expvalues)
 
void clear_tensor_filler ()
 
void clear_tensor_filler_vint32 ()
 
void clear_tensor_filler_vfloat ()
 

Detailed Description

Loads TF lite file and provides helpers to access attributes.

Definition at line 40 of file TFliteImport.h.

Constructor & Destructor Documentation

◆ TFliteImport() [1/2]

tflchef::TFliteImport::TFliteImport ( const tflite::Model *  model)

Definition at line 28 of file TFliteImport.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}

◆ TFliteImport() [2/2]

tflchef::TFliteImport::TFliteImport ( )
delete

Member Function Documentation

◆ buffer_info()

size_t tflchef::TFliteImport::buffer_info ( const tflite::Tensor *  tensor,
const uint8_t **  buff_data 
)

Definition at line 101 of file TFliteImport.cpp.

102{
103 *buff_data = nullptr;
104
105 if (tensor->buffer() == 0)
106 return 0;
107
108 if (auto *buffer = (*_buffers)[tensor->buffer()])
109 {
110 if (auto *array = buffer->data())
111 {
112 if (size_t size = array->size())
113 {
114 *buff_data = reinterpret_cast<const uint8_t *>(array->data());
115 return size;
116 }
117 }
118 }
119
120 return 0;
121}
int32_t size[5]
Definition Slice.cpp:35

References size.

◆ buffers()

const TFliteBuffers_t * tflchef::TFliteImport::buffers ( )
inline

Definition at line 51 of file TFliteImport.h.

51{ return _buffers; }

Referenced by tflchef::generate_recipe().

◆ builtin_code()

tflite::BuiltinOperator tflchef::TFliteImport::builtin_code ( const tflite::Operator *  op) const

Definition at line 67 of file TFliteImport.cpp.

68{
69 uint32_t index = op->opcode_index();
70 assert(index < _op_codes.size());
71 const tflite::OperatorCode *opcode = _op_codes.at(index);
72
74}
::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 tflchef::generate_recipe().

◆ inputs()

const std::vector< int32_t > & tflchef::TFliteImport::inputs ( ) const
inline

◆ num_subgraph()

uint32_t tflchef::TFliteImport::num_subgraph ( ) const
inline

Definition at line 57 of file TFliteImport.h.

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

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

Referenced by tflchef::generate_recipe().

◆ opcode_name()

std::string tflchef::TFliteImport::opcode_name ( const tflite::Operator *  op) const

Definition at line 76 of file TFliteImport.cpp.

77{
78 uint32_t index = op->opcode_index();
79 assert(index < _op_codes.size());
80 const tflite::OperatorCode *opcode = _op_codes.at(index);
81
82 if (!mio::tflite::is_valid(opcode))
83 {
84 std::ostringstream oss;
85 oss << "(invalid: " << index << ")";
86 return oss.str();
87 }
88
89 if (mio::tflite::is_custom(opcode))
90 {
91 if (!opcode->custom_code())
92 return "(invalid custom)";
93
94 return opcode->custom_code()->c_str();
95 }
96
97 tflite::BuiltinOperator code = mio::tflite::builtin_code_neutral(opcode);
98 return EnumNameBuiltinOperator(code);
99}
Code * code(const SessionID &sess)
Definition Session.cpp:54
bool is_valid(const ::tflite::OperatorCode *opcode)
Definition Helper.cpp:40
bool is_custom(const ::tflite::OperatorCode *opcode)
Definition Helper.cpp:55

References mio::tflite::builtin_code_neutral(), mio::tflite::is_custom(), and mio::tflite::is_valid().

Referenced by tflchef::generate_recipe().

◆ operators()

const TFliteOperators_t * tflchef::TFliteImport::operators ( )
inline

Definition at line 53 of file TFliteImport.h.

53{ return _operators; }

Referenced by tflchef::generate_recipe().

◆ outputs()

const std::vector< int32_t > & tflchef::TFliteImport::outputs ( ) const
inline

◆ select_sub_graph()

bool tflchef::TFliteImport::select_sub_graph ( uint32_t  subgraph)

Definition at line 40 of file TFliteImport.cpp.

41{
42 _tensors = nullptr;
43 _operators = nullptr;
44 _inputs.clear();
45 _outputs.clear();
49
50 if (_subgraphs->size() <= sgindex)
51 {
52 assert(false);
53 return false;
54 }
55
56 const tflite::SubGraph *subgraph = (*_subgraphs)[sgindex];
57
58 _tensors = subgraph->tensors();
59 _operators = subgraph->operators();
60
61 _inputs = as_index_vector(subgraph->inputs());
62 _outputs = as_index_vector(subgraph->outputs());
63
64 return true;
65}
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Convert.h:47

References tflchef::as_index_vector(), souschef::TensorFiller::clear_tensor_filler(), souschef::TensorFiller::clear_tensor_filler_vfloat(), souschef::TensorFiller::clear_tensor_filler_vint32(), and flatbuffers::Vector< T >::size().

Referenced by tflchef::generate_recipe().

◆ tensors()

const TFliteTensors_t * tflchef::TFliteImport::tensors ( )
inline

Definition at line 52 of file TFliteImport.h.

52{ return _tensors; }

Referenced by tflchef::generate_recipe().


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