LoginSignup
5
3

More than 1 year has passed since last update.

Tensorflow lite/micro 用の SPRESENSE Arduino パッケージを作ってみた (SDK Ver 2.5.0対応)

Last updated at Posted at 2022-01-22

SPRESENSEはArduino IDEで開発できて、しかもかなり高度なライブラリも準備されており、とても便利です。ですがSDKで用意されているTensorflowのような外部ライブラリは使えません。Spresense Arduino LibraryはプリコンパイルされたOS(NuttX)を使っているためです。

しかし、逃げ道はあります。SPRESENSEの開発環境は、独自にSPRESENSEのArduinoパッケージを作ることができるようになっており、公式ドキュメントでも作る方法が紹介されています。

Spresense Arduino board package ローカルパッケージの作成

ただ、いざやろうとするとかなり苦労します。手順はそれぞれのライブラリによって異なりますし、SDKのビルド環境やArduino IDEの仕組みがある程度わかっている人でないと、間違いなく心が折れます。

今回は、Tensorflow lite/microをサポートしたSPRESENSEのArduinoパッケージを作成する手順を説明します。変更するポイントは他のライブラリも同じなので。独自のライブラリを作りたい場合の参考にもなると思います。

標準でサポートしている機能

標準のSpresense Arduino Libraryパッケージがサポートしている機能は、sprerense-arduino-comaptibletools/config/で定義されています。spresense.confはメインコア用の設定で、spresense_sub.confがサブコア用です。

spresense.conf
default device/adc device/camera device/charger device/emmc \
device/hostif device/pwm device/sdcard \
feature/asmp feature/audio_player feature/audio_recorder \
feature/audio_recognizer feature/audio_synthesizer \
feature/dnnrt_mp feature/fwuputils feature/gnss \
feature/imageproc feature/libcxx feature/lte_stub_mbedtls \
feature/step_counter feature/digital_filters \
-- +CXD56_I2C_DRIVER=n +CXD56_I2C1 +CXD56_I2C1_SCUSEQ=n \
+CXD56_LTE_LATE_INITIALIZE=y +CXD56_HPADC0_INPUT_GAIN_M6DB \
+CXD56_HPADC1_INPUT_GAIN_M6DB +CXD56_USE_SYSBUS=n -LTE_SYSCTL=y
spresense_sub.conf
feature/subcore feature/digital_filters feature/libcxx \
-- +CXD56_I2C_DRIVER=n +CXD56_I2C1 +CXD56_I2C1_SCUSEQ=n \
+CXD56_HPADC0_INPUT_GAIN_M6DB +CXD56_HPADC1_INPUT_GAIN_M6DB \
+CXD56_USE_SYSBUS=n

これらの項目を変更すれば、メインコアやサブコアがサポートする機能を選択できるようになります。今回はメインコアでTensorflowを動かしますので、spresnse.confにTensorflowを追加します。やり方は後述します。

SDKがサポートしている外部ライブラリ

作業に入る前にSDKがサポートしているライブラリを確認しましょう。Spresense SDKがサポートしている外部ライブラリはspresense/externalsフォルダにあります。

ライブラリ名  機能 
alt_stubs  mbedtlsのスタブ 
awsiot  AWSIoTライブラリ 
cmsis  CMSISライブラリ 
libjpeg  JPEGライブラリ 
lwm2m  Lightweight M2Mライブラリ 
mbedtls  mbedTLSライブラリ 
nnablart  DNNRTライブラリ 
sslutils  SSLユーティリティライブラリ 
tensorflow  tensorflowライブラリ 
vtun  VPN関連ライブラリ 
wavelib  Wavelet変換ライブラリ 
websocket  WebScoketライブラリ 

Tensorflow lite/microを有効にする手順

Tensorflowを有効にするには、Spresense SDKspresense-arduino-comaptibleをgithubからクローンする必要があります。その後にコンフィギュレーションファイルやビルド関連ファイルを編集してTensorflowを有効にしていきます。

問題はこの変更箇所です。公式で提供されている情報だけで外部ライブラリを有効にしようとするとなかなか骨の折れる仕事になります。(実際、かなり苦労しました)

