ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.h File Reference

This header declares various as_tflite_TYPE functions. More...

#include <tflchef.pb.h>
#include <mio/tflite/schema_generated.h>

Go to the source code of this file.

Data Structures

class  sparsity::FormatConverter< T >
 

Namespaces

namespace  sparsity
 

Enumerations

enum  sparsity::TfLiteDimensionType { sparsity::kTfLiteDimDense = 0 , sparsity::kTfLiteDimSparseCSR , sparsity::kTfLiteDimDense = 0 , sparsity::kTfLiteDimSparseCSR }
 

Functions

tflite::Padding as_tflite_padding (const tflchef::Padding &value)
 
tflite::ActivationFunctionType as_tflite_activation (const tflchef::Activation &value)
 
tflite::TensorType as_tflite_tensortype (const tflchef::TensorType &value)
 
tflite::MirrorPadMode as_tflite_mirrorpadmode (const tflchef::MirrorPadMode &value)
 
tflite::DimensionType as_tflite_dimensiontype (const tflchef::DimensionType &value)
 
tflite::SparseIndexVector as_tflite_sparse_idx_vec_type (const tflchef::SparseIndexVecType &value)
 
flatbuffers::Offset< void > as_tflite_sparse_index_vec (flatbuffers::FlatBufferBuilder &fb, const ::tflchef::TensorSparsity_IndexVec &value)
 

Detailed Description

This header declares various as_tflite_TYPE functions.

Definition in file Convert.h.

Function Documentation

◆ as_tflite_activation()

tflite::ActivationFunctionType as_tflite_activation ( const tflchef::Activation &  value)

Definition at line 37 of file Convert.cpp.

38{
39 switch (value)
40 {
41 case tflchef::NONE:
42 return tflite::ActivationFunctionType_NONE;
43 case tflchef::RELU:
44 return tflite::ActivationFunctionType_RELU;
45 case tflchef::RELU_N1_TO_1:
46 return tflite::ActivationFunctionType_RELU_N1_TO_1;
47 case tflchef::RELU6:
48 return tflite::ActivationFunctionType_RELU6;
49 case tflchef::TANH:
50 return tflite::ActivationFunctionType_TANH;
51 case tflchef::SIGN_BIT:
52 return tflite::ActivationFunctionType_SIGN_BIT;
53 default:
54 break;
55 }
56
57 throw std::runtime_error{"Unknown activation"};
58}

Referenced by AddChef::value(), AveragePool2DChef::value(), BidirectionalSequenceLSTMChef::value(), ConcatenationChef::value(), Conv2DChef::value(), DepthwiseConv2DChef::value(), DivChef::value(), L2Normalize::value(), L2Pool2DChef::value(), MaxPool2DChef::value(), MulChef::value(), SubChef::value(), SVDFChef::value(), TransposeConvChef::value(), and UnidirectionalSequenceLSTMChef::value().

◆ as_tflite_dimensiontype()

tflite::DimensionType as_tflite_dimensiontype ( const tflchef::DimensionType &  value)

Definition at line 106 of file Convert.cpp.

107{
108 switch (value)
109 {
110 case tflchef::DimensionType::DENSE:
111 return tflite::DimensionType_DENSE;
112 case tflchef::DimensionType::SPARSE_CSR:
113 return tflite::DimensionType_SPARSE_CSR;
114 default:
115 break;
116 }
117
118 throw std::runtime_error("Unknown dimension type");
119}

◆ as_tflite_mirrorpadmode()

tflite::MirrorPadMode as_tflite_mirrorpadmode ( const tflchef::MirrorPadMode &  value)

Definition at line 91 of file Convert.cpp.

92{
93 switch (value)
94 {
95 case tflchef::REFLECT:
96 return tflite::MirrorPadMode_REFLECT;
97 case tflchef::SYMMETRIC:
98 return tflite::MirrorPadMode_SYMMETRIC;
99 default:
100 break;
101 }
102
103 throw std::runtime_error{"Unknown mirrorpad mode"};
104}

Referenced by MirrorPadChef::value().

◆ as_tflite_padding()

tflite::Padding as_tflite_padding ( const tflchef::Padding &  value)

Definition at line 22 of file Convert.cpp.

