ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.cpp
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#include "Convert.h"
18
19namespace tflchef
20{
21
22tflchef::TensorType as_tflchef_type(const tflite::TensorType type)
23{
24 switch (type)
25 {
26 case tflite::TensorType_FLOAT32:
27 return tflchef::FLOAT32;
28 case tflite::TensorType_INT32:
29 return tflchef::INT32;
30 case tflite::TensorType_INT64:
31 return tflchef::INT64;
32 case tflite::TensorType_UINT8:
33 return tflchef::UINT8;
34 case tflite::TensorType_BOOL:
35 return tflchef::BOOL;
36 case tflite::TensorType_INT8:
37 return tflchef::INT8;
38 case tflite::TensorType_INT16:
39 return tflchef::INT16;
40 case tflite::TensorType_FLOAT16:
41 return tflchef::FLOAT16;
42 // TODO handle other types
43 // TensorType_STRING
44 // TensorType_COMPLEX64
45 default:
46 throw std::runtime_error{"unsupported tensor type"};
47 }
48}
49
50tflchef::Activation as_tflchef_activation(const tflite::ActivationFunctionType type)
51{
52 switch (type)
53 {
54 case tflite::ActivationFunctionType_NONE:
55 return tflchef::NONE;
56 case tflite::ActivationFunctionType_RELU:
57 return tflchef::RELU;
58 case tflite::ActivationFunctionType_RELU_N1_TO_1:
59 return tflchef::RELU_N1_TO_1;
60 case tflite::ActivationFunctionType_RELU6:
61 return tflchef::RELU6;
62 case tflite::ActivationFunctionType_TANH:
63 return tflchef::TANH;
64 case tflite::ActivationFunctionType_SIGN_BIT:
65 return tflchef::SIGN_BIT;
66 default:
67 throw std::runtime_error{"unsupported activation type"};
68 }
69}
70
71tflchef::Padding as_tflchef_padding(const tflite::Padding padding)
72{
73 switch (padding)
74 {
75 case tflite::Padding_SAME:
76 return tflchef::SAME;
77 case tflite::Padding_VALID:
78 return tflchef::VALID;
79 default:
80 throw std::runtime_error{"unsupported padding"};
81 }
82}
83
84tflchef::MirrorPadMode as_tflchef_mirrorpadmode(const tflite::MirrorPadMode mode)
85{
86 switch (mode)
87 {
88 case tflite::MirrorPadMode_REFLECT:
89 return tflchef::REFLECT;
90 case tflite::MirrorPadMode_SYMMETRIC:
91 return tflchef::SYMMETRIC;
92 default:
93 throw std::runtime_error{"Unknown mirrorpad mode"};
94 }
95}
96
97tflchef::DimensionType as_tflchef_sparse_dim_type(const tflite::DimensionType type)
98{
99 switch (type)
100 {
101 case tflite::DimensionType_DENSE:
102 return tflchef::DimensionType::DENSE;
103 case tflite::DimensionType_SPARSE_CSR:
104 return tflchef::DimensionType::SPARSE_CSR;
105 default:
106 throw std::runtime_error("unsupported sparse dimension type");
107 }
108}
109
110tflchef::SparseIndexVecType as_tflchef_sparse_idx_vec_type(const tflite::SparseIndexVector type)
111{
112 switch (type)
113 {
114 case tflite::SparseIndexVector_NONE:
115 return tflchef::SparseIndexVecType::SparseIdxVecType_NONE;
116 case tflite::SparseIndexVector_Int32Vector:
117 return tflchef::SparseIndexVecType::INT32VEC;
118 case tflite::SparseIndexVector_Uint16Vector:
119 return tflchef::SparseIndexVecType::UINT16VEC;
120 case tflite::SparseIndexVector_Uint8Vector:
121 return tflchef::SparseIndexVecType::UINT8VEC;
122 default:
123 throw std::runtime_error("unsupported sparse index vector type");
124 }
125}
126
127} // namespace tflchef
tflchef::MirrorPadMode as_tflchef_mirrorpadmode(const tflite::MirrorPadMode mode)
Definition Convert.cpp:84
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
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