Skip to content

Commit

Permalink
MLTK version 0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
silabsbot committed Apr 2, 2024
1 parent 1bd412a commit 5ae4b25
Show file tree
Hide file tree
Showing 639 changed files with 17,389 additions and 9,309 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ __pycache__
/build
.pytest_cache
.vscode
!.vscode/c_cpp_properties.json
!.vscode/cmake-kits.json

*.exe
*.dll
Expand All @@ -26,4 +24,7 @@ __pycache__
*.egg-info
/.eggs
!pyrightconfig.json
~*
~*

!.vscode/c_cpp_properties.json
!.vscode/cmake-kits.json
8 changes: 4 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools",
"intelliSenseMode": "windows-gcc-x64",
"compilerPath": "~/.mltk/tools/toolchains/gcc/windows/8.4.0/mingw64/bin/g++.exe",
"compilerPath": "~/.mltk/tools/toolchains/gcc/windows/13.2.0/mingw64/bin/g++.exe",
"compileCommands": "${workspaceFolder}/build/windows-gcc/Debug/compile_commands.json"
},
{
Expand All @@ -21,7 +21,7 @@
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools",
"intelliSenseMode": "windows-gcc-x64",
"compilerPath": "~/.mltk/tools/toolchains/gcc/windows/8.4.0/mingw64/bin/g++.exe",
"compilerPath": "~/.mltk/tools/toolchains/gcc/windows/13.2.0/mingw64/bin/g++.exe",
"compileCommands": "${workspaceFolder}/build/windows-gcc/Release/compile_commands.json"
},
{
Expand All @@ -45,7 +45,7 @@
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools",
"intelliSenseMode": "gcc-arm",
"compilerPath": "~/.mltk/tools/toolchains/gcc/arm/2021.10/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++.exe",
"compilerPath": "~/.mltk/tools/toolchains/gcc/arm/13.2/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin/arm-none-eabi-g++.exe",
"compileCommands": "${workspaceFolder}/build/arm-gcc/Debug/compile_commands.json"
},
{
Expand All @@ -57,7 +57,7 @@
"cppStandard": "c++17",
"configurationProvider": "ms-vscode.cmake-tools",
"intelliSenseMode": "gcc-arm",
"compilerPath": "~/.mltk/tools/toolchains/gcc/arm/2021.10/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++.exe",
"compilerPath": "~/.mltk/tools/toolchains/gcc/arm/13.2/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin/arm-none-eabi-g++.exe",
"compileCommands": "${workspaceFolder}/build/arm-gcc/Release/compile_commands.json"
}
],
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ This package is made available as a self-serve reference supported only by the o
There are no Silicon Labs support services for this software at this time.
```

<a href="https://siliconlabs.github.io/mltk" target="_blank">![version](https://img.shields.io/badge/MLTK%20Version-0.19.0-red?style=for-the-badge)</a>
<a href="https://siliconlabs.github.io/mltk" target="_blank">![version](https://img.shields.io/badge/MLTK%20Version-0.20.0-red?style=for-the-badge)</a>
<a href="https://pypi.org/project/silabs-mltk" target="_blank">![PyPI - Python Version](https://img.shields.io/pypi/pyversions/silabs-mltk?style=for-the-badge)</a>
<a href="https://github.com/SiliconLabs/gecko_sdk/tree/v4.3.0" target="_blank">![gsdk](https://img.shields.io/badge/Gecko%20SDK-4.3.0-green?style=for-the-badge)</a>
<a href="https://github.com/tensorflow/tflite-micro/tree/9bc9deab8db4d24dcca4070c8153e7d7b5d28770" target="_blank">![tflm](https://img.shields.io/badge/Tensorflow--Lite%20Micro-June%202023-orange?style=for-the-badge)</a>
<a href="https://www.tensorflow.org/api_docs" target="_blank">![tf](https://img.shields.io/badge/Tensorflow-2.13-yellow?style=for-the-badge)</a>
<a href="https://github.com/SiliconLabs/gecko_sdk/tree/v4.3.3" target="_blank">![gsdk](https://img.shields.io/badge/Gecko%20SDK-4.3.3-green?style=for-the-badge)</a>
<a href="https://github.com/tensorflow/tflite-micro/tree/7005d60ede074762f01c1d0fd24ec58240af89b5" target="_blank">![tflm](https://img.shields.io/badge/Tensorflow--Lite%20Micro-March%202024-orange?style=for-the-badge)</a>
<a href="https://www.tensorflow.org/api_docs" target="_blank">![tf](https://img.shields.io/badge/Tensorflow-2.16-yellow?style=for-the-badge)</a>

This is a Python package with command-line utilities and scripts to aid the development
of machine learning models for Silicon Lab's embedded platforms.
Expand Down
7 changes: 4 additions & 3 deletions cpp/audio_feature_generator_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging

from mltk import cli, MLTK_ROOT_DIR
from mltk.utils.cmake import build_mltk_target

from mltk import MLTK_ROOT_DIR


def build_audio_feature_generator_wrapper(
Expand All @@ -13,6 +11,9 @@ def build_audio_feature_generator_wrapper(
debug:bool=False,
):
"""Build the AudioFeatureGenerator Python wrapper for the current OS/Python environment"""
# This must be import here in case the CMake package is installed during setup
from mltk.utils.cmake import build_mltk_target

logger = logger or logging.getLogger()

build_mltk_target(
Expand Down
4 changes: 2 additions & 2 deletions cpp/mltk.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
id=uc.extension.mltk
label=Machine Learning Toolkit
description=Machine Learning Toolkit
version=0.19.0
dependantSdkVersion=4.3.0
version=0.20.0
dependantSdkVersion=4.3.3
prop.file.templatesFile=shared/gecko_sdk/simplicity_studio/apps.xml
4 changes: 2 additions & 2 deletions cpp/mltk.slce
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ id: mltk
label: Machine Learning Toolkit
description: >
Machine Learning Toolkit extension for Gecko SDK Suite
version: "0.19.0"
version: "0.20.0"
sdk:
id: gecko_sdk
version: "4.3.0"
version: "4.3.3"
component_path:
- path: shared/gecko_sdk/simplicity_studio
11 changes: 10 additions & 1 deletion cpp/mvp_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if(HOST_OS_IS_WINDOWS)
else()
target_link_options(${MODULE_NAME}
PUBLIC
-static-libgcc -static-libstdc++ -pthread
-static-libgcc -pthread
)
endif()

Expand All @@ -85,6 +85,15 @@ endif()
set(mvp_accelerator_dir "${TFLITE_MICRO_WRAPPER_ACCELERATORS_DIR}/mvp")
tflite_micro_link_python_wrapper(${MODULE_NAME} ${mvp_accelerator_dir})

if(HOST_OS_IS_WINDOWS)
# This is required by the stacktrace component for Windows
# We link it here to work-around potential runtime DLL import errors
# NOTE: This must come AFTER the tflite_micro_link_python_wrapper() call above
target_link_libraries(${MODULE_NAME}
PUBLIC
imagehlp
)
endif()

target_compile_features(${MODULE_NAME}
PUBLIC
Expand Down
4 changes: 3 additions & 1 deletion cpp/mvp_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from mltk import MLTK_ROOT_DIR
from mltk.utils.cmake import build_mltk_target


def build_mvp_wrapper(
Expand All @@ -12,6 +11,9 @@ def build_mvp_wrapper(
debug:bool=False,
):
"""Build the MVP kernels + simulator Python wrapper for the current OS/Python environment"""

# This must be import here in case the CMake package is installed during setup
from mltk.utils.cmake import build_mltk_target
logger = logger or logging.getLogger()

build_mltk_target(
Expand Down
3 changes: 1 addition & 2 deletions cpp/mvp_wrapper/mvp_tflite_micro_accelerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class MvpTfliteMicroAcceleratorWrapper : public TfliteMicroAcceleratorWrapper
tflite::MicroOpResolver* load() override
{
get_logger().debug("Loading MVP accelerator");
mltk_tflite_micro_register_accelerator();
this->accelerator = mltk_tflite_micro_get_registered_accelerator();
this->accelerator = mltk_tflite_micro_register_accelerator();
return &mvp_ops_resolver;
}
};
Expand Down
34 changes: 17 additions & 17 deletions cpp/mvp_wrapper/mvp_wrapper_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ extern "C" void sli_mvp_set_simulator_backend_enabled(bool);
namespace mltk
{
extern bool mvpv1_calculate_accelerator_cycles_only;
extern "C" const TfliteMicroAccelerator* mltk_tflite_micro_get_accelerator();
extern "C" TfliteMicroAccelerator* mltk_tflite_micro_get_accelerator();
}


PYBIND11_MODULE(MODULE_NAME, m)
PYBIND11_MODULE(MODULE_NAME, m)
{

/*************************************************************************************************
* API version number of the wrapper
*
* API version number of the wrapper
*
* Any other wrappers that link to this wrapper should check
* this version to ensure compatibility
*/
m.def("name", []() -> const char*
{
auto acc = mltk::mltk_tflite_micro_get_accelerator();
return acc->name;
return acc->name();
});

/*************************************************************************************************
* API version number of the wrapper
*
* API version number of the wrapper
*
* Any other wrappers that link to this wrapper should check
* this version to ensure compatibility
*/
Expand All @@ -48,7 +48,7 @@ PYBIND11_MODULE(MODULE_NAME, m)

/*************************************************************************************************
* GIT hash of the MLTK repo when the DLL was compiled
*
*
*/
m.def("git_hash", []() -> const char*
{
Expand All @@ -57,7 +57,7 @@ PYBIND11_MODULE(MODULE_NAME, m)

/*************************************************************************************************
* Return the MvpTfliteMicroAcceleratorWrapper
*
*
*/
m.def("get_accelerator_wrapper", []() -> void*
{
Expand All @@ -67,7 +67,7 @@ PYBIND11_MODULE(MODULE_NAME, m)
/*************************************************************************************************
* Enable/disabe the simulator backend.
* This is used internally
*
*
*/
m.def("set_simulator_backend_enabled", [](bool enabled) -> void
{
Expand All @@ -77,28 +77,28 @@ PYBIND11_MODULE(MODULE_NAME, m)
/*************************************************************************************************
* Enable/disabe only calculating accelerator cycles during simulation
* This is used internally
*
*
*/
m.def("set_calculate_accelerator_cycles_only_enabled", [](bool enabled) -> void
{
mltk::mvpv1_calculate_accelerator_cycles_only = enabled;
});

/*************************************************************************************************
* Enable recording hardware accelerator instructions
*
*
*/
m.def("enable_program_recorder", []() -> void
m.def("set_program_recorder_enabled", [](bool enabled) -> void
{
mltk::TfliteMicroAcceleratorRecorder::instance().set_program_recording_enabled();
mltk::TfliteMicroAcceleratorRecorder::set_program_recording_enabled(enabled);
});

/*************************************************************************************************
* Enable recording hardware accelerator data
*
*
*/
m.def("enable_data_recorder", []() -> void
{
mltk::TfliteMicroAcceleratorRecorder::instance().set_data_recording_enabled();
mltk::TfliteMicroAcceleratorRecorder::set_enabled(true);
});
}
29 changes: 14 additions & 15 deletions cpp/shared/apps/audio_classifier/audio_classifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "cli_opts.hpp"
#include "audio_io.h"

#include "mltk_audio_classifier_model_generated.hpp"


#ifdef SL_CATALOG_KERNEL_PRESENT
Expand All @@ -52,7 +52,6 @@ static sl_sleeptimer_timer_handle_t inference_timer;
#error "Sample application requires two leds"
#endif

static tflite::AllOpsResolver op_resolver;
static RecognizeCommands *command_recognizer = nullptr;
static mltk::TfliteMicroModel model;

Expand All @@ -67,10 +66,6 @@ int category_count = 0;
static mltk::StringList category_labels;
static int category_label_count;

// This is defined by the build scripts
// which converts the specified .tflite to a C array
extern "C" const uint8_t sl_tflite_model_array[];



static void handle_results(int32_t current_time, int result, uint8_t score, bool is_new_command);
Expand All @@ -84,21 +79,25 @@ static sl_status_t process_output(const bool did_run_inference);
******************************************************************************/
void audio_classifier_init(void)
{
#ifdef SL_TFLITE_MICRO_OPCODE_RESOLVER
SL_TFLITE_MICRO_OPCODE_RESOLVER(mltk_model_op_resolver);
#endif

sl_status_t status;

printf("Audio Classifier\n");

#ifdef __arm__
#ifdef __arm__
// First check if a new .tflite was programmed to the end of flash
// (This will happen when this app is executed from the command-line: "mltk classify_audio my_model --device")
if(!mltk::get_tflite_flatbuffer_from_end_of_flash(&cli_opts.model_flatbuffer))
if(!mltk::TfliteMicroModelHelper::get_tflite_flatbuffer_from_end_of_flash(&cli_opts.model_flatbuffer))
{
// If no .tflite was programmed, then just use the default model
printf("Using default model built into application\n");
cli_opts.model_flatbuffer = sl_tflite_model_array;
cli_opts.model_flatbuffer = mltk_model_flatbuffer;
}

#else // If this is a Windows/Linux build
#else // If this is a Windows/Linux build
// Parse the CLI options
parse_cli_opts();

Expand All @@ -107,16 +106,16 @@ void audio_classifier_init(void)
if(cli_opts.model_flatbuffer == nullptr)
{
printf("Using default model built into application\n");
cli_opts.model_flatbuffer = sl_tflite_model_array;
cli_opts.model_flatbuffer = mltk_model_flatbuffer;
}
#endif // ifdef __arm__
#endif // ifdef __arm__


// Register the accelerator if the TFLM lib was built with one
mltk::mltk_tflite_micro_register_accelerator();

// Attempt to load the model using the arena size specified in the .tflite
if(!model.load(cli_opts.model_flatbuffer, op_resolver))
if(!model.load(cli_opts.model_flatbuffer, mltk_model_op_resolver))
{
printf("ERROR: Failed to load .tflite model\n");
while(1)
Expand Down Expand Up @@ -153,14 +152,14 @@ void audio_classifier_init(void)
;
}

#ifdef AUDIO_IO_ENABLED
#ifdef AUDIO_IO_ENABLED
if(!audio_io_init())
{
printf("ERROR: Failed to init audio I/O\n");
while(1)
;
}
#endif
#endif

// Instantiate CommandRecognizer
static RecognizeCommands static_recognizer(SMOOTHING_WINDOW_DURATION_MS,
Expand Down
1 change: 1 addition & 0 deletions cpp/shared/apps/audio_classifier/config/tflite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is only used by the Simplicity Studio Project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "sl_tflite_micro_opcode_resolver.h"
#include "sl_tflite_micro_model.h"

const auto mltk_model_flatbuffer = sl_tflite_model_array;
5 changes: 4 additions & 1 deletion cpp/shared/apps/audio_classifier/mltk_audio_classifier.slcp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ quality: development
# value: ["Machine Learning"]
sdk_extension:
- id: mltk
version: "0.19.0"
version: "0.20.0"
include:
- path: .
file_list:
Expand All @@ -29,6 +29,9 @@ include:
- path: cli_opts.hpp
- path: recognize_commands.h
- path: audio_io.h
- path: config/tflite
file_list:
- path: mltk_audio_classifier_model_generated.hpp
source:
- path: main.c
- path: app.c
Expand Down
Loading

0 comments on commit 5ae4b25

Please sign in to comment.