23{
24 switch (value)
25 {
26 case tflchef::SAME:
27 return tflite::Padding_SAME;
28 case tflchef::VALID:
29 return tflite::Padding_VALID;
30 default:
31 break;
32 }
33
34 throw std::runtime_error{"Unknown padding value"};
35}

Referenced by AveragePool2DChef::value(), Conv2DChef::value(), DepthwiseConv2DChef::value(), L2Pool2DChef::value(), MaxPool2DChef::value(), and TransposeConvChef::value().

◆ as_tflite_sparse_idx_vec_type()

tflite::SparseIndexVector as_tflite_sparse_idx_vec_type ( const tflchef::SparseIndexVecType &  value)

Definition at line 121 of file Convert.cpp.

122{
123 switch (value)
124 {
125 case tflchef::SparseIndexVecType::SparseIdxVecType_NONE:
126 return tflite::SparseIndexVector_NONE;
127 case tflchef::SparseIndexVecType::INT32VEC:
128 return tflite::SparseIndexVector_Int32Vector;
129 case tflchef::SparseIndexVecType::UINT16VEC:
130 return tflite::SparseIndexVector_Uint16Vector;
131 case tflchef::SparseIndexVecType::UINT8VEC:
132 return tflite::SparseIndexVector_Uint8Vector;
133 default:
134 break;
135 }
136
137 throw std::runtime_error("Unknown SparseIndexVector type");
138}

◆ as_tflite_sparse_index_vec()

flatbuffers::Offset< void > as_tflite_sparse_index_vec ( flatbuffers::FlatBufferBuilder fb,
const ::tflchef::TensorSparsity_IndexVec &  value 
)

Definition at line 141 of file Convert.cpp.

143{
144 auto sparse_idx_type = value.type();
145
146 switch (sparse_idx_type)
147 {
148 case tflchef::SparseIndexVecType::SparseIdxVecType_NONE:
150 case tflchef::SparseIndexVecType::INT32VEC:
151 {
152 auto values_vec_int32 = std::vector<int32_t>{value.dim().begin(), value.dim().end()};
153 auto values_int32 = fb.CreateVector(values_vec_int32);
154 return tflite::CreateInt32Vector(fb, values_int32).Union();
155 }
156 case tflchef::SparseIndexVecType::UINT16VEC:
157 {
158 auto values_vec_uint16 = std::vector<uint16_t>{value.dim().begin(), value.dim().end()};
159 auto values_uint16 = fb.CreateVector(values_vec_uint16);
160 return tflite::CreateUint16Vector(fb, values_uint16).Union();
161 }
162 case tflchef::SparseIndexVecType::UINT8VEC:
163 {
164 auto values_vec_uint8 = std::vector<uint8_t>{value.dim().begin(), value.dim().end()};
165 auto values_uint8 = fb.CreateVector(values_vec_uint8);
166 return tflite::CreateUint8Vector(fb, values_uint8).Union();
167 }
168 default:
169 break;
170 }
171
172 throw std::runtime_error("Unknown SparseIndexVector type");
173}
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.

References flatbuffers::FlatBufferBuilder::CreateVector().

◆ as_tflite_tensortype()

tflite::TensorType as_tflite_tensortype ( const tflchef::TensorType &  value)

Definition at line 60 of file Convert.cpp.

61{
62 switch (value)
63 {
64 case tflchef::FLOAT32:
65 return tflite::TensorType_FLOAT32;
66 case tflchef::FLOAT16:
67 return tflite::TensorType_FLOAT16;
68 case tflchef::INT32:
69 return tflite::TensorType_INT32;
70 case tflchef::UINT8:
71 return tflite::TensorType_UINT8;
72 case tflchef::INT64:
73 return tflite::TensorType_INT64;
74 case tflchef::STRING:
75 return tflite::TensorType_STRING;
76 case tflchef::BOOL:
77 return tflite::TensorType_BOOL;
78 case tflchef::INT16:
79 return tflite::TensorType_INT16;
80 case tflchef::INT8:
81 return tflite::TensorType_INT8;
82 case tflchef::INT4:
83 return tflite::TensorType_INT4;
84 default:
85 break;
86 }
87
88 throw std::runtime_error{"Unknown tensor type"};
89}

Referenced by ArgMaxChef::value(), ArgMinChef::value(), CastChef::value(), ShapeChef::value(), and UniqueChef::value().