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() <<
")";
195 if (
const auto &s_params = tensor->sparsity())
197 std::string strsparsity =
" Sparsity: ";
198 std::string strsindent(strsparsity.size(),
' ');
201 if (s_params->traversal_order())
203 os <<
"traversal_order(" << s_params->traversal_order() <<
") ";
204 os << std::endl << strsindent;
206 if (s_params->block_map())
208 os <<
"block_map(" << s_params->block_map() <<
") ";
209 os << std::endl << strsindent;
211 if (
const auto &dim_metadata = s_params->dim_metadata())
214 for (
const auto &dm : *dim_metadata)
216 std::string strdm =
"dim_metadata[" + std::to_string(idx++) +
"]: ";
217 std::string strdm_indent = strsindent + std::string(strdm.size(),
' ');
220 os <<
"format(" << circle::EnumNameDimensionType(dm->format()) <<
") ";
221 os << std::endl << strdm_indent;
223 os <<
"dense_size(" << dm->dense_size() <<
") ";
224 os << std::endl << strdm_indent;
226 os <<
"array_segments_type("
227 << circle::EnumNameSparseIndexVector(dm->array_segments_type()) <<
") ";
228 os << std::endl << strdm_indent;
230 os <<
"array_segments(";
231 switch (dm->array_segments_type())
233 case circle::SparseIndexVector_NONE:
236 case circle::SparseIndexVector_Int32Vector:
237 os << dm->array_segments_as_Int32Vector()->values();
239 case circle::SparseIndexVector_Uint16Vector:
240 os << dm->array_segments_as_Uint16Vector()->values();
242 case circle::SparseIndexVector_Uint8Vector:
243 os << dm->array_segments_as_Uint8Vector()->values();
246 throw std::runtime_error(
"Invalid SparseIndexVector type of array_segments");
248 os <<
")" << std::endl << strdm_indent;
250 os <<
"array_indices_type(" << circle::EnumNameSparseIndexVector(dm->array_indices_type())
252 os << std::endl << strdm_indent;
254 os <<
"array_indices(";
255 switch (dm->array_indices_type())
257 case circle::SparseIndexVector_NONE:
260 case circle::SparseIndexVector_Int32Vector:
261 os << dm->array_indices_as_Int32Vector()->values();
263 case circle::SparseIndexVector_Uint16Vector:
264 os << dm->array_indices_as_Uint16Vector()->values();
266 case circle::SparseIndexVector_Uint8Vector:
267 os << dm->array_indices_as_Uint8Vector()->values();
270 throw std::runtime_error(
"Invalid SparseIndexVector type of array_indices");
272 os <<
")" << std::endl << strsindent;
280 os <<
"Operators: O(subgraph index : operator index) OpCodeName " << std::endl;
281 os <<
" Option(values) ... <-- depending on OpCode" << std::endl;
282 os <<
" I T(tensor index) OperandName <-- as input" << std::endl;
283 os <<
" O T(tensor index) OperandName <-- as output" << std::endl;
284 for (uint32_t i = 0; i < operators->size(); ++i)
286 const auto op = operators->Get(i);
287 circle::BuiltinOperator builtincode = reader.
builtin_code(op);
293 os <<
"O(" << reader.
subgraph_index() <<
":" << i <<
") " << op_name <<
" ";
298 op_prn->options(op, os);
301 for (
auto input : inputs)
306 auto tensor = tensors->Get(input);
311 for (
auto output : outputs)
313 os <<
" O T(" << reader.
subgraph_index() <<
":" << output <<
") ";
316 auto tensor = tensors->Get(output);
325 os <<
"Inputs/Outputs: I(input)/O(output) T(tensor index) OperandName" << std::endl;
327 for (
const auto input : reader.
inputs())
329 auto tensor = tensors->Get(input);
331 os <<
"I T(" << reader.
subgraph_index() <<
":" << input <<
") " << name << std::endl;
334 for (
const auto output : reader.
outputs())
336 auto tensor = tensors->Get(output);
338 os <<
"O T(" << reader.
subgraph_index() <<
":" << output <<
") " << name << std::endl;
344void dump_model(std::ostream &os,
const circle::Model *model,
const std::vector<char> *rawdata)
351 os <<
"===================================================================" << std::endl;
352 os <<
"Model version: " << reader.
version() << std::endl;
353 os <<
" # sub graphs: " << num_subgraph << std::endl;
356 auto opcodes = reader.
opcodes();
357 auto buffers = reader.
buffers();
362 os <<
"Operator Codes: [order] OpCodeName (OpCode Enum)" << std::endl;
363 int32_t opcode_index = 0;
364 for (
auto opcode : opcodes)
366 circle::BuiltinOperator op_code = opcode->builtin_code();
368 int32_t dp_code =
static_cast<int32_t
>(opcode->deprecated_builtin_code());
371 auto op_version = opcode->version();
373 os <<
"[" << opcode_index <<
"] " << op_name <<
" (code: " << op_code
374 <<
", dep_code: " << dp_code <<
", version: " << op_version <<
")" << std::endl;
381 os <<
"Buffers: B(index) (length) values, if any; (length *) for ext_offset" << std::endl;
382 for (uint32_t i = 0; i < buffers->size(); ++i)
384 bool ext_offset =
false;
385 const uint8_t *buff_data;
388 os <<
"B(" << i <<
") (" <<
size;
392 if (buff_data !=
nullptr)
401 if (metadata !=
nullptr)
403 os <<
"metadata : B(index) name" << std::endl;
404 for (uint32_t i = 0; i < metadata->size(); ++i)
406 const auto buff_id = metadata->Get(i)->buffer();
407 const auto metadata_name = metadata->Get(i)->name()->str();
408 os <<
"B(" << buff_id <<
") " << metadata_name << std::endl;
410 const uint8_t *buff_data;
414 meta_prn->print(buff_data, os);
421 if (signaturedefs !=
nullptr)
423 os <<
"SignatureDef" << std::endl;
424 for (uint32_t i = 0; i < signaturedefs->size(); ++i)
426 auto sign_i = signaturedefs->Get(i);
427 os <<
"S(" << i <<
") signature_key(" << sign_i->signature_key()->c_str() <<
"), sub_graph("
428 << sign_i->subgraph_index() <<
")" << std::endl;
430 auto inputs_i = sign_i->inputs();
431 for (uint32_t t = 0; t < inputs_i->size(); ++t)
433 auto inputs_i_t = inputs_i->Get(t);
434 os <<
" I(" << t <<
")"
435 <<
" T(" << sign_i->subgraph_index() <<
":" << inputs_i_t->tensor_index() <<
") "
436 << inputs_i_t->name()->c_str() << std::endl;
439 auto outputs_i = sign_i->outputs();
440 for (uint32_t t = 0; t < outputs_i->size(); ++t)
442 auto outputs_i_t = outputs_i->Get(t);
443 os <<
" O(" << t <<
")"
444 <<
" T(" << sign_i->subgraph_index() <<
":" << outputs_i_t->tensor_index() <<
") "
445 << outputs_i_t->name()->c_str() << std::endl;
451 for (uint32_t sg = 0; sg < num_subgraph; ++sg)
455 os <<
"-------------------------------------------------------------------" << std::endl;
456 os <<
"Sub-Graph: #" << sg <<
" " << reader.
subgraph_name() << std::endl;
462 os <<
"===================================================================" << std::endl;