127 auto tensors = reader.
tensors();
131 os <<
"Operands: T(subgraph index : tensor index) TYPE (shape) (shape_signature) "
132 <<
"B(buffer index) (variable) OperandName" << std::endl;
133 for (uint32_t i = 0; i < tensors->size(); ++i)
136 auto tensor = tensors->Get(i);
137 std::vector<int32_t> dims = {-1};
144 os <<
"(" << dims <<
") ";
145 if (tensor->shape_signature())
148 os <<
"(" << dims_sig <<
") ";
150 os <<
"B(" << tensor->buffer() <<
") ";
151 if (tensor->is_variable())
157 if (
auto q_params = tensor->quantization())
159 if ((q_params->min() && q_params->max()) || (q_params->scale() && q_params->zero_point()))
161 std::string strquantiz =
" Quantization: ";
162 std::string strqindent(strquantiz.size(),
' ');
167 os <<
"min(" << q_params->min() <<
") ";
168 if (q_params->min()->size() > 1)
169 os << std::endl << strqindent;
173 os <<
"max(" << q_params->max() <<
") ";
174 if (q_params->max()->size() > 1)
175 os << std::endl << strqindent;
177 if (q_params->scale())
179 os <<
"scale(" << q_params->scale() <<
") ";
180 if (q_params->scale()->size() > 1)
181 os << std::endl << strqindent;
183 if (q_params->zero_point())
185 os <<
"zeropt(" << q_params->zero_point() <<
") ";
186 if (q_params->zero_point()->size() > 1)
187 os << std::endl << strqindent;
189 os <<
"quantized_dimension(" << q_params->quantized_dimension() <<
")";
194 if (q_params->details_type() == circle::QuantizationDetails_MXQuantization)
196 const auto &mx_params = q_params->details_as_MXQuantization();
197 std::string strquantiz =
" MX Quantization: ";
199 os <<
"axis (" << mx_params->axis() <<
")" << std::endl;
205 if (
const auto &s_params = tensor->sparsity())
207 std::string strsparsity =
" Sparsity: ";
208 std::string strsindent(strsparsity.size(),
' ');
211 if (s_params->traversal_order())
213 os <<
"traversal_order(" << s_params->traversal_order() <<
") ";
214 os << std::endl << strsindent;
216 if (s_params->block_map())
218 os <<
"block_map(" << s_params->block_map() <<
") ";
219 os << std::endl << strsindent;
221 if (
const auto &dim_metadata = s_params->dim_metadata())
224 for (
const auto &dm : *dim_metadata)
226 std::string strdm =
"dim_metadata[" + std::to_string(idx++) +
"]: ";
227 std::string strdm_indent = strsindent + std::string(strdm.size(),
' ');
230 os <<
"format(" << circle::EnumNameDimensionType(dm->format()) <<
") ";
231 os << std::endl << strdm_indent;
233 os <<
"dense_size(" << dm->dense_size() <<
") ";
234 os << std::endl << strdm_indent;
236 os <<
"array_segments_type("
237 << circle::EnumNameSparseIndexVector(dm->array_segments_type()) <<
") ";
238 os << std::endl << strdm_indent;
240 os <<
"array_segments(";
241 switch (dm->array_segments_type())
243 case circle::SparseIndexVector_NONE:
246 case circle::SparseIndexVector_Int32Vector:
247 os << dm->array_segments_as_Int32Vector()->values();
249 case circle::SparseIndexVector_Uint16Vector:
250 os << dm->array_segments_as_Uint16Vector()->values();
252 case circle::SparseIndexVector_Uint8Vector:
253 os << dm->array_segments_as_Uint8Vector()->values();
256 throw std::runtime_error(
"Invalid SparseIndexVector type of array_segments");
258 os <<
")" << std::endl << strdm_indent;
260 os <<
"array_indices_type(" << circle::EnumNameSparseIndexVector(dm->array_indices_type())
262 os << std::endl << strdm_indent;
264 os <<
"array_indices(";
265 switch (dm->array_indices_type())
267 case circle::SparseIndexVector_NONE:
270 case circle::SparseIndexVector_Int32Vector:
271 os << dm->array_indices_as_Int32Vector()->values();
273 case circle::SparseIndexVector_Uint16Vector:
274 os << dm->array_indices_as_Uint16Vector()->values();
276 case circle::SparseIndexVector_Uint8Vector:
277 os << dm->array_indices_as_Uint8Vector()->values();
280 throw std::runtime_error(
"Invalid SparseIndexVector type of array_indices");
282 os <<
")" << std::endl << strsindent;
290 os <<
"Operators: O(subgraph index : operator index) OpCodeName " << std::endl;
291 os <<
" Option(values) ... <-- depending on OpCode" << std::endl;
292 os <<
" I T(tensor index) OperandName <-- as input" << std::endl;
293 os <<
" O T(tensor index) OperandName <-- as output" << std::endl;
294 for (uint32_t i = 0; i < operators->size(); ++i)
296 const auto op = operators->Get(i);
297 circle::BuiltinOperator builtincode = reader.
builtin_code(op);
303 os <<
"O(" << reader.
subgraph_index() <<
":" << i <<
") " << op_name <<
" ";
308 op_prn->options(op, os);
311 for (
auto input : inputs)
316 auto tensor = tensors->Get(input);
321 for (
auto output : outputs)
323 os <<
" O T(" << reader.
subgraph_index() <<
":" << output <<
") ";
326 auto tensor = tensors->Get(output);
335 os <<
"Inputs/Outputs: I(input)/O(output) T(tensor index) OperandName" << std::endl;
337 for (
const auto input : reader.
inputs())
339 auto tensor = tensors->Get(input);
341 os <<
"I T(" << reader.
subgraph_index() <<
":" << input <<
") " << name << std::endl;
344 for (
const auto output : reader.
outputs())
346 auto tensor = tensors->Get(output);
348 os <<
"O T(" << reader.
subgraph_index() <<
":" << output <<
") " << name << std::endl;
354void dump_model(std::ostream &os,
const circle::Model *model,
const std::vector<char> *rawdata)
361 os <<
"===================================================================" << std::endl;
362 os <<
"Model version: " << reader.
version() << std::endl;
363 os <<
" # sub graphs: " << num_subgraph << std::endl;
366 auto opcodes = reader.
opcodes();
367 auto buffers = reader.
buffers();
372 os <<
"Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl;
373 int32_t opcode_index = 0;
374 for (
auto opcode : opcodes)
376 circle::BuiltinOperator op_code = opcode->builtin_code();
378 int32_t dp_code =
static_cast<int32_t
>(opcode->deprecated_builtin_code());
381 auto op_version = opcode->version();
383 os <<
"[" << opcode_index <<
"] " << op_name <<
" (code: " << op_code
384 <<
", dep_code: " << dp_code <<
", version: " << op_version <<
")" << std::endl;
391 os <<
"Buffers: B(index) (length) values, if any; (length *) for ext_offset" << std::endl;
392 for (uint32_t i = 0; i < buffers->size(); ++i)
394 bool ext_offset =
false;
395 const uint8_t *buff_data;
398 os <<
"B(" << i <<
") (" <<
size;
402 if (buff_data !=
nullptr)
411 if (metadata !=
nullptr)
413 os <<
"metadata : B(index) name" << std::endl;
414 for (uint32_t i = 0; i < metadata->size(); ++i)
416 const auto buff_id = metadata->Get(i)->buffer();
417 const auto metadata_name = metadata->Get(i)->name()->str();
418 os <<
"B(" << buff_id <<
") " << metadata_name << std::endl;
420 const uint8_t *buff_data;
424 meta_prn->print(buff_data, os);
431 if (signaturedefs !=
nullptr)
433 os <<
"SignatureDef" << std::endl;
434 for (uint32_t i = 0; i < signaturedefs->size(); ++i)
436 auto sign_i = signaturedefs->Get(i);
437 os <<
"S(" << i <<
") signature_key(" << sign_i->signature_key()->c_str() <<
"), sub_graph("
438 << sign_i->subgraph_index() <<
")" << std::endl;
440 auto inputs_i = sign_i->inputs();
441 for (uint32_t t = 0; t < inputs_i->size(); ++t)
443 auto inputs_i_t = inputs_i->Get(t);
444 os <<
" I(" << t <<
")"
445 <<
" T(" << sign_i->subgraph_index() <<
":" << inputs_i_t->tensor_index() <<
") "
446 << inputs_i_t->name()->c_str() << std::endl;
449 auto outputs_i = sign_i->outputs();
450 for (uint32_t t = 0; t < outputs_i->size(); ++t)
452 auto outputs_i_t = outputs_i->Get(t);
453 os <<
" O(" << t <<
")"
454 <<
" T(" << sign_i->subgraph_index() <<
":" << outputs_i_t->tensor_index() <<
") "
455 << outputs_i_t->name()->c_str() << std::endl;
461 for (uint32_t sg = 0; sg < num_subgraph; ++sg)
465 os <<
"-------------------------------------------------------------------" << std::endl;
466 os <<
"Sub-Graph: #" << sg <<
" " << reader.
subgraph_name() << std::endl;
472 os <<
"===================================================================" << std::endl;