126 auto tensors = reader.
tensors();
130 os <<
"Operands: T(subgraph index : tensor index) TYPE (shape) (shape_signature) "
131 <<
"B(buffer index) (variable) OperandName" << std::endl;
132 for (uint32_t i = 0; i < tensors->size(); ++i)
135 auto tensor = tensors->Get(i);
136 std::vector<int32_t> dims = {-1};
143 os <<
"(" << dims <<
") ";
144 if (tensor->shape_signature())
147 os <<
"(" << dims_sig <<
") ";
149 os <<
"B(" << tensor->buffer() <<
") ";
150 if (tensor->is_variable())
156 if (
auto q_params = tensor->quantization())
158 if ((q_params->min() && q_params->max()) || (q_params->scale() && q_params->zero_point()))
160 std::string strquantiz =
" Quantization: ";
161 std::string strqindent(strquantiz.size(),
' ');
166 os <<
"min(" << q_params->min() <<
") ";
167 if (q_params->min()->size() > 1)
168 os << std::endl << strqindent;
172 os <<
"max(" << q_params->max() <<
") ";
173 if (q_params->max()->size() > 1)
174 os << std::endl << strqindent;
176 if (q_params->scale())
178 os <<
"scale(" << q_params->scale() <<
") ";
179 if (q_params->scale()->size() > 1)
180 os << std::endl << strqindent;
182 if (q_params->zero_point())
184 os <<
"zeropt(" << q_params->zero_point() <<
") ";
185 if (q_params->zero_point()->size() > 1)
186 os << std::endl << strqindent;
188 os <<
"quantized_dimension(" << q_params->quantized_dimension() <<
")";
194 if (
const auto &s_params = tensor->sparsity())
196 std::string strsparsity =
" Sparsity: ";
197 std::string strsindent(strsparsity.size(),
' ');
200 if (s_params->traversal_order())
202 os <<
"traversal_order(" << s_params->traversal_order() <<
") ";
203 os << std::endl << strsindent;
205 if (s_params->block_map())
207 os <<
"block_map(" << s_params->block_map() <<
") ";
208 os << std::endl << strsindent;
210 if (
const auto &dim_metadata = s_params->dim_metadata())
213 for (
const auto &dm : *dim_metadata)
215 std::string strdm =
"dim_metadata[" + std::to_string(idx++) +
"]: ";
216 std::string strdm_indent = strsindent + std::string(strdm.size(),
' ');
219 os <<
"format(" << tflite::EnumNameDimensionType(dm->format()) <<
") ";
220 os << std::endl << strdm_indent;
222 os <<
"dense_size(" << dm->dense_size() <<
") ";
223 os << std::endl << strdm_indent;
225 os <<
"array_segments_type("
226 << tflite::EnumNameSparseIndexVector(dm->array_segments_type()) <<
") ";
227 os << std::endl << strdm_indent;
229 os <<
"array_segments(";
230 switch (dm->array_segments_type())
232 case tflite::SparseIndexVector_NONE:
235 case tflite::SparseIndexVector_Int32Vector:
236 os << dm->array_segments_as_Int32Vector()->values();
238 case tflite::SparseIndexVector_Uint16Vector:
239 os << dm->array_segments_as_Uint16Vector()->values();
241 case tflite::SparseIndexVector_Uint8Vector:
242 os << dm->array_segments_as_Uint8Vector()->values();
245 throw std::runtime_error(
"Invalid SparseIndexVector type of array_segments");
247 os <<
")" << std::endl << strdm_indent;
249 os <<
"array_indices_type(" << tflite::EnumNameSparseIndexVector(dm->array_indices_type())
251 os << std::endl << strdm_indent;
253 os <<
"array_indices(";
254 switch (dm->array_indices_type())
256 case tflite::SparseIndexVector_NONE:
259 case tflite::SparseIndexVector_Int32Vector:
260 os << dm->array_indices_as_Int32Vector()->values();
262 case tflite::SparseIndexVector_Uint16Vector:
263 os << dm->array_indices_as_Uint16Vector()->values();
265 case tflite::SparseIndexVector_Uint8Vector:
266 os << dm->array_indices_as_Uint8Vector()->values();
269 throw std::runtime_error(
"Invalid SparseIndexVector type of array_indices");
271 os <<
")" << std::endl << strsindent;
279 os <<
"Operators: O(subgraph index : operator index) OpCodeName " << std::endl;
280 os <<
" Option(values) ... <-- depending on OpCode" << std::endl;
281 os <<
" I T(tensor index) OperandName <-- as input" << std::endl;
282 os <<
" O T(tensor index) OperandName <-- as output" << std::endl;
283 for (uint32_t i = 0; i < operators->size(); ++i)
285 const auto op = operators->Get(i);
286 tflite::BuiltinOperator builtincode = reader.
builtin_code(op);
292 os <<
"O(" << reader.
subgraph_index() <<
":" << i <<
") " << op_name <<
" ";
297 op_prn->options(op, os);
300 for (
auto input : inputs)
305 auto tensor = tensors->Get(input);
310 for (
auto output : outputs)
312 os <<
" O T(" << reader.
subgraph_index() <<
":" << output <<
") ";
315 auto tensor = tensors->Get(output);
324 os <<
"Inputs/Outputs: I(input)/O(output) T(tensor index) OperandName" << std::endl;
326 for (
const auto input : reader.
inputs())
328 auto tensor = tensors->Get(input);
330 os <<
"I T(" << reader.
subgraph_index() <<
":" << input <<
") " << name << std::endl;
333 for (
const auto output : reader.
outputs())
335 auto tensor = tensors->Get(output);
337 os <<
"O T(" << reader.
subgraph_index() <<
":" << output <<
") " << name << std::endl;
343void dump_model(std::ostream &os,
const tflite::Model *model,
const std::vector<char> *rawdata)
350 os <<
"===================================================================" << std::endl;
351 os <<
"Model version: " << reader.
version() << std::endl;
352 os <<
" # sub graphs: " << num_subgraph << std::endl;
355 auto opcodes = reader.
opcodes();
356 auto buffers = reader.
buffers();
361 os <<
"Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl;
362 int32_t opcode_index = 0;
363 for (
auto opcode : opcodes)
365 tflite::BuiltinOperator op_code = opcode->builtin_code();
366 tflite::BuiltinOperator dp_code = tflite::BuiltinOperator(opcode->deprecated_builtin_code());
369 auto op_version = opcode->version();
371 os <<
"[" << opcode_index <<
"] " << op_name <<
" (code: " << op_code
372 <<
", dep_code: " << dp_code <<
", version: " << op_version <<
")" << std::endl;
379 os <<
"Buffers: B(index) (length) values, if any; (length *) for ext_offset" << std::endl;
380 for (uint32_t i = 0; i < buffers->size(); ++i)
382 bool ext_offset =
false;
383 const uint8_t *buff_data;
386 os <<
"B(" << i <<
") (" <<
size;
390 if (buff_data !=
nullptr)
399 if (metadata !=
nullptr)
401 os <<
"metadata : B(index) name" << std::endl;
402 for (uint32_t i = 0; i < metadata->size(); ++i)
404 os <<
"B(" << metadata->Get(i)->buffer() <<
") " << metadata->Get(i)->name()->c_str()
411 if (signaturedefs !=
nullptr)
413 os <<
"SignatureDef" << std::endl;
414 for (uint32_t i = 0; i < signaturedefs->size(); ++i)
416 auto sign_i = signaturedefs->Get(i);
417 os <<
"S(" << i <<
") signature_key(" << sign_i->signature_key()->c_str() <<
"), sub_graph("
418 << sign_i->subgraph_index() <<
")" << std::endl;
420 auto inputs_i = sign_i->inputs();
421 for (uint32_t t = 0; t < inputs_i->size(); ++t)
423 auto inputs_i_t = inputs_i->Get(t);
424 os <<
" I(" << t <<
")"
425 <<
" T(" << sign_i->subgraph_index() <<
":" << inputs_i_t->tensor_index() <<
") "
426 << inputs_i_t->name()->c_str() << std::endl;
429 auto outputs_i = sign_i->outputs();
430 for (uint32_t t = 0; t < outputs_i->size(); ++t)
432 auto outputs_i_t = outputs_i->Get(t);
433 os <<
" O(" << t <<
")"
434 <<
" T(" << sign_i->subgraph_index() <<
":" << outputs_i_t->tensor_index() <<
") "
435 << outputs_i_t->name()->c_str() << std::endl;
441 for (uint32_t sg = 0; sg < num_subgraph; ++sg)
445 os <<
"-------------------------------------------------------------------" << std::endl;
446 os <<
"Sub-Graph: #" << sg <<
" " << reader.
subgraph_name() << std::endl;
452 os <<
"===================================================================" << std::endl;