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 tflite::Operator *operator_match_output(
tflinspect::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();
102 for (uint32_t g = 0; g < subgraph_size; g++)
108 for (uint32_t i = 0; i <
ops->size(); ++i)
110 const auto op =
ops->Get(i);
113 if (bc == tflite::BuiltinOperator_CONV_2D || bc == tflite::BuiltinOperator_DEPTHWISE_CONV_2D)
116 if (inputs.size() < 2)
118 throw std::runtime_error(
"Operator has invalid input");
120 auto weight_input = inputs[1];
122 const auto op_weight = operator_match_output(reader, weight_input);
123 const auto buffer_size = tensor_buffer_size(reader, weight_input);
125 std::string weight_op_name =
"?";
127 if (op_weight ==
nullptr && buffer_size > 0)
129 weight_op_name =
"CONST";
131 else if (op_weight !=
nullptr)
137 os << op_name <<
"," << weight_op_name << std::endl;
150 std::map<std::string, int32_t> op_version_map;
156 for (uint32_t g = 0; g < subgraph_size; g++)
162 for (uint32_t i = 0; i <
ops->size(); ++i)
164 const auto op =
ops->Get(i);
167 auto op_version = reader.
opcodes().at(op->opcode_index())->version();
169 if (op_version_map.find(op_name) == op_version_map.end() ||
170 op_version_map[op_name] < op_version)
171 op_version_map[op_name] = op_version;
175 for (
auto op : op_version_map)
177 os << op.first <<
"," << op.second << std::endl;
void run(std::ostream &os, const tflite::Model *model)
void run(std::ostream &os, const tflite::Model *model)
void run(std::ostream &os, const tflite::Model *model)
Loads TF lite file and provides helpers to access attributes.
bool select_subgraph(uint32_t subgraph)
const TFliteOperators_t * operators()
tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const
const TFliteTensors_t * tensors()
uint32_t num_subgraph() const
size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data)
const std::vector< const tflite::OperatorCode * > & opcodes()
std::string opcode_name(const tflite::Operator *op) const
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
This file contains Reader class.