ここでは、他のライブラリの導入のヒントとなるように、できるだけポイントに絞って説明します。今回は、開発のホストにLinux Ubuntuを使っています。

SDKのインストール

SDKのインストールは公式ドキュメントを参照してください。

spresense-arduino-compatibleの準備

GitHubから次のコマンドでクローンします。

$ git clone --recursive https://github.com/sonydevworld/spresense-arduino-compatible.git

メインコアのコンフィギュレーションの変更

spresense-arduino-comaptible/tools/configs/spresense.confに"Tensorflow"を追加します。同時に"DNNRT"は削除します。(ついでにステップカウンターも使わないので削除してます)

spresense.conf
default device/adc device/camera device/charger device/emmc \
device/hostif device/pwm device/sdcard \
feature/asmp feature/audio_player feature/audio_recorder \
feature/audio_recognizer feature/audio_synthesizer \
feature/fwuputils feature/gnss \
feature/imageproc feature/libcxx feature/lte_stub_mbedtls feature/digital_filters \
feature/tensorflow \
-- +CXD56_I2C_DRIVER=n +CXD56_I2C1 +CXD56_I2C1_SCUSEQ=n \
+CXD56_LTE_LATE_INITIALIZE=y +CXD56_HPADC0_INPUT_GAIN_M6DB \
+CXD56_HPADC1_INPUT_GAIN_M6DB +CXD56_USE_SYSBUS=n -LTE_SYSCTL=y

ここでfeature/tensorflowはSpresense SDKで定義されているコンフィグ設定です。spresense/sdk/configs/feature/tensorflow/defconfigが有効になります。

+EXTERNALS_TENSORFLOW=y

Arduino IDE設定ファイルの変更

