ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Read.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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 __TFLREAD_READ_H__
18#define __TFLREAD_READ_H__
19
20#include <mio/tflite/schema_generated.h>
21
22#include <map>
23#include <string>
24#include <vector>
25
26namespace tflread
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:
51
52public:
53 Reader(const tflite::Model *model);
54 Reader(const tflite::Model *model, const std::vector<char> *rawdata);
55
56 Reader() = delete;
57
58public:
59 uint32_t version() const { return _version; }
60
61 const std::vector<const tflite::OperatorCode *> &opcodes() { return _op_codes; }
62 const TFliteBuffers_t *buffers() { return _buffers; }
63 const TFliteTensors_t *tensors() { return _tensors; }
64 const TFliteOperators_t *operators() { return _operators; }
65 const std::vector<int32_t> &inputs() const { return _inputs; }
66 const std::vector<int32_t> &outputs() const { return _outputs; }
67 const TFliteMetadata_t *metadata() const { return _metadata; }
68 const TFliteSignatureDef_t *signaturedefs() const { return _signaturedefs; }
69
70 uint32_t num_subgraph() const { return _subgraphs->size(); }
71
72 size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data);
73 size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data, bool &ext_offset);
74 tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const;
75 std::string opcode_name(const tflite::Operator *op) const;
76
77public:
78 bool select_subgraph(uint32_t subgraph);
79 const std::string &subgraph_name(void) const { return _subgraph_name; }
80 uint32_t subgraph_index(void) const { return _subgraph_index; }
81
82private:
83 uint32_t _version;
84
85 const std::vector<char> *_rawdata{nullptr};
86
87 const TFliteSubGraphs_t *_subgraphs{nullptr};
88 const TFliteBuffers_t *_buffers{nullptr};
89 const TFliteTensors_t *_tensors{nullptr};
90 const TFliteOperators_t *_operators{nullptr};
91 const TFliteMetadata_t *_metadata{nullptr};
92 const TFliteSignatureDef_t *_signaturedefs{nullptr};
93
94 uint32_t _subgraph_index;
95 std::string _subgraph_name;
96 std::vector<const tflite::OperatorCode *> _op_codes;
97 std::vector<int32_t> _inputs;
98 std::vector<int32_t> _outputs;
99};
100
101} // namespace tflread
102
103#endif // __TFLREAD_READ_H__
return_type Get(uoffset_t i) const
uoffset_t size() const
Loads TF lite file and provides helpers to access attributes.
Definition Read.h:43
uint32_t num_subgraph() const
Definition Read.h:70
const TFliteOperators_t * operators()
Definition Read.h:64
const std::vector< const tflite::OperatorCode * > & opcodes()
Definition Read.h:61
tflite::BuiltinOperator builtin_code(const tflite::Operator *op) const
Definition Read.cpp:123
const std::vector< int32_t > & inputs() const
Definition Read.h:65
size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data)
Definition Read.cpp:60
const TFliteBuffers_t * buffers()
Definition Read.h:62
uint32_t subgraph_index(void) const
Definition Read.h:80
const std::vector< int32_t > & outputs() const
Definition Read.h:66
bool select_subgraph(uint32_t subgraph)
Definition Read.cpp:148
const TFliteSignatureDef_t * signaturedefs() const
Definition Read.h:68
uint32_t version() const
Definition Read.h:59
const TFliteTensors_t * tensors()
Definition Read.h:63
const std::string & subgraph_name(void) const
Definition Read.h:79
std::string opcode_name(const tflite::Operator *op) const
Definition Read.cpp:132
const TFliteMetadata_t * metadata() const
Definition Read.h:67
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Read.h:29