mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/tflite-micro: Update tflite-micro to latest version
This commit is contained in:
parent
410fd5afc8
commit
9c1e664e36
@ -1,7 +1,7 @@
|
|||||||
PKG_NAME=tflite-micro
|
PKG_NAME=tflite-micro
|
||||||
PKG_URL=https://github.com/tensorflow/tflite-micro
|
PKG_URL=https://github.com/tensorflow/tflite-micro
|
||||||
# sync from 2022.04.07
|
# sync from 2024.05.21
|
||||||
PKG_VERSION=1501b574b74fd7877aba30aa9d8b667f41b139c3
|
PKG_VERSION=8e22946b3faa51564df5dd9194f7540b2694892c
|
||||||
PKG_LICENSE=Apache 2.0
|
PKG_LICENSE=Apache 2.0
|
||||||
|
|
||||||
include $(RIOTBASE)/pkg/pkg.mk
|
include $(RIOTBASE)/pkg/pkg.mk
|
||||||
@ -14,23 +14,29 @@ CFLAGS += -Wno-unused-parameter
|
|||||||
TFLITE_MODULES := \
|
TFLITE_MODULES := \
|
||||||
tflite-c \
|
tflite-c \
|
||||||
tflite-core-api \
|
tflite-core-api \
|
||||||
|
tflite-core-c \
|
||||||
tflite-kernels \
|
tflite-kernels \
|
||||||
tflite-kernels-internal \
|
tflite-kernels-internal \
|
||||||
tflite-kernels-internal-reference \
|
tflite-kernels-internal-reference \
|
||||||
tflite-micro \
|
tflite-micro \
|
||||||
|
tflite-micro-arena_allocator \
|
||||||
tflite-micro-kernels \
|
tflite-micro-kernels \
|
||||||
tflite-micro-memory-planner \
|
tflite-micro-memory-planner \
|
||||||
|
tflite-micro-tflite_bridge \
|
||||||
tflite-schema \
|
tflite-schema \
|
||||||
#
|
#
|
||||||
|
|
||||||
DIR_tflite-c := tensorflow/lite/c
|
DIR_tflite-c := tensorflow/lite/c
|
||||||
DIR_tflite-core-api := tensorflow/lite/core/api
|
DIR_tflite-core-api := tensorflow/lite/core/api
|
||||||
|
DIR_tflite-core-c := tensorflow/lite/core/c
|
||||||
DIR_tflite-kernels := tensorflow/lite/kernels
|
DIR_tflite-kernels := tensorflow/lite/kernels
|
||||||
DIR_tflite-kernels-internal := tensorflow/lite/kernels/internal
|
DIR_tflite-kernels-internal := tensorflow/lite/kernels/internal
|
||||||
DIR_tflite-kernels-internal-reference := tensorflow/lite/kernels/internal/reference
|
DIR_tflite-kernels-internal-reference := tensorflow/lite/kernels/internal/reference
|
||||||
DIR_tflite-micro := tensorflow/lite/micro
|
DIR_tflite-micro := tensorflow/lite/micro
|
||||||
|
DIR_tflite-micro-arena_allocator := tensorflow/lite/micro/arena_allocator
|
||||||
DIR_tflite-micro-kernels := tensorflow/lite/micro/kernels
|
DIR_tflite-micro-kernels := tensorflow/lite/micro/kernels
|
||||||
DIR_tflite-micro-memory-planner := tensorflow/lite/micro/memory_planner
|
DIR_tflite-micro-memory-planner := tensorflow/lite/micro/memory_planner
|
||||||
|
DIR_tflite-micro-tflite_bridge := tensorflow/lite/micro/tflite_bridge
|
||||||
DIR_tflite-schema := tensorflow/lite/schema
|
DIR_tflite-schema := tensorflow/lite/schema
|
||||||
|
|
||||||
TFLITE_MODULES_USED := $(filter $(TFLITE_MODULES),$(USEMODULE))
|
TFLITE_MODULES_USED := $(filter $(TFLITE_MODULES),$(USEMODULE))
|
||||||
@ -40,5 +46,13 @@ all: $(TFLITE_MODULES_USED)
|
|||||||
|
|
||||||
.PHONY: tflite-%
|
.PHONY: tflite-%
|
||||||
|
|
||||||
tflite-%:
|
# .PHONY: $(PKG_SOURCE_DIR)/tensorflow/lite/schema/schema_generated.h
|
||||||
|
|
||||||
|
$(PKG_SOURCE_DIR)/tensorflow/lite/schema/schema_generated.h: $(PKG_SOURCE_DIR)/tensorflow/lite/schema/schema.fbs $(FLATC)
|
||||||
|
$(FLATC) --cpp -o "$(dir $@)" "$<"
|
||||||
|
|
||||||
|
tflite-%: $(PKG_SOURCE_DIR)/tensorflow/lite/schema/schema_generated.h
|
||||||
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/$(DIR_$@) -f $(CURDIR)/$@.mk
|
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/$(DIR_$@) -f $(CURDIR)/$@.mk
|
||||||
|
|
||||||
|
$(FLATC):
|
||||||
|
$(Q)make -C "$(dir $@)"
|
||||||
|
@ -6,12 +6,15 @@ USEPKG += ruy
|
|||||||
|
|
||||||
USEMODULE += tflite-c
|
USEMODULE += tflite-c
|
||||||
USEMODULE += tflite-core-api
|
USEMODULE += tflite-core-api
|
||||||
|
USEMODULE += tflite-core-c
|
||||||
USEMODULE += tflite-kernels
|
USEMODULE += tflite-kernels
|
||||||
USEMODULE += tflite-kernels-internal
|
USEMODULE += tflite-kernels-internal
|
||||||
USEMODULE += tflite-kernels-internal-reference
|
USEMODULE += tflite-kernels-internal-reference
|
||||||
USEMODULE += tflite-micro
|
USEMODULE += tflite-micro
|
||||||
|
USEMODULE += tflite-micro-arena_allocator
|
||||||
USEMODULE += tflite-micro-kernels
|
USEMODULE += tflite-micro-kernels
|
||||||
USEMODULE += tflite-micro-memory-planner
|
USEMODULE += tflite-micro-memory-planner
|
||||||
|
USEMODULE += tflite-micro-tflite_bridge
|
||||||
USEMODULE += tflite-schema
|
USEMODULE += tflite-schema
|
||||||
|
|
||||||
# This package doesn't work on riscv
|
# This package doesn't work on riscv
|
||||||
|
Binary file not shown.
BIN
pkg/tflite-micro/patches/0001-fix-private-descriptor.patch
Normal file
BIN
pkg/tflite-micro/patches/0001-fix-private-descriptor.patch
Normal file
Binary file not shown.
Binary file not shown.
5
pkg/tflite-micro/tflite-core-c.mk
Normal file
5
pkg/tflite-micro/tflite-core-c.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MODULE = tflite-core-c
|
||||||
|
|
||||||
|
SRCXXEXT = cc
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
6
pkg/tflite-micro/tflite-micro-arena_allocator.mk
Normal file
6
pkg/tflite-micro/tflite-micro-arena_allocator.mk
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
MODULE = tflite-micro-arena_allocator
|
||||||
|
|
||||||
|
SRCXXEXT = cc
|
||||||
|
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
5
pkg/tflite-micro/tflite-micro-tflite_bridge.mk
Normal file
5
pkg/tflite-micro/tflite-micro-tflite_bridge.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MODULE = tflite-micro-tflite_bridge
|
||||||
|
|
||||||
|
SRCXXEXT = cc
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
@ -17,17 +17,11 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "kernel_defines.h"
|
#include "kernel_defines.h"
|
||||||
#if IS_USED(MODULE_TENSORFLOW_LITE)
|
|
||||||
#include "tensorflow/lite/micro/kernels/all_ops_resolver.h"
|
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
|
||||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
|
||||||
#include "tensorflow/lite/micro/micro_interpreter.h"
|
|
||||||
#include "tensorflow/lite/version.h"
|
|
||||||
#else
|
|
||||||
#include "tensorflow/lite/micro/all_ops_resolver.h"
|
|
||||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
|
||||||
#include "tensorflow/lite/micro/micro_interpreter.h"
|
#include "tensorflow/lite/micro/micro_interpreter.h"
|
||||||
#include "tensorflow/lite/micro/system_setup.h"
|
#include "tensorflow/lite/micro/system_setup.h"
|
||||||
#endif
|
|
||||||
#include "tensorflow/lite/schema/schema_generated.h"
|
#include "tensorflow/lite/schema/schema_generated.h"
|
||||||
|
|
||||||
#include "blob/digit.h"
|
#include "blob/digit.h"
|
||||||
@ -37,7 +31,6 @@
|
|||||||
|
|
||||||
// Globals, used for compatibility with Arduino-style sketches.
|
// Globals, used for compatibility with Arduino-style sketches.
|
||||||
namespace {
|
namespace {
|
||||||
tflite::ErrorReporter* error_reporter = nullptr;
|
|
||||||
const tflite::Model* model = nullptr;
|
const tflite::Model* model = nullptr;
|
||||||
tflite::MicroInterpreter* interpreter = nullptr;
|
tflite::MicroInterpreter* interpreter = nullptr;
|
||||||
TfLiteTensor* input = nullptr;
|
TfLiteTensor* input = nullptr;
|
||||||
@ -52,15 +45,6 @@ namespace {
|
|||||||
// The name of this function is important for Arduino compatibility.
|
// The name of this function is important for Arduino compatibility.
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
#if IS_USED(MODULE_TFLITE_MICRO)
|
|
||||||
tflite::InitializeTarget();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set up logging. Google style is to avoid globals or statics because of
|
|
||||||
// lifetime uncertainty, but since this has a trivial destructor it's okay.
|
|
||||||
// NOLINTNEXTLINE(runtime-global-variables)
|
|
||||||
static tflite::MicroErrorReporter micro_error_reporter;
|
|
||||||
error_reporter = µ_error_reporter;
|
|
||||||
|
|
||||||
// Map the model into a usable data structure. This doesn't involve any
|
// Map the model into a usable data structure. This doesn't involve any
|
||||||
// copying or parsing, it's a very lightweight operation.
|
// copying or parsing, it's a very lightweight operation.
|
||||||
@ -74,16 +58,23 @@ void setup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This pulls in all the operation implementations we need.
|
// This pulls in all the operation implementations we need.
|
||||||
// NOLINTNEXTLINE(runtime-global-variables)
|
static tflite::MicroMutableOpResolver<4> resolver;
|
||||||
#if IS_USED(MODULE_TFLITE_MICRO)
|
if (resolver.AddFullyConnected() != kTfLiteOk) {
|
||||||
static tflite::AllOpsResolver resolver;
|
return;
|
||||||
#else
|
}
|
||||||
static tflite::ops::micro::AllOpsResolver resolver;
|
if (resolver.AddQuantize() != kTfLiteOk) {
|
||||||
#endif
|
return;
|
||||||
|
}
|
||||||
|
if (resolver.AddDequantize() != kTfLiteOk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (resolver.AddSoftmax() != kTfLiteOk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Build an interpreter to run the model with.
|
// Build an interpreter to run the model with.
|
||||||
static tflite::MicroInterpreter static_interpreter(
|
static tflite::MicroInterpreter static_interpreter(
|
||||||
model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
|
model, resolver, tensor_arena, kTensorArenaSize);
|
||||||
interpreter = &static_interpreter;
|
interpreter = &static_interpreter;
|
||||||
|
|
||||||
// Allocate memory from the tensor_arena for the model's tensors.
|
// Allocate memory from the tensor_arena for the model's tensors.
|
||||||
|
Loading…
Reference in New Issue
Block a user