8000 Sync with TFLM by Gostas · Pull Request #2 · Gostas/tflite-micro-arduino-examples · GitHub
[go: up one dir, main page]

Skip to content

Sync with TFLM #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ jobs:
- uses: actions/checkout@v4
- name: Test
run: |
./scripts/install_arduino_cli.sh
./scripts/test_arduino_library.sh "${PWD}"
cd src/
../scripts/install_arduino_cli.sh
../scripts/test_arduino_library.sh .
6 changes: 5 additions & 1 deletion .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ jobs:
git commit -m "Sync from tflite-micro."
fi

git push --set-upstream origin AutoSync

- name: Create Pull Request
run: gh pr create -B main -H "AutoSync" -t 'Automated sync from TFLM' -b 'Created by Github action' -r Gostas
run: |
gh repo set-default Gostas/tflite-micro-arduino-examples
gh pr create -B main -H AutoSync -t 'Automated sync with TFLM' -b 'Created by Github action' -r Gostas
env:
GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
*.elf
*.map
*.obj
*.a
logs.txt
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TensorFlow Lite Micro library for Arduino

This is a fork of the [Arduino TensorFlow Lite Micro](https://github.com/tensorflow/tflite-micro-arduino-examples) library. It has been updated to use the latest code from the [TensorFlow Lite Micro](github.com/tensorflow/tflite-micro) repository, with fully functional example sketches and the additional capability of creating a static library for use with the Arduino environment.
This is a fork of the [Arduino TensorFlow Lite Micro](https://github.com/tensorflow/tflite-micro-arduino-examples) library. It has been updated to use the latest code from the [TensorFlow Lite Micro](https://github.com/tensorflow/tflite-micro) repository, with fully functional example sketches and the additional capability of creating a static library for use with the Arduino environment.

## Table of contents
<!--ts-->
Expand All @@ -21,8 +21,8 @@ This is a fork of the [Arduino TensorFlow Lite Micro](https://github.com/tensorf

Build Type | Status |
--------------- | ------------- |
Arduino CLI on Linux | [![Arduino](https://github.com/tensorflow/tflite-micro-arduino-examples/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/tensorflow/tflite-micro-arduino-examples/actions/workflows/ci.yml)
Sync from tflite-micro | [![Sync from tflite-micro](https://github.com/tensorflow/tflite-micro-arduino-examples/actions/workflows/sync.yml/badge.svg)](https://github.com/tensorflow/tflite-micro-arduino-examples/actions/workflows/sync.yml)
Arduino CLI on Linux | [![Arduino](https://github.com/Gostas/tflite-micro-arduino-examples/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/Gostas/tflite-micro-arduino-examples/actions/workflows/ci.yml)
Sync from tflite-micro | [![Sync from tflite-micro](https://github.com/Gostas/tflite-micro-arduino-examples/actions/workflows/sync.yml/badge.svg)](https://github.com/Gostas/tflite-micro-arduino-examples/actions/workflows/sync.yml)

## How to Install

Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=Arduino_TensorFlowLite
version=6.6.7
version=24.2
author=TensorFlow Authors
maintainer=Pete Warden <petewarden@google.com>
maintainer=Konstantinos Papaspyridis
sentence=Allows you to run machine learning models locally on your device.
paragraph=This library runs TensorFlow machine learning models on microcontrollers, allowing you to build AI/ML applications powered by deep learning and neural networks. With the included examples, you can recognize speech, detect people using a camera, and recognise "magic wand" gestures using an accelerometer. The examples work best with the Arduino Nano 33 BLE Sense board, which has a microphone and accelerometer.
category=Data Processing
Expand Down
5 changes: 2 additions & 3 deletions scripts/MANIFEST.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ files =
src/tensorflow/lite/micro/system_setup.h
src/tensorflow/lite/micro/debug_log.cpp
src/tensorflow/lite/micro/micro_time.cpp
src/tensorflow/lite/micro/micro_string.cpp
src/tensorflow/lite/micro/micro_string.h
src/LICENSE
examples/
src/test_over_serial/
src/peripherals/
src/tensorflow/lite/micro/tools/make/
third_party/cmsis/

#
# Required section.
Expand Down Expand Up @@ -109,7 +109,6 @@ sed_scripts =
#
[patch TF_LITE_STATIC_MEMORY]
files =
src/tensorflow/lite/c/common.cpp
src/tensorflow/lite/c/common.h
src/tensorflow/lite/core/api/flatbuffer_conversions.cpp
src/tensorflow/lite/kernels/internal/compatibility.h
Expand Down
16 changes: 10 additions & 6 deletions scripts/sync_from_tflite_micro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@ cd tflite-micro

make -f tensorflow/lite/micro/tools/make/Makefile clean_downloads

"${SCRIPT_DIR}"/install_arduino_cli.sh

BASE_DIR="${TEMP_DIR}/tflm_tree"
OUTPUT_DIR="${TEMP_DIR}/Arduino_TensorFlowLite"
TARGET=cortex_m_generic
OPTIMIZED_KERNEL_DIR=cmsis_nn
TARGET_ARCH=cortex-m4+sfp
CMSIS_PATH="${HOME}/.arduino15/packages/arduino/hardware/mbed_nano/4.1.1/cores/arduino/mbed/cmsis/CMSIS_5"
TARGET_ARCH=project_generation

# Create the TFLM base tree
python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
-e hello_world -e micro_speech -e person_detection \
--makefile_options="TARGET=${TARGET} OPTIMIZED_KERNEL_DIR=${OPTIMIZED_KERNEL_DIR} TARGET_ARCH=${TARGET_ARCH}" \
"${BASE_DIR}"
--makefile_options="TARGET=${TARGET} OPTIMIZED_KERNEL_DIR=${OPTIMIZED_KERNEL_DIR} TARGET_ARCH=${TARGET_ARCH}" "${BASE_DIR}"

echo create_tflm_tree.py done
#read

# Need the mbed core
"${SCRIPT_DIR}"/install_arduino_cli.sh
# Replace downloaded CMSIS lib with the one Arduino uses
cp -a "${HOME}/.arduino15/packages/arduino/hardware/mbed_nano/4.1.1/cores/arduino/mbed/cmsis/CMSIS_5/CMSIS/" ${BASE_DIR}/third_party/cmsis
mv ${BASE_DIR}/third_party/cmsis/CMSIS/TARGET_CORTEX_M ${BASE_DIR}/third_party/cmsis/CMSIS/Core
rm -rf ${BASE_DIR}/third_party/cmsis//CMSIS/TARGET* ${BASE_DIR}/third_party/cmsis/CMSIS/RTOS2


# Create the final tree in ${OUTPUT_DIR} using the base tree in ${BASE_DIR}
# The create_tflm_arduino.py script takes care of cleaning ${OUTPUT_DIR}
cd "${ROOT_DIR}"
Expand Down
14 changes: 7 additions & 7 deletions scripts/test_arduino_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ mkdir -p ${TEMP_BUILD_DIR}

cp -a ${LIBRARY_DIR} "${ARDUINO_LIBRARIES_DIR}"

# build static library
make -f ${LIBRARY_DIR}/src/tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_generic TARGET_ARCH=cortex-m4+sfp OPTIMIZED_KERNEL_DIR=cmsis_nn microlite
mkdir ${LIBRARY_DIR}/src/cortex-m4
mkdir ${LIBRARY_DIR}/src/cortex-m4/fpv4-sp-d16-softfp
mv "/tmp/gen/cortex_m_generic_cortex-m4+sfp_default/lib/libtensorflow-microlite.a" "${LIBRARY_DIR}/cortex-m4/fpv4-sp-d16-softfp"
# build static library -- comment out as it's not working currently
# make -f ${LIBRARY_DIR}/src/tensorflow/lite/micro/tools/make/Makefile TENSORFLOW_ROOT="${LIBRARY_DIR}/src/" microlite
# mkdir ${LIBRARY_DIR}/src/cortex-m4
# mkdir ${LIBRARY_DIR}/src/cortex-m4/fpv4-sp-d16-softfp
# mv "/tmp/gen/cortex_m_generic_cortex-m4+sfp_default/lib/libtensorflow-microlite.a" "${LIBRARY_DIR}/src/cortex-m4/fpv4-sp-d16-softfp"

# Installs all dependencies for Arduino
InstallLibraryDependencies () {
Expand All @@ -64,8 +64,8 @@ ino_files+=(${LIBRARY_DIR}/src/peripherals/tests/test_*/*.ino)
for f in "${ino_files[@]}"; do
echo "Compiling $(basename ${f} .ino)"
${ARDUINO_CLI_TOOL} compile --library ${LIBRARY_DIR} --build-cache-path ${TEMP_BUILD_DIR} \
--build-path ${TEMP_BUILD_DIR} -b arduino:mbed_nano:nano33ble "$f" -e -v &> logs.txt
echo Done. Press enter to continue
--build-path ${TEMP_BUILD_DIR} -b arduino:mbed_nano:nano33ble "$f"
#echo Done. Press enter to continue
#read
done

Expand Down
14 changes: 9 additions & 5 deletions scripts/test_tflm_arduino.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ cd tflite-micro

readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean_downloads

readable_run "${SCRIPT_DIR}"/install_arduino_cli.sh

BASE_DIR=/tmp/tflm_tree
OUTPUT_DIR=/tmp/tflm_arduino
TARGET=cortex_m_generic
OPTIMIZED_KERNEL_DIR=cmsis_nn
TARGET_ARCH=cortex-m4+sfp
CMSIS_PATH="${HOME}/.arduino15/packages/arduino/hardware/mbed_nano/4.1.1/cores/arduino/mbed/cmsis/CMSIS_5"

readable_run python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
-e hello_world -e micro_speech -e person_detection \
--makefile_options="TARGET=${TARGET} OPTIMIZED_KERNEL_DIR=${OPTIMIZED_KERNEL_DIR} TARGET_ARCH=${TARGET_ARCH} CMSIS_PATH=${CMSIS_PATH}" \
"${BASE_DIR}"
--makefile_options="TARGET=${TARGET} OPTIMIZED_KERNEL_DIR=${OPTIMIZED_KERNEL_DIR} TARGET_ARCH=${TARGET_ARCH}" "${BASE_DIR}"


# Need the mbed core
# readable_run "${SCRIPT_DIR}"/install_arduino_cli.sh
# Replace downloaded CMSIS lib with the one Arduino uses
# cp -r "${HOME}/.arduino15/packages/arduino/hardware/mbed_nano/4.1.1/cores/arduino/mbed/cmsis/CMSIS_5/CMSIS/" ${BASE_DIR}/third_party/cmsis
# mv ${BASE_DIR}/third_party/cmsis/CMSIS/TARGET_CORTEX_M ${BASE_DIR}/third_party/cmsis/CMSIS/Core
# rm -rf ${BASE_DIR}/third_party/cmsis//CMSIS/TARGET* ${BASE_DIR}/third_party/cmsis/CMSIS/RTOS2

cd "${ROOT_DIR}"

Expand Down
Loading
0