| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "edge-impulse-sdk/tensorflow/lite/micro/flatbuffer_utils.h" |
| #include "edge-impulse-sdk/tensorflow/lite/schema/schema_generated_full.h" |
|
|
| namespace tflite { |
|
|
| FlexbufferWrapper::FlexbufferWrapper(const uint8_t* buffer, size_t size) |
| : flexbuffers::Vector(flexbuffers::GetRoot(buffer, size).AsVector()) {} |
|
|
| int64_t FlexbufferWrapper::ElementAsInt64(size_t i) const { |
| const uint8_t* elem = data_ + i * byte_width_; |
| return ::flexbuffers::ReadInt64(elem, byte_width_); |
| } |
|
|
| uint64_t FlexbufferWrapper::ElementAsUInt64(size_t i) const { |
| const uint8_t* elem = data_ + i * byte_width_; |
| return ::flexbuffers::ReadUInt64(elem, byte_width_); |
| } |
|
|
| int32_t FlexbufferWrapper::ElementAsInt32(size_t i) const { |
| return static_cast<int32_t>(ElementAsInt64(i)); |
| } |
|
|
| bool FlexbufferWrapper::ElementAsBool(size_t i) const { |
| return static_cast<bool>(ElementAsUInt64(i)); |
| } |
|
|
| double FlexbufferWrapper::ElementAsDouble(size_t i) const { |
| const uint8_t* elem = data_ + i * byte_width_; |
| return ::flexbuffers::ReadDouble(elem, byte_width_); |
| } |
|
|
| float FlexbufferWrapper::ElementAsFloat(size_t i) const { |
| return static_cast<float>(FlexbufferWrapper::ElementAsDouble(i)); |
| } |
|
|
| |
| uint32_t NumSubgraphOperators(const SubGraph* subgraph) { |
| if (subgraph->operators() != nullptr) { |
| return subgraph->operators()->size(); |
| } else { |
| return 0; |
| } |
| } |
| |
| uint32_t NumSubgraphOperators(const Model* model, int subgraph_idx) { |
| const SubGraph* subgraph = model->subgraphs()->Get(subgraph_idx); |
| return NumSubgraphOperators(subgraph); |
| } |
|
|
| TfLiteIntArray* FlatBufferVectorToTfLiteTypeArray( |
| const flatbuffers::Vector<int32_t>* flatbuffer_array) { |
| |
| |
| |
| |
| return const_cast<TfLiteIntArray*>( |
| reinterpret_cast<const TfLiteIntArray*>(flatbuffer_array)); |
| } |
|
|
| TfLiteFloatArray* FlatBufferVectorToTfLiteTypeArray( |
| const flatbuffers::Vector<float>* flatbuffer_array) { |
| |
| |
| |
| |
| return const_cast<TfLiteFloatArray*>( |
| reinterpret_cast<const TfLiteFloatArray*>(flatbuffer_array)); |
| } |
|
|
| } |
|
|