Arduino IDEが起動するときに参照するのが、boards.txtplatform.txtいう設定ファイルです。コンパイル時もリンクするライブラやコンパイルオプションをここで指定します。boards.txtplatform.txtは、少しディレクトリが深い位置にあります。`spresense-arduino-comapatible/Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/

board.txtの変更

boards.txtはリンクするライブラリを設定します。今回は、Tensorflowを有効にして、DNNRTは無効にします。

100行目を変更します。

削除→ "{build.libpath}/libnnablart.a" 追加→"{build.libpath}/libtensorflow-microlite.a"

platform.txtの変更

platform.txtはコンパイラの設定を行っています。Tensorflowをコンパイルするためのコンパイラオプションを追加します。

35行目に次のオプションを追加します。
-fno-threadsafe-statics -fno-unwind-tables -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -DSPRESENSE -DCMSIS_NN -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK

プリコンパイルNuttX生成用シェルの変更

Spresense Arduino LibraryはプリコンパイルのNuttXを使います。Tensorflowを使えるようにするのは、Spresense SDKのビルド設定を変更する必要があります。変更をするのは、次のファイルです。

spresense/sdk/tools/mksdkexport.sh

ビルドしたライブラリを出力に追加します。Spresense SDK Ver2.5.0で Tensorflow のビルド構成、ディレクトリ構成が大幅に変わりました。これは、Tensorflow のポリシー変更によるためです。それぞれ別に記載しますので参考にしてください。

【Spresense SDK Ver2.4.0/2.5.0共通】

変更前:mksdkexport.sh: 130,136行目

mksdkexport.sh
LIBLIST=(\
	${SDK_DIR}/../externals/cmsis/dsp/libarm_cortexM4lf_math.a\
	${SDK_DIR}/../externals/cmsis/nn/libcmsis_nn.a\
	${SDK_DIR}/../externals/sslutils/libsslutils.a\
	${SDK_DIR}/modules/sensing/gnss/cxd56nmea/libcxd56nmea.a\
	${SDK_DIR}/modules/libmodules.a\
)

変更後:mksdkexport.sh: 130,137行目

mksdkexport.sh
LIBLIST=(\
        ${SDK_DIR}/../externals/cmsis/dsp/libarm_cortexM4lf_math.a\
        ${SDK_DIR}/../externals/cmsis/nn/libcmsis_nn.a\
        ${SDK_DIR}/../externals/sslutils/libsslutils.a\
        ${SDK_DIR}/../externals/tensorflow/libtensorflow-microlite.a\
        ${SDK_DIR}/modules/sensing/gnss/cxd56nmea/libcxd56nmea.a\
        ${SDK_DIR}/modules/libmodules.a\
)

Tensorflowの場合は、ディレクトリで細分化している上に依存ヘッダー多く、変更量がかなり多くなってしまいました。

変更前:mksdkexport.sh: 111,112行目

mksdkexport.sh
# Copy External header files
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include

変更後:mksdkexport.sh: 112行以降

【Spresense SDK Ver2.5.0の場合】

mksdkexport.sh
# Copy External header files
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include
## third_party
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/flatbuffers
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/fixedpoint
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/internal
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/kissfft/tools
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/ruy/ruy/profiler
## tensorflow/lite
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/c
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/core/api
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/experimental/microfrontend/lib
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/kernels/internal
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/schema
## tensorflow/lite/micro
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/kernels
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/memory_planner
export $(sed 's/ //g' ${SDK_DIR}/../externals/tensorflow/TensorflowTag.mk);
## third_party
TENSORFLOW_DIR=${SDK_DIR}/../externals/tensorflow/tflite-micro-spresense-examples-${TENSORFLOW_TAG}
TARGET_DIR=${TMP_DIR}/${SDK_EXP_SDK}/externals
## copy flatbuffer headers
cp -a ${TENSORFLOW_DIR}/third_party/flatbuffers/include/flatbuffers/*.h ${TARGET_DIR}/include/flatbuffers
## copy gemmlowp headers
cp -a ${TENSORFLOW_DIR}/third_party/gemmlowp/fixedpoint/*.h ${TARGET_DIR}/include/gemmlowp/fixedpoint
cp -a ${TENSORFLOW_DIR}/third_party/gemmlowp/internal/*.h ${TARGET_DIR}/include/gemmlowp/internal
## copy kissfft headers
cp -a ${TENSORFLOW_DIR}/third_party/kissfft/*.h ${TARGET_DIR}/include/kissfft
cp -a ${TENSORFLOW_DIR}/third_party/kissfft/tools/*.h ${TARGET_DIR}/include/kissfft/tools
## copy ruy headers
cp -a ${TENSORFLOW_DIR}/third_party/ruy/ruy/profiler/*.h ${TARGET_DIR}/include/ruy/ruy/profiler
## copy tensorflow/lite headers
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/*.h ${TARGET_DIR}/include/tensorflow/lite
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/c/*.h ${TARGET_DIR}/include/tensorflow/lite/c
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/core/api/*.h ${TARGET_DIR}/include/tensorflow/lite/core/api
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/experimental/microfrontend/lib/*.h ${TARGET_DIR}/include/tensorflow/lite/experimental/microfrontend/lib
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/kernels/*.h ${TARGET_DIR}/include/tensorflow/lite/kernels
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/kernels/internal/*.h ${TARGET_DIR}/include/tensorflow/lite/kernels/internal
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/schema/*.h ${TARGET_DIR}/include/tensorflow/lite/schema
## copy tensorflow/lite/micro headers
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/micro/*.h ${TARGET_DIR}/include/tensorflow/lite/micro
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/micro/kernels/*.h ${TARGET_DIR}/include/tensorflow/lite/micro/kernels
cp -a ${TENSORFLOW_DIR}/tensorflow/lite/micro/memory_planner/*.h ${TARGET_DIR}/include/tensorflow/lite/micro/memory_planner

【Spresense SDK Ver2.4.0の場合】

mksdkexport.sh
# Copy External header files
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include
## third_party
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/flatbuffers
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/fixedpoint
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/internal
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/kissfft/tools
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/ruy/ruy/profiler
## tensorflow/lite
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/core/public
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/c
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/core/api
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/core/public
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/benchmarks
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/kernels
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/memory_planner
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/testing
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/schema
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/kernels/internal/optimized
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/kernels/internal/reference
mkdir -p ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/experimental/microfrontend/lib
export $(sed 's/ //g' ${SDK_DIR}/../externals/tensorflow/TensorflowSHA1.mk);
## third_party
# copy flatbuffer headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/flatbuffers/include/flatbuffers/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/flatbuffers
# copy gemmlowp headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/gemmlowp/fixedpoint/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/fixedpoint
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/gemmlowp/internal/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/gemmlowp/internal
# copy kissfft headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/kissfft/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/kissfft
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/kissfft/tools/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/kissfft/tools
# copy ruy headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/downloads/ruy/ruy/profiler/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/ruy/ruy/profiler
## tensorflow/core/public
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/core/public/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/core/public
## tensorflow/lite
# copy lite headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite
# copy c headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/c/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/c
# copy core/api headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/core/api/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/core/api
# copy experimental headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/experimental/microfrontend/lib/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/experimental/microfrontend/lib
# copy kernels headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/kernels/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/kernels
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/kernels/internal/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/kernels/internal
# copy micro headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/benchmarks/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/benchmarks
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/kernels/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/kernels
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/memory_planner/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/memory_planner
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/testing/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/micro/testing
# copy schema headers
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/schema/*.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include/tensorflow/lite/schema
# copy TensofFlowLite header
cp -a ${SDK_DIR}/../externals/tensorflow/tensorflow-${TENSORFLOW_SHA1}/tensorflow/lite/micro/tools/make/templates/TensorFlowLite.h ${TMP_DIR}/${SDK_EXP_SDK}/externals/include

Spresense Arduino Libraryの生成

Spresense Arduino Librarynの生成は、公式で説明されている通りの手順です。メインコアのリリース版とデバッグ版、サブコアのリリース版とでバック版の計4つコンパイルします。

$ cd spresense-arduino-compatible
$ ./tools/prepare_arduino.sh -S path/to/spresense -c spresense -d disable -p
$ ./tools/prepare_arduino.sh -S path/to/spresense -c spresense -d enable -p
$ ./tools/prepare_arduino.sh -S path/to/spresense -c spresense_sub -d disable -p
$ ./tools/prepare_arduino.sh -S path/to/spresense -c spresense_sub -d enable -p

この後に、Arduino Libraryパッケージを作成します。spresense-arduino-compatibleで
ビルドを行います。outディレクトリにjsonファイルとパッケージが生成されます。

cd spresense-arduino-compatible
make

その後、Arduino15フォルダにjsonとパッケージをコピーします。今回はLinuxを使っていますが、Arduino15フォルダの場所は、お使いのプラットフォームにあわせてください。

cp -r ./out/staging  ~/snap/arduino/61/.arduino15

Spresense Arduino Libraryのインストール

Arduino Libraryのインストールはこちらも公式の通りです。Arduino IDEのボードマネージャーURLに、package_spresense_local_index.jsonのファイルパスを追加します。

今回の場合は、file:///home/<user>/spresense-arduino-compatible/out/package_spresense_local_index.json を追加します。

Arduino IDE Board Manager

Tensorflow lite/microのサンプル

動作確認のためにSPRESENSEで動かした"Helloworld"サンプルです。Tensorflowの学習済モデルは、modelファイルに格納されています。

spresense_tf_helloworld.cpp
#include <TensorFlowLite.h>
#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/system_setup.h"
#include "tensorflow/lite/schema/schema_generated.h"

namespace {
tflite::ErrorReporter* error_reporter = nullptr;
const tflite::Model* model = nullptr;
tflite::MicroInterpreter* interpreter = nullptr;
TfLiteTensor* input = nullptr;
TfLiteTensor* output = nullptr;
int inference_count = 0;

constexpr int kTensorArenaSize = 2000;
uint8_t tensor_arena[kTensorArenaSize];
}  // namespace


const float kXrange = 2.f * 3.14159265359f;
const int kInferencesPerCycle = 20;

extern const unsigned char g_model[];
extern const int g_model_len;

void setup() {
  
  Serial.begin(115200);
  tflite::InitializeTarget();

  // Set up logging. 
  static tflite::MicroErrorReporter micro_error_reporter;
  error_reporter = &micro_error_reporter;

  // Map the model into a usable data structure..
  model = tflite::GetModel(g_model);
  if (model->version() != TFLITE_SCHEMA_VERSION) {
    Serial.println("Model provided is schema version " 
                  + String(model->version()) + " not equal "
                  + "to supported version "
                  + String(TFLITE_SCHEMA_VERSION));
    return;
  } else {
    Serial.println("Model version: " + String(model->version()));
  }

  // This pulls in all the operation implementations we need.
  static tflite::AllOpsResolver resolver;

  // Build an interpreter to run the model with.
  static tflite::MicroInterpreter static_interpreter(
      model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
  interpreter = &static_interpreter;

  // Allocate memory from the tensor_arena for the model's tensors.
  TfLiteStatus allocate_status = interpreter->AllocateTensors();
  if (allocate_status != kTfLiteOk) {
    Serial.println("AllocateTensors() failed");
    return;
  }

  // Obtain pointers to the model's input and output tensors.
  input = interpreter->input(0);
  output = interpreter->output(0);

  // Keep track of how many inferences we have performed.
  inference_count = 0;
}

void loop() {
  // Calculate an x value to feed into the model.
  float position_x = static_cast<float>(inference_count) /
                   static_cast<float>(kInferencesPerCycle);
  float x = position_x * kXrange;

  // Quantize the input from floating-point to integer
  int8_t x_quantized = x / input->params.scale + input->params.zero_point;

  // Place the quantized input in the model's input tensor
  input->data.int8[0] = x_quantized;

  // Run inference, and report any error
  TfLiteStatus invoke_status = interpreter->Invoke();
  if (invoke_status != kTfLiteOk) {
    Serial.println("Invoke failed on x: " + String(x));
    return;
  }

  // Obtain the quantized output from model's output tensor
  int8_t y_quantized = output->data.int8[0];
  
  // Dequantize the output from integer to floating-point
  float y = (y_quantized - output->params.zero_point) * output->params.scale;
  Serial.println("y_value: " + String(y));

  ++inference_count;
  if (inference_count >= kInferencesPerCycle) inference_count = 0;
}
model.cpp
// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses.
alignas(8) const unsigned char g_model[] = {
    0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00,
    0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00,
    0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
    0x98, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
    0x2c, 0x03, 0x00, 0x00, 0x30, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xf7, 0xff, 0xff,
    0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
    0x44, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76,
    0x65, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76,
    0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xff, 0xff, 0xff,
    0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
    0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x04, 0x00, 0x00, 0x00, 0x76, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
    0x0d, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f,
    0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00,
    0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74,
    0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00,
    0x0c, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00,
    0x34, 0x02, 0x00, 0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00,
    0x6c, 0x01, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
    0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
    0x04, 0x00, 0x00, 0x00, 0xfa, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xfd, 0xff, 0xff,
    0x88, 0xfd, 0xff, 0xff, 0x8c, 0xfd, 0xff, 0xff, 0x22, 0xfe, 0xff, 0xff,
    0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0xa5, 0x8b, 0xca,
    0x5e, 0x1d, 0xce, 0x42, 0x9d, 0xce, 0x1f, 0xb0, 0xdf, 0x54, 0x2f, 0x81,
    0x3e, 0xfe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
    0xee, 0xfc, 0x00, 0xec, 0x05, 0x17, 0xef, 0xec, 0xe6, 0xf8, 0x03, 0x01,
    0x00, 0xfa, 0xf8, 0xf5, 0xdc, 0xeb, 0x27, 0x14, 0xf1, 0xde, 0xe2, 0xdb,
    0xf0, 0xde, 0x31, 0x06, 0x02, 0xe6, 0xee, 0xf9, 0x00, 0x16, 0x07, 0xe0,
    0xfe, 0xff, 0xe9, 0x06, 0xe7, 0xef, 0x81, 0x1b, 0x18, 0xea, 0xc9, 0x01,
    0x0f, 0x00, 0xda, 0xf7, 0x0e, 0xec, 0x13, 0x1f, 0x04, 0x13, 0xb4, 0xe6,
    0xfd, 0x06, 0xb9, 0xe0, 0x0d, 0xec, 0xf0, 0xde, 0xeb, 0xf7, 0x05, 0x26,
    0x1a, 0xe4, 0x6f, 0x1a, 0xea, 0x1e, 0x35, 0xdf, 0x1a, 0xf3, 0xf1, 0x19,
    0x0f, 0x03, 0x1b, 0xe1, 0xde, 0x13, 0xf6, 0x19, 0xff, 0xf6, 0x1b, 0x18,
    0xf0, 0x1c, 0xda, 0x1b, 0x1b, 0x20, 0xe5, 0x1a, 0xf5, 0xff, 0x96, 0x0b,
    0x00, 0x01, 0xcd, 0xde, 0x0d, 0xf6, 0x16, 0xe3, 0xed, 0xfc, 0x0e, 0xe9,
    0xfa, 0xeb, 0x5c, 0xfc, 0x1d, 0x02, 0x5b, 0xe2, 0xe1, 0xf5, 0x15, 0xec,
    0xf4, 0x00, 0x13, 0x05, 0xec, 0x0c, 0x1d, 0x14, 0x0e, 0xe7, 0x0b, 0xf4,
    0x19, 0x00, 0xd7, 0x05, 0x27, 0x02, 0x15, 0xea, 0xea, 0x02, 0x9b, 0x00,
    0x0c, 0xfa, 0xe8, 0xea, 0xfd, 0x00, 0x14, 0xfd, 0x0b, 0x02, 0xef, 0xee,
    0x06, 0xee, 0x01, 0x0d, 0x06, 0xe6, 0xf7, 0x11, 0xf7, 0x09, 0xf8, 0xf1,
    0x21, 0xff, 0x0e, 0xf3, 0xec, 0x12, 0x26, 0x1d, 0xf2, 0xe9, 0x28, 0x18,
    0xe0, 0xfb, 0xf3, 0xf4, 0x05, 0x1d, 0x1d, 0xfb, 0xfd, 0x1e, 0xfc, 0x11,
    0xe8, 0x07, 0x09, 0x03, 0x12, 0xf2, 0x36, 0xfb, 0xdc, 0x1c, 0xf9, 0xef,
    0xf3, 0xe7, 0x6f, 0x0c, 0x1d, 0x00, 0x45, 0xfd, 0x0e, 0xf0, 0x0b, 0x19,
    0x1a, 0xfa, 0xe0, 0x19, 0x1f, 0x13, 0x36, 0x1c, 0x12, 0xeb, 0x3b, 0x0c,
    0xb4, 0xcb, 0xe6, 0x13, 0xfa, 0xeb, 0xf1, 0x06, 0x1c, 0xfa, 0x18, 0xe5,
    0xeb, 0xcb, 0x0c, 0xf4, 0x4a, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0x75, 0x1c, 0x11, 0xe1, 0x0c, 0x81, 0xa5, 0x42,
    0xfe, 0xd5, 0xd4, 0xb2, 0x61, 0x78, 0x19, 0xdf, 0x66, 0xff, 0xff, 0xff,
    0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x77, 0x0b, 0x00, 0x00, 0x53, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
    0x77, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0xd3, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x72, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x07, 0x00, 0x00,
    0x67, 0xf5, 0xff, 0xff, 0x34, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
    0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0xb5, 0x04, 0x00, 0x00, 0x78, 0x0a, 0x00, 0x00,
    0x2d, 0x06, 0x00, 0x00, 0x71, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
    0x9a, 0x0a, 0x00, 0x00, 0xfe, 0xf7, 0xff, 0xff, 0x0e, 0x05, 0x00, 0x00,
    0xd4, 0x09, 0x00, 0x00, 0x47, 0xfe, 0xff, 0xff, 0xb6, 0x04, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0xac, 0xf7, 0xff, 0xff, 0x4b, 0xf9, 0xff, 0xff,
    0x4a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00,
    0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x8c, 0xef, 0xff, 0xff, 0x84, 0xff, 0xff, 0xff, 0x88, 0xff, 0xff, 0xff,
    0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 0x20, 0x43, 0x6f, 0x6e,
    0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00,
    0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00,
    0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00,
    0xe0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
    0x84, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x96, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
    0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
    0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
    0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
    0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
    0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
    0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
    0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00,
    0x0e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
    0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
    0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00,
    0xd0, 0x03, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00,
    0x98, 0x02, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00,
    0x24, 0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0xf0, 0xfb, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
    0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
    0x01, 0x00, 0x00, 0x00, 0xdc, 0xfb, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
    0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x4a, 0xce, 0x0a, 0x3c, 0x01, 0x00, 0x00, 0x00,
    0x34, 0x84, 0x85, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x8f, 0xbf,
    0x1e, 0x00, 0x00, 0x00, 0x53, 0x74, 0x61, 0x74, 0x65, 0x66, 0x75, 0x6c,
    0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x43,
    0x61, 0x6c, 0x6c, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00,
    0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x80, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x54, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
    0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
    0x10, 0x00, 0x00, 0x00, 0x6c, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
    0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0x01, 0x00, 0x00, 0x00, 0x93, 0xd0, 0xc0, 0x3b, 0x01, 0x00, 0x00, 0x00,
    0xc2, 0x0f, 0xc0, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x14, 0x00, 0x00, 0x00, 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c,
    0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x31,
    0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0x08, 0xfd, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00,
    0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
    0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xf4, 0xfc, 0xff, 0xff,
    0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0xe0, 0xdb, 0x47, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x04, 0x14, 0x47, 0x40,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
    0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, 0x79, 0x5f, 0x63, 0x6f,
    0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff,
    0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, 0x6c, 0xfd, 0xff, 0xff,
    0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
    0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x4b, 0x0b, 0x3c,
    0x01, 0x00, 0x00, 0x00, 0x40, 0x84, 0x4b, 0x3f, 0x01, 0x00, 0x00, 0x00,
    0x63, 0x35, 0x8a, 0xbf, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e,
    0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x32, 0x00, 0x00, 0x00,
    0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
    0x72, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
    0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00,
    0xdc, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
    0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x60, 0x01, 0x4f, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x47, 0x6d, 0xb3, 0x3f,
    0x01, 0x00, 0x00, 0x00, 0x5d, 0x63, 0xcd, 0xbf, 0x0d, 0x00, 0x00, 0x00,
    0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74,
    0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0xe2, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00,
    0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
    0x50, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00,
    0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0xd5, 0x6b, 0x8a, 0x3b, 0x01, 0x00, 0x00, 0x00,
    0xab, 0x49, 0x01, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xfd, 0x56, 0x09, 0xbf,
    0x0c, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73,
    0x74, 0x61, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x52, 0xff, 0xff, 0xff,
    0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x44, 0xff, 0xff, 0xff,
    0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x28, 0xb3, 0xd9, 0x38, 0x0c, 0x00, 0x00, 0x00,
    0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x62, 0x69, 0x61, 0x73,
    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
    0xaa, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00,
    0x9c, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0xdd, 0x9b, 0x21, 0x39, 0x0c, 0x00, 0x00, 0x00,
    0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x62, 0x69, 0x61, 0x73,
    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00,
    0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x48, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
    0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0xf4, 0xd4, 0x51, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73,
    0x65, 0x5f, 0x34, 0x2f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00,
    0x18, 0x00, 0x17, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
    0x2c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x09, 0x84, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
    0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00,
    0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
    0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
    0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x5d, 0x4f, 0xc9, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x86, 0xc8, 0x40,
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
    0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61,
    0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f,
    0x69, 0x6e, 0x70, 0x75, 0x74, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38,
    0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
    0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff,
    0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
    0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
    0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72,
    0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
    0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x09};
const int g_model_len = 2488;

作業をしてみた感想

対応方法を書き起こしてみたものの、ここまでやるのはなかなか大変でした。これらの一連の変更を再び行うのはあまり現実的ではありません。ということで、どこかのタイミングでこのパッケージをGithubに公開したいと思います。少しTensorflow lite/microとも仲良くなってきたので、応用アプリケーションにもチャレンジしていきたいと思います。

参考資料

Tensorflow対応のSPRESENSE Arduinoパッケージを作ってみた話 

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3