ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circlechef::CircleImport Class Reference

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

#include <CircleImport.h>

Collaboration diagram for circlechef::CircleImport:

Public Member Functions

 CircleImport (const circle::Model *model)
 
 CircleImport ()=delete
 
bool select_sub_graph (uint32_t subgraph)
 
const CircleBuffers_tbuffers ()
 
const CircleTensors_ttensors ()
 
const CircleOperators_toperators ()
 
const std::vector< int32_t > & inputs () const
 
const std::vector< int32_t > & outputs () const
 
uint32_t num_subgraph () const
 
circle::BuiltinOperator builtin_code (const circle::Operator *op) const
 
std::string opcode_name (const circle::Operator *op) const
 
size_t buffer_info (const circle::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 CircleImport.h.

Constructor & Destructor Documentation

◆ CircleImport() [1/2]

circlechef::CircleImport::CircleImport ( const circle::Model *  model)

Definition at line 28 of file CircleImport.cpp.

29{
30 _subgraphs = model->subgraphs();
31 _buffers = model->buffers();
32
33 auto opcodes = model->operator_codes();
34 for (const ::circle::OperatorCode *opcode : *opcodes)
35 {
36 _op_codes.push_back(opcode);
37 }
38}

◆ CircleImport() [2/2]

circlechef::CircleImport::CircleImport ( )
delete

Member Function Documentation

◆ buffer_info()

size_t circlechef::CircleImport::buffer_info ( const circle::Tensor *  tensor,
const uint8_t **  buff_data 
)

Definition at line 98 of file CircleImport.cpp.

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

References size.

◆ buffers()

const CircleBuffers_t * circlechef::CircleImport::buffers ( )
inline

Definition at line 51 of file CircleImport.h.

51{ return _buffers; }

Referenced by circlechef::generate_recipe().

◆ builtin_code()

circle::BuiltinOperator circlechef::CircleImport::builtin_code ( const circle::Operator *  op) const

Definition at line 64 of file CircleImport.cpp.

65{
66 uint32_t index = op->opcode_index();
67 assert(index < _op_codes.size());
68 const circle::OperatorCode *opcode = _op_codes.at(index);
69
71}
::circle::BuiltinOperator builtin_code_neutral(const ::circle::OperatorCode *opcode)
Definition Helper.cpp:33
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References mio::circle::builtin_code_neutral().

Referenced by circlechef::generate_recipe().

◆ inputs()

const std::vector< int32_t > & circlechef::CircleImport::inputs ( ) const
inline

◆ num_subgraph()

uint32_t circlechef::CircleImport::num_subgraph ( ) const
inline

Definition at line 57 of file CircleImport.h.

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

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

Referenced by circlechef::generate_recipe().

◆ opcode_name()

std::string circlechef::CircleImport::opcode_name ( const circle::Operator *  op) const

Definition at line 73 of file CircleImport.cpp.

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

References mio::circle::is_custom(), and mio::circle::is_valid().

Referenced by circlechef::generate_recipe().

◆ operators()

const CircleOperators_t * circlechef::CircleImport::operators ( )
inline

Definition at line 53 of file CircleImport.h.

53{ return _operators; }

Referenced by circlechef::generate_recipe().

◆ outputs()

const std::vector< int32_t > & circlechef::CircleImport::outputs ( ) const
inline

◆ select_sub_graph()

bool circlechef::CircleImport::select_sub_graph ( uint32_t  subgraph)

Definition at line 40 of file CircleImport.cpp.

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

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

Referenced by circlechef::generate_recipe().

◆ tensors()

const CircleTensors_t * circlechef::CircleImport::tensors ( )
inline

Definition at line 52 of file CircleImport.h.

52{ return _tensors; }

Referenced by circlechef::generate_recipe().


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