30 _version = model->version();
31 _subgraphs = model->subgraphs();
32 _buffers = model->buffers();
33 _metadata = model->metadata();
34 _signaturedefs = model->signature_defs();
36 auto opcodes = model->operator_codes();
37 for (const ::tflite::OperatorCode *opcode : *
opcodes)
39 _op_codes.push_back(opcode);
47 _version = model->version();
48 _subgraphs = model->subgraphs();
49 _buffers = model->buffers();
50 _metadata = model->metadata();
51 _signaturedefs = model->signature_defs();
53 auto opcodes = model->operator_codes();
54 for (const ::tflite::OperatorCode *opcode : *
opcodes)
56 _op_codes.push_back(opcode);
67 if (
auto *buffer = (*_buffers)[buf_idx])
69 if (
auto *array = buffer->data())
71 if (
size_t size = array->size())
73 *buff_data =
reinterpret_cast<const uint8_t *
>(array->data());
90 if (
auto *buffer = (*_buffers)[buf_idx])
92 auto buffer_offset = buffer->offset();
93 if (buffer->offset() > 1)
96 if (_rawdata ==
nullptr)
100 *buff_data =
reinterpret_cast<const uint8_t *
>(&_rawdata->at(buffer_offset));
101 return buffer->size();
103 else if (
auto *array = buffer->data())
105 if (
size_t size = array->size())
107 *buff_data =
reinterpret_cast<const uint8_t *
>(array->data());
113 if (buffer->offset() == 1 && buffer->size() == 1)
115 std::cerr <<
"Buffer " << buf_idx <<
" has invalid offset/size." << std::endl;
125 uint32_t index = op->opcode_index();
126 assert(index < _op_codes.size());
127 const tflite::OperatorCode *opcode = _op_codes.at(index);
134 uint32_t index = op->opcode_index();
135 assert(index < _op_codes.size());
136 const tflite::OperatorCode *opcode = _op_codes.at(index);
140 std::ostringstream oss;
141 oss <<
"(invalid: " << index <<
")";
150 _subgraph_index = sgindex;
152 _operators =
nullptr;
157 if (_subgraphs->
size() <= sgindex)
163 const tflite::SubGraph *subgraph = (*_subgraphs)[sgindex];
165 auto name = subgraph->name();
166 _subgraph_name = name ? name->c_str() :
"(noname)";
168 _tensors = subgraph->tensors();
169 _operators = subgraph->operators();
const std::vector< const tflite::OperatorCode * > & opcodes()
tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const
size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data)
bool select_subgraph(uint32_t subgraph)
std::string opcode_name(const tflite::Operator *op) const
std::string opcode_name(const ::tflite::OperatorCode *opcode)
bool is_valid(const ::tflite::OperatorCode *opcode)
::tflite::BuiltinOperator builtin_code_neutral(const ::tflite::OperatorCode *opcode)
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)