ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Reader.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __READER_H__
18#define __READER_H__
19
20#include <mio/tflite/schema_generated.h>
21
22#include <map>
23#include <string>
24#include <vector>
25
26namespace tflinspect
27{
28
29template <typename T> std::vector<T> as_index_vector(const flatbuffers::Vector<T> *flat_array)
30{
31 std::vector<T> ret(flat_array->size());
32 for (uint32_t i = 0; i < flat_array->size(); i++)
33 {
34 ret[i] = flat_array->Get(i);
35 }
36 return ret;
37}
38
42class Reader
43{
44private:
49
50public:
51 Reader(const tflite::Model *model);
52
53 Reader() = delete;
54
55public:
56 const std::vector<const tflite::OperatorCode *> &opcodes() { return _op_codes; }
57 const TFliteBuffers_t *buffers() { return _buffers; }
58 const TFliteTensors_t *tensors() { return _tensors; }
59 const TFliteOperators_t *operators() { return _operators; }
60 const std::vector<int32_t> &inputs() const { return _inputs; }
61 const std::vector<int32_t> &outputs() const { return _outputs; }
62
63 uint32_t num_subgraph() const { return _subgraphs->size(); }
64
65 size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data);
66 tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const;
67 std::string opcode_name(const tflite::Operator *op) const;
68
69public:
70 bool select_subgraph(uint32_t subgraph);
71
72private:
73 const TFliteSubGraphs_t *_subgraphs{nullptr};
74 const TFliteBuffers_t *_buffers{nullptr};
75 const TFliteTensors_t *_tensors{nullptr};
76 const TFliteOperators_t *_operators{nullptr};
77
78 std::vector<const tflite::OperatorCode *> _op_codes;
79 std::vector<int32_t> _inputs;
80 std::vector<int32_t> _outputs;
81};
82
83} // namespace tflinspect
84
85#endif // __READER_H__
return_type Get(uoffset_t i) const
uoffset_t size() const
Loads TF lite file and provides helpers to access attributes.
Definition Reader.h:43
bool select_subgraph(uint32_t subgraph)
Definition Reader.cpp:93
const TFliteBuffers_t * buffers()
Definition Reader.h:57
const TFliteOperators_t * operators()
Definition Reader.h:59
const std::vector< int32_t > & outputs() const
Definition Reader.h:61
tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const
Definition Reader.cpp:68
const TFliteTensors_t * tensors()
Definition Reader.h:58
uint32_t num_subgraph() const
Definition Reader.h:63
const std::vector< int32_t > & inputs() const
Definition Reader.h:60
size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data)
Definition Reader.cpp:40
const std::vector< const tflite::OperatorCode * > & opcodes()
Definition Reader.h:56
std::string opcode_name(const tflite::Operator *op) const
Definition Reader.cpp:77
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Reader.h:29