pkg/tensorflow-lite: add support to RIOT

This commit is contained in:
Alexandre Abadie 2019-11-27 11:55:29 +01:00
parent 2af88551e7
commit 2c3c967244
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
13 changed files with 185 additions and 0 deletions

View File

@ -0,0 +1,29 @@
PKG_NAME=tensorflow-lite
PKG_URL=https://github.com/tensorflow/tensorflow
PKG_VERSION=1768c8f2fa155d4c6406e8ff7addf374c83de7ad
PKG_LICENSE=Apache2.0
include $(RIOTBASE)/pkg/pkg.mk
TF_MODULES = tensorflow-lite-hello_world
TF_USEMODULE = $(filter $(TF_MODULES),$(USEMODULE))
.PHONY: tensorflow-lite tensorflow-lite-%
CFLAGS += -Wno-pedantic
CFLAGS += -DTF_LITE_STATIC_MEMORY
CFLAGS += -DTF_LITE_USE_GLOBAL_ROUND
all: tensorflow-lite
tensorflow-lite: $(TF_USEMODULE)
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/c -f $(CURDIR)/Makefile.$(PKG_NAME)-c
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/core/api -f $(CURDIR)/Makefile.$(PKG_NAME)-core
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/kernels -f $(CURDIR)/Makefile.$(PKG_NAME)-kernels
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/kernels/internal -f $(CURDIR)/Makefile.$(PKG_NAME)-kernels-internal
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/micro/kernels -f $(CURDIR)/Makefile.$(PKG_NAME)-micro-kernels
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/micro/memory_planner -f $(CURDIR)/Makefile.$(PKG_NAME)-memory
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/micro -f $(CURDIR)/Makefile.$(PKG_NAME)
tensorflow-lite-%:
"$(MAKE)" -C $(PKG_BUILDDIR)/tensorflow/lite/micro/examples/$* -f $(CURDIR)/Makefile.$(PKG_NAME)-$*

View File

@ -0,0 +1,12 @@
USEMODULE += cpp11-compat
USEPKG += flatbuffers
USEPKG += gemmlowp
USEMODULE += tensorflow-lite
USEMODULE += tensorflow-lite-c
USEMODULE += tensorflow-lite-core
USEMODULE += tensorflow-lite-kernels
USEMODULE += tensorflow-lite-kernels-internal
USEMODULE += tensorflow-lite-memory
USEMODULE += tensorflow-lite-micro-kernels

View File

@ -0,0 +1 @@
INCLUDES += -I$(PKGDIRBASE)/tensorflow-lite

View File

@ -0,0 +1,12 @@
MODULE = tensorflow-lite
CXXEXFLAGS += -Wno-sign-compare
CXXEXFLAGS += -Wno-strict-aliasing
CXXEXFLAGS += -Wno-type-limits
CXXEXFLAGS += -Wno-unused-parameter
CXXEXFLAGS += -Wno-unused-variable
SRCXXEXT = cc
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,9 @@
MODULE = tensorflow-lite-c
CFLAGS += -Wno-strict-prototypes
CFLAGS += -Wno-old-style-definition
NO_AUTO_SRC = 1
SRC = common.c
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,17 @@
MODULE = tensorflow-lite-core
CXXEXFLAGS += -Wno-sign-compare
CXXEXFLAGS += -Wno-type-limits
SRCXXEXT = cc
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
NO_AUTO_SRC = 1
SRCXX = \
error_reporter.cc \
flatbuffer_conversions.cc \
op_resolver.cc \
tensor_utils.cc \
#
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,17 @@
MODULE = tensorflow-lite-hello_world
CXXEXFLAGS += -Wno-type-limits
CXXEXFLAGS += -Wno-unused-parameter
SRCXXEXT = cc
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
NO_AUTO_SRC = 1
SRCXX = \
constants.cc \
main_functions.cc \
output_handler.cc \
sine_model_data.cc \
#
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,12 @@
MODULE = tensorflow-lite-kernels
CXXEXFLAGS += -Wno-missing-field-initializers
CXXEXFLAGS += -Wno-unused-function
CXXEXFLAGS += -Wno-unused-parameter
SRCXXEXT = cc
NO_AUTO_SRC = 1
SRCXX = kernel_util.cc
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,12 @@
MODULE = tensorflow-lite-kernels-internal
CXXEXFLAGS += -Wno-missing-field-initializers
CXXEXFLAGS += -Wno-unused-function
CXXEXFLAGS += -Wno-unused-parameter
SRCXXEXT = cc
NO_AUTO_SRC = 1
SRCXX = quantization_util.cc
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,9 @@
MODULE = tensorflow-lite-memory
CXXEXFLAGS += -Wno-sign-compare
CXXEXFLAGS += -Wno-unused-parameter
SRCXXEXT = cc
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,15 @@
MODULE = tensorflow-lite-micro-kernels
CXXEXFLAGS += -Wno-missing-field-initializers
CXXEXFLAGS += -Wno-strict-overflow
CXXEXFLAGS += -Wno-type-limits
CXXEXFLAGS += -Wno-unused-parameter
ifeq (llvm,$(TOOLCHAIN))
CXXEXFLAGS += -Wno-unused-const-variable
endif
SRCXXEXT = cc
SRCXXEXCLUDE = $(wildcard *_test.$(SRCXXEXT))
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,7 @@
/**
* @defgroup pkg_tensorflow-lite TensorFlow Lite
* @ingroup pkg
* @brief Provides a RIOT support for TensorFlow Lite AI library
*
* @see https://www.tensorflow.org/lite/microcontrollers
*/

View File

@ -0,0 +1,33 @@
From e7d7acc96975ac47038fb7215925d4324b20aa86 Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Tue, 17 Dec 2019 11:53:05 +0100
Subject: [PATCH] use global round function
---
tensorflow/lite/kernels/internal/reference/concatenation.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tensorflow/lite/kernels/internal/reference/concatenation.h b/tensorflow/lite/kernels/internal/reference/concatenation.h
index f587cfd1c9..3767112738 100644
--- a/tensorflow/lite/kernels/internal/reference/concatenation.h
+++ b/tensorflow/lite/kernels/internal/reference/concatenation.h
@@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/internal/common.h"
#include "tensorflow/lite/kernels/internal/compatibility.h"
#include "tensorflow/lite/kernels/internal/types.h"
+#include "tensorflow/lite/kernels/internal/round.h"
namespace tflite {
namespace reference_ops {
@@ -122,7 +123,7 @@ inline void ConcatenationWithScaling(const ConcatenationParams& params,
const float bias = -input_zeropoint[i] * scale;
for (int j = 0; j < copy_size; ++j) {
const int32_t value =
- static_cast<int32_t>(std::round(input_ptr[j] * scale + bias)) +
+ static_cast<int32_t>(tflite::TfLiteRound(input_ptr[j] * scale + bias)) +
output_zeropoint;
output_ptr[j] = static_cast<uint8_t>(
std::max<int32_t>(std::min<int32_t>(255, value), 0));
--
2.20.1