samples/modules/tflite-micro/hello_world/README.html · samples/modules/tflite-micro/hello_world/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · TFLM

TensorFlow Lite Micro Hello World

0부터 2π까지 x와 예측 y를 출력하고 자체 model training 구성을 안내합니다.

Official pathsamples/modules/tflite-micro/hello_world/README.html
Source filesamples/modules/tflite-micro/hello_world/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

QEMU reference kernel, Corstone-300 CMSIS-NN, Kconfig와 malformed source command를 보존합니다.

Model

Sine

Kernels

Reference · CMSIS-NN

Output

10 pairs

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 1295E08C3C1FBC3D0AB02EEC198177A888F3F7F18B22A125AE6F907FBD5841FD
.. _tensorflow_hello_world:

TensorFlow Lite Micro Hello World sample
########################################

Overview
********

This sample TensorFlow application replicates a sine wave and
demonstrates the absolute basics of using TensorFlow Lite Micro.

The model included with the sample is trained to replicate a
sine function and generates x values to print alongside the
y values predicted by the model. The x values iterate from 0 to
an approximation of 2π.

The sample also includes a full end-to-end workflow of training
a model and converting it for use with TensorFlow Lite Micro for
running inference on a microcontroller.

The sample comes in two flavors. One with TensorFlow Lite Micro
reference kernels and one with CMSIS-NN optimized kernels.

.. Note::
   This README and sample have been modified from
   `the TensorFlow Hello World sample for Zephyr`_.

.. _the TensorFlow Hello World sample for Zephyr:
   https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world

Building and Running
********************

The sample should work on most boards since it does not rely
on any sensors.

Add the tflite-micro module to your West manifest and pull it:

.. code-block:: console

    west config manifest.project-filter -- +tflite-micro
    west update

The reference kernel application can be built and executed on QEMU as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/modules/tflite-micro/hello_world
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.

The CMSIS-NN kernel application can be built and executed on any Arm(R) Cortex(R)-M core based platform,
for example based on Arm Corstone(TM)-300 software. A reference implementation of Corstone-300
can be downloaded either as a FPGA bitfile for the
[MPS3 FPGA prototyping board](https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3),
or as a
[Fixed Virtual Platform](https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps)
that can be emulated on a host machine.

Assuming that the Corstone-300 FVP has been downloaded, installed and added to
the `PATH` variable, then building and testing can be done with following
commands.

```
$ west build -p auto -b mps3/an547 samples/modules/tflite-micro/hello_world/ -T sample.tensorflow.helloworld.cmsis_nn
$ FVP_Corstone_SSE-300_Ethos-U55 build/zephyr/zephyr.elf
```

Sample Output
=============

.. code-block:: console

    ...

    x_value: 1.0995567*2^1, y_value: 1.6951603*2^-1

    x_value: 1.2566366*2^1, y_value: 1.1527088*2^-1

    x_value: 1.4137159*2^1, y_value: 1.1527088*2^-2

    x_value: 1.5707957*2^1, y_value: -1.0849024*2^-6

    x_value: 1.7278753*2^1, y_value: -1.0509993*2^-2

    ...

The modified sample prints 10 generated-x-and-predicted-y pairs. To see
the full period of the sine curve, increase the number of loops in :file:`main.c`.

Modifying Sample for Your Own Project
*************************************

It is recommended that you copy and modify one of the two TensorFlow
samples when creating your own TensorFlow project. To build with
TensorFlow, you must enable the below Kconfig options in your :file:`prj.conf`:

.. code-block:: cfg

    CONFIG_CPP=y
    CONFIG_REQUIRES_FULL_LIBC=y
    CONFIG_TENSORFLOW_LITE_MICRO=y

Note that the CMSIS-NN kernel sample demonstrates how to use CMSIS-NN optimized kernels with
TensorFlow Lite Micro, in that is sets below Kconfig option. Note also that this
Kconfig option is only set for Arm Cortex-M cores, i.e. option CPU_CORTEX_M is set.

