ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.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 __CONVERT_H__
18#define __CONVERT_H__
19
20#include <mio/tflite/schema_generated.h>
21
22#include <tflchef.pb.h>
23
24namespace tflchef
25{
26
27tflchef::TensorType as_tflchef_type(const tflite::TensorType type);
28tflchef::Activation as_tflchef_activation(const tflite::ActivationFunctionType type);
29tflchef::Padding as_tflchef_padding(const tflite::Padding padding);
30tflchef::MirrorPadMode as_tflchef_mirrorpadmode(const tflite::MirrorPadMode mode);
31tflchef::DimensionType as_tflchef_sparse_dim_type(const tflite::DimensionType type);
32tflchef::SparseIndexVecType as_tflchef_sparse_idx_vec_type(const tflite::SparseIndexVector type);
33
37template <typename DT> std::vector<DT> extract_buffer(const tflite::Buffer *buffer)
38{
39 assert(buffer->data() != nullptr);
40 auto buffer_length = buffer->data()->size();
41 auto num_elements = buffer_length / sizeof(DT);
42 std::vector<DT> result(num_elements);
43 std::memcpy(result.data(), buffer->data()->data(), buffer_length);
44 return result;
45}
46
47template <typename T> std::vector<T> as_index_vector(const flatbuffers::Vector<T> *flat_array)
48{
49 std::vector<T> ret(flat_array->size());
50 for (uint32_t i = 0; i < flat_array->size(); i++)
51 {
52 ret[i] = flat_array->Get(i);
53 }
54 return ret;
55}
56
57} // namespace tflchef
58
59#endif // __CONVERT_H__
return_type Get(uoffset_t i) const
uoffset_t size() const
tflchef::MirrorPadMode as_tflchef_mirrorpadmode(const tflite::MirrorPadMode mode)
Definition Convert.cpp:84
std::vector< DT > extract_buffer(const tflite::Buffer *buffer)
extract buffer data to std::vector<DT>
Definition Convert.h:37
tflchef::Padding as_tflchef_padding(const tflite::Padding padding)
Definition Convert.cpp:71
tflchef::DimensionType as_tflchef_sparse_dim_type(const tflite::DimensionType type)
Definition Convert.cpp:97
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Convert.h:47
tflchef::SparseIndexVecType as_tflchef_sparse_idx_vec_type(const tflite::SparseIndexVector type)
Definition Convert.cpp:110
tflchef::TensorType as_tflchef_type(const tflite::TensorType type)
Definition Convert.cpp:22
tflchef::Activation as_tflchef_activation(const tflite::ActivationFunctionType type)
Definition Convert.cpp:50