| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef TENSORFLOW_LITE_MICRO_MICRO_INTERPRETER_H_ |
| #define TENSORFLOW_LITE_MICRO_MICRO_INTERPRETER_H_ |
|
|
| #include <cstddef> |
| #include <cstdint> |
|
|
| #include "edge-impulse-sdk/third_party/flatbuffers/include/flatbuffers/flatbuffers.h" |
| #include "edge-impulse-sdk/tensorflow/lite/c/c_api_types.h" |
| #include "edge-impulse-sdk/tensorflow/lite/c/common.h" |
| #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" |
| #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/tensor_ctypes.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_allocator.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_context.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_graph.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_op_resolver.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_profiler_interface.h" |
| #include "edge-impulse-sdk/tensorflow/lite/portable_type_to_tflitetype.h" |
| #include "edge-impulse-sdk/tensorflow/lite/schema/schema_generated.h" |
| #include "edge-impulse-sdk/tensorflow/lite/schema/schema_generated_full.h" |
|
|
| |
| |
| #define TFLITE_SCHEMA_VERSION (3) |
|
|
| namespace tflite { |
|
|
| class MicroInterpreter { |
| public: |
| |
| |
| |
| |
| |
| |
| |
| |
| MicroInterpreter(const Model* model, const MicroOpResolver& op_resolver, |
| uint8_t* tensor_arena, size_t tensor_arena_size, |
| MicroResourceVariables* resource_variables = nullptr, |
| MicroProfilerInterface* profiler = nullptr); |
|
|
| |
| |
| |
| |
| |
| MicroInterpreter(const Model* model, const MicroOpResolver& op_resolver, |
| MicroAllocator* allocator, |
| MicroResourceVariables* resource_variables = nullptr, |
| MicroProfilerInterface* profiler = nullptr); |
|
|
| ~MicroInterpreter(); |
|
|
| |
| |
| TfLiteStatus AllocateTensors(bool run_all_prep_ops); |
|
|
| |
| |
| |
| TfLiteStatus Invoke(); |
|
|
| |
| |
| |
| |
| TfLiteStatus SetMicroExternalContext(void* external_context_payload); |
|
|
| size_t tensors_size(size_t subgraph_idx = 0) const { return model_->subgraphs()->Get(subgraph_idx)->tensors()->size(); } |
|
|
| TfLiteTensor* tensor(size_t tensor_index, size_t subgraph_idx = 0); |
|
|
| template <class T> |
| T* typed_tensor(int tensor_index) { |
| if (TfLiteTensor* tensor_ptr = tensor(tensor_index)) { |
| if (tensor_ptr->type == typeToTfLiteType<T>()) { |
| return GetTensorData<T>(tensor_ptr); |
| } |
| } |
| return nullptr; |
| } |
|
|
| TfLiteTensor* input(size_t index); |
| size_t inputs_size() const { |
| return model_->subgraphs()->Get(0)->inputs()->size(); |
| } |
| const flatbuffers::Vector<int32_t>& inputs() const { |
| return *model_->subgraphs()->Get(0)->inputs(); |
| } |
| TfLiteTensor* input_tensor(size_t index) { return input(index); } |
| template <class T> |
| T* typed_input_tensor(int tensor_index) { |
| if (TfLiteTensor* tensor_ptr = input_tensor(tensor_index)) { |
| if (tensor_ptr->type == typeToTfLiteType<T>()) { |
| return GetTensorData<T>(tensor_ptr); |
| } |
| } |
| return nullptr; |
| } |
|
|
| TfLiteTensor* output(size_t index); |
| size_t outputs_size() const { |
| return model_->subgraphs()->Get(0)->outputs()->size(); |
| } |
| const flatbuffers::Vector<int32_t>& outputs() const { |
| return *model_->subgraphs()->Get(0)->outputs(); |
| } |
| TfLiteTensor* output_tensor(size_t index) { return output(index); } |
| template <class T> |
| T* typed_output_tensor(int tensor_index) { |
| if (TfLiteTensor* tensor_ptr = output_tensor(tensor_index)) { |
| if (tensor_ptr->type == typeToTfLiteType<T>()) { |
| return GetTensorData<T>(tensor_ptr); |
| } |
| } |
| return nullptr; |
| } |
|
|
| |
| |
| TfLiteStatus Reset(); |
|
|
| TfLiteStatus initialization_status() const { return initialization_status_; } |
|
|
| #ifdef EON_COMPILER_RUN |
| NodeAndRegistration* node_and_registrations_ = nullptr; |
|
|
| size_t operators_size(uint32_t subgraph_idx = 0) const |
| { |
| return model_->subgraphs()->Get(subgraph_idx)->operators()->size(); |
| } |
|
|
| const NodeAndRegistration node_and_registration(int node_index, int sg) |
| { |
| return graph_.GetAllocations()[sg].node_and_registrations[node_index]; |
| } |
| #endif |
|
|
| |
| |
| |
| |
| TfLiteStatus PrepareNodeAndRegistrationDataFromFlatbuffer(); |
|
|
| |
| |
| |
| |
| |
| |
| size_t arena_used_bytes() const { return allocator_.used_bytes(); } |
|
|
| protected: |
| const MicroAllocator& allocator() const { return allocator_; } |
| const TfLiteContext& context() const { return context_; } |
|
|
| private: |
| |
| |
| void Init(MicroProfilerInterface* profiler); |
|
|
| |
| int get_subgraph_index() { return graph_.GetCurrentSubgraphIndex(); } |
|
|
| const Model* model_; |
| const MicroOpResolver& op_resolver_; |
| TfLiteContext context_ = {}; |
| MicroAllocator& allocator_; |
| MicroGraph graph_; |
| bool tensors_allocated_; |
|
|
| TfLiteStatus initialization_status_; |
|
|
| ScratchBufferHandle* scratch_buffer_handles_ = nullptr; |
|
|
| |
| |
| TfLiteTensor** input_tensors_; |
| TfLiteTensor** output_tensors_; |
|
|
| MicroContext micro_context_; |
| }; |
|
|
| } |
|
|
| #endif |
|
|