19#include <mio_circle/Helper.h>
20#include <mio_circle/Reader.h>
27void DumpOperators::run(std::ostream &os,
const circle::Model *model,
const std::vector<char> *data)
33 for (uint32_t g = 0; g < subgraph_size; g++)
39 for (uint32_t i = 0; i <
ops->size(); ++i)
41 const auto op =
ops->Get(i);
45 os << op_name << std::endl;
55const circle::Operator *operator_match_output(
mio::circle::Reader &reader,
const int32_t tensor)
59 for (uint32_t i = 0; i <
ops->size(); ++i)
61 const auto op =
ops->Get(i);
65 for (
auto output : outputs)
76 auto tensors = reader.
tensors();
78 if (tensor_id < 0 || tensor_id >= tensors->size())
80 throw std::runtime_error(
"Invalid Tensor ID");
83 auto tensor = tensors->Get(tensor_id);
84 auto buffer_id =
tensor->buffer();
85 bool ext_offset =
false;
98 const std::vector<char> *data)
104 for (uint32_t g = 0; g < subgraph_size; g++)
110 for (uint32_t i = 0; i <
ops->size(); ++i)
112 const auto op =
ops->Get(i);
115 if (bc == circle::BuiltinOperator_CONV_2D || bc == circle::BuiltinOperator_DEPTHWISE_CONV_2D)
118 if (inputs.size() < 2)
120 throw std::runtime_error(
"Operator has invalid input");
122 auto weight_input = inputs[1];
124 const auto op_weight = operator_match_output(reader, weight_input);
125 const auto buffer_size = tensor_buffer_size(reader, weight_input);
127 std::string weight_op_name =
"?";
129 if (op_weight ==
nullptr && buffer_size > 0)
131 weight_op_name =
"CONST";
133 else if (op_weight !=
nullptr)
139 os << op_name <<
"," << weight_op_name << std::endl;
151 const std::vector<char> *data)
153 std::map<std::string, int32_t> op_version_map;
164 for (uint32_t i = 0; i <
ops->size(); ++i)
166 const auto op =
ops->Get(i);
169 auto op_version = reader.
opcodes().at(op->opcode_index())->version();
171 if (op_version_map.find(op_name) == op_version_map.end() ||
172 op_version_map[op_name] < op_version)
173 op_version_map[op_name] = op_version;
176 for (
auto op : op_version_map)
178 os << op.first <<
"," << op.second << std::endl;
188 const std::vector<char> *data)
194 for (uint32_t g = 0; g < subgraph_size; g++)
197 auto tensors = reader.
tensors();
199 for (uint32_t i = 0; i < tensors->size(); ++i)
201 const auto tensor = tensors->Get(i);
219 for (uint32_t g = 0; g < subgraph_size; g++)
222 auto tensors = reader.
tensors();
224 for (uint32_t i = 0; i < tensors->size(); ++i)
226 const auto tensor = tensors->Get(i);
227 if (tensor->is_variable())
230 auto const buffer_id = tensor->buffer();
231 bool ext_offset =
false;
233 auto const buffer_size = reader.
buffer_info(buffer_id,
nullptr, ext_offset);
234 if (buffer_size == 0)
248 const std::vector<char> *data)
254 for (uint32_t g = 0; g < subgraph_size; g++)
257 auto tensors = reader.
tensors();
259 for (uint32_t i = 0; i < tensors->size(); ++i)
261 const auto tensor = tensors->Get(i);
262 auto shape = tensor->shape_signature() ? tensor->shape_signature() : tensor->shape();
264 for (uint32_t i = 0; i < shape->size(); i++)
267 if (i != shape->size() - 1)
272 os <<
"]" << std::endl;
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
void run(std::ostream &os, const circle::Model *model, const std::vector< char > *data)
Loads Circle file and provides helpers to access attributes.
const std::vector< const ::circle::OperatorCode * > & opcodes()
const CircleTensors_t * tensors()
std::string opcode_name(const ::circle::Operator *op) const
uint32_t num_subgraph() const
const CircleOperators_t * operators()
std::string tensor_name(const ::circle::Tensor *tensor) const
size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data)
std::string tensor_dtype(const ::circle::Tensor *tensor) const
::circle::BuiltinOperator builtin_code(const ::circle::Operator *op) const
bool select_subgraph(uint32_t subgraph)
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)