.. code-block:: cfg

    CONFIG_TENSORFLOW_LITE_MICRO_CMSIS_NN_KERNELS=y

Training
********
Follow the instructions in the :file:`train/` directory to train your
own model for use in the sample.

Part 3

한국어 전문 번역

개요

이 TensorFlow sample application은 sine wave를 재현하며 TensorFlow Lite Micro 사용의 가장 기본적인 사항을 보여줍니다.

Sample에 포함된 model은 sine function을 재현하도록 training되어 있습니다. Model이 예측한 y 값과 함께 출력할 x 값을 생성하며 x 값은 0에서 약 2π까지 순회합니다.

Microcontroller에서 inference를 수행할 수 있도록 model을 training하고 TensorFlow Lite Micro용으로 변환하는 전체 end-to-end workflow도 포함합니다.

Sample은 TensorFlow Lite Micro reference kernel을 사용하는 version과 CMSIS-NN optimized kernel을 사용하는 version 두 가지로 제공됩니다. 이 README와 sample은 TensorFlow의 Zephyr용 Hello World sample을 수정한 것입니다.

Build와 실행

Sensor에 의존하지 않으므로 대부분의 board에서 이 sample이 동작합니다.

West manifest에 tflite-micro module을 추가하고 내려받습니다.

west config manifest.project-filter -- +tflite-micro
west update

Reference kernel application은 다음과 같이 QEMU에서 build하고 실행합니다.

west build -b qemu_x86 samples/modules/tflite-micro/hello_world
west build -t run

CTRL+A를 누른 뒤 x를 눌러 QEMU를 종료합니다.

CMSIS-NN kernel application은 Arm Cortex-M core 기반 platform에서 build하고 실행할 수 있습니다. 예를 들어 Arm Corstone-300 software를 사용할 수 있으며, reference implementation은 MPS3 FPGA prototyping board용 FPGA bitfile이나 host에서 emulation할 수 있는 Fixed Virtual Platform으로 받을 수 있습니다.

Corstone-300 FVP를 내려받아 설치하고 PATH에 추가했다면 다음 명령으로 build하고 시험합니다. 원문에 Markdown fence로 적힌 명령을 읽을 수 있는 code block으로 구조화했습니다.

$ west build -p auto -b mps3/an547 samples/modules/tflite-micro/hello_world/ -T sample.tensorflow.helloworld.cmsis_nn
$ FVP_Corstone_SSE-300_Ethos-U55 build/zephyr/zephyr.elf

Sample 출력

...

x_value: 1.0995567*2^1, y_value: 1.6951603*2^-1

x_value: 1.2566366*2^1, y_value: 1.1527088*2^-1

x_value: 1.4137159*2^1, y_value: 1.1527088*2^-2

x_value: 1.5707957*2^1, y_value: -1.0849024*2^-6

x_value: 1.7278753*2^1, y_value: -1.0509993*2^-2

...

수정된 sample은 생성한 x 값과 예측한 y 값의 pair 10개를 출력합니다. Sine curve의 전체 period를 보려면 main.c에서 loop 횟수를 늘리십시오.

자체 project용 sample 수정

자체 TensorFlow project를 만들 때는 TensorFlow sample 두 개 중 하나를 복사해 수정하는 방법을 권장합니다. TensorFlow를 포함해 build하려면 prj.conf에서 다음 Kconfig option을 활성화해야 합니다.

CONFIG_CPP=y
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_TENSORFLOW_LITE_MICRO=y

CMSIS-NN kernel sample은 TensorFlow Lite Micro에서 CMSIS-NN optimized kernel을 사용하는 방법을 보여주기 위해 다음 Kconfig option도 설정합니다. 이 option은 CPU_CORTEX_M이 설정된 Arm Cortex-M core에서만 사용합니다.

CONFIG_TENSORFLOW_LITE_MICRO_CMSIS_NN_KERNELS=y

Training

Sample에서 사용할 자체 model을 training하려면 train/ directory의 지침을 따르십시오.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.