8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 |
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/gradle/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/armnn-style-transfer-android/gradle/.DS_Store
--------------------------------------------------------------------------------
/armnn-style-transfer-android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/armnn-style-transfer-android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/armnn-style-transfer-android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Nov 11 08:35:34 PST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Sun Nov 10 15:24:42 PST 2019
8 | sdk.dir=/Users/weixia02/Library/Android/sdk
9 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/armnn-style-transfer-android/styletransferapp.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/.ci/README.md:
--------------------------------------------------------------------------------
1 | # Continuous Integration (CI) Tests for CMSIS-Pack based Machine Learning Examples
2 |
3 |
4 | Content of `.ci` Directory | Description
5 | :----------------------------|:-----------------
6 | `vcpkg-configuration.json` | Tool setup for the CI test.
7 |
8 |
9 | ## GitHub Action Workflows
10 |
11 | The [GitHub Actions](https://docs.github.com/en/actions) in the directory `.github/workflows` are the scripts for the CI tests. These scripts contain detailed comments about each step that is executed.
12 |
13 | These examples use the [Arm® Compiler for Embedded](https://developer.arm.com/Tools%20and%20Software/Arm%20Compiler%20for%20Embedded) (AC6) toolchain. As such all workflows are using this compiler.
14 |
15 | - `AVH-FVP-CI.yml` implements the *AVH build and execution test* that runs on [Arm Virtual Hardware - Fixed Virtual Platforms (AVH FVP)](https://arm-software.github.io/AVH/main/simulation/html/index.html) simulation models. The directory `FVP` contains configuration files for the FVP simulation models.
16 |
17 | - `Hardware-CI.yml` implmentes the *Hardware build test* that runs on evaluation boards. The output of this build test is stored as artifacts and can be downloaded to the evaluation board for execution.
18 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/.ci/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "registries": [
3 | {
4 | "name": "arm",
5 | "kind": "artifact",
6 | "location": "https://artifacts.tools.arm.com/vcpkg-registry"
7 | }
8 | ],
9 | "requires": {
10 | "arm:tools/open-cmsis-pack/cmsis-toolbox": "^2.4.0",
11 | "arm:tools/kitware/cmake": "^3.28.4",
12 | "arm:tools/ninja-build/ninja": "^1.12.0",
13 | "arm:compilers/arm/armclang": "^6.22.0",
14 | "arm:models/arm/avh-fvp": "^11.27.31"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/.clang-format:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2022 Arm Limited. All rights reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the License); you may
7 | # not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | ---
19 | Language: Cpp
20 | BasedOnStyle: LLVM
21 | IndentWidth: 4
22 | ColumnLimit: 100
23 | AccessModifierOffset: -4
24 | PointerAlignment: Left
25 | AlignAfterOpenBracket: Align
26 | AlignConsecutiveAssignments: true
27 | AlignConsecutiveMacros: true
28 | AlignEscapedNewlines: Left
29 | AlignTrailingComments: true
30 | AllowAllParametersOfDeclarationOnNextLine: true
31 | AllowShortFunctionsOnASingleLine: Empty
32 | AllowShortBlocksOnASingleLine: true
33 | AlwaysBreakTemplateDeclarations: true
34 | BinPackArguments: false
35 | BinPackParameters: false
36 | BreakInheritanceList: AfterColon
37 | BreakConstructorInitializers: AfterColon
38 | BreakBeforeBraces: Custom
39 | BraceWrapping:
40 | AfterClass: false
41 | AfterControlStatement: false
42 | AfterEnum: false
43 | AfterFunction: true
44 | AfterNamespace: false
45 | AfterObjCDeclaration: false
46 | AfterStruct: false
47 | AfterUnion: false
48 | AfterExternBlock: false
49 | BeforeCatch: false
50 | BeforeElse: false
51 | IndentBraces: false
52 | SplitEmptyFunction: false
53 | SplitEmptyRecord: false
54 | SplitEmptyNamespace: true
55 | NamespaceIndentation: Inner
56 | ---
57 |
58 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/.github/workflows/Hardware-CI.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | name: Hardware build test
18 | on:
19 | workflow_dispatch:
20 | pull_request:
21 | branches: [main]
22 | push:
23 | branches: [main]
24 | schedule:
25 | - cron: '00 20 * * 6'
26 |
27 | jobs:
28 | HW:
29 | strategy:
30 |
31 | matrix:
32 | target: [
33 | {proj: kws, board: FRDM-K64F},
34 | {proj: kws, board: STM32F746-DISCO}
35 | # {proj: kws, board: Alif-E7-M55-HP},
36 | # {proj: object-detection, board: Alif-E7-M55-HP}
37 | ]
38 |
39 | fail-fast: false
40 |
41 | runs-on: ubuntu-latest
42 |
43 | steps:
44 | - name: Checkout repo
45 | uses: actions/checkout@v4
46 |
47 | - name: Install tools
48 | uses: ARM-software/cmsis-actions/vcpkg@v1
49 | with:
50 | config: ".ci/vcpkg-configuration.json"
51 |
52 | - name: Activate Arm tool license
53 | uses: ARM-software/cmsis-actions/armlm@v1
54 |
55 | - name: Build project ${{ matrix.target.proj }} for target ${{ matrix.target.board }} with AC6
56 | run: |
57 | cbuild mlek.csolution.yml --update-rte --packs --context ${{ matrix.target.proj }}+${{ matrix.target.board }}
58 |
59 | - name: Upload build Artifact
60 | if: always()
61 | uses: actions/upload-artifact@v4
62 | with:
63 | name: ${{ matrix.target.proj }}_${{ matrix.target.board }}_AC6
64 | path: |
65 | ./out/${{ matrix.target.proj }}/${{ matrix.target.board }}/
66 | retention-days: 1
--------------------------------------------------------------------------------
/cmsis-pack-examples/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // SPDX-FileCopyrightText: Copyright (c) 2022-2023 Arm Limited and/or its
3 | // affiliates
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 |
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | // See https://go.microsoft.com/fwlink/?LinkId=733558
19 | // for the documentation about the tasks.json format
20 |
21 | // Use IntelliSense to learn about possible attributes.
22 | // Hover to view descriptions of existing attributes.
23 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
24 | "version": "0.2.0",
25 | "configurations": [
26 | {
27 | "name": "Embedded Debug",
28 | "type": "embedded-debug",
29 | "request": "launch",
30 | "serialNumber": "${command:device-manager.getSerialNumber}",
31 | "program": "${command:cmsis-csolution.getBinaryFile}",
32 | "cmsisPack": "${command:device-manager.getDevicePack}",
33 | "debugFrom": "main"
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/cmsis-pack-examples/cdefault.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2023-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/cdefault.schema.json
18 |
19 | default:
20 |
21 | misc:
22 | # Note that we need AC6@6.18 or higher to compile for Arm Cortex-M85 based targets.
23 | - for-compiler: AC6
24 | CPP:
25 | - -std=c++17
26 | - -fno-exceptions
27 | - -fno-rtti
28 | - -ffp-mode=full
29 | - -Wno-license-management
30 | C:
31 | - -std=c17
32 | - -Wno-license-management
33 | Link:
34 | - --entry=Reset_Handler
35 | - --verbose
36 | - --callgraph_file='callgraph'
37 | - --map
38 | - --info=sizes,totals,unused,compression,inline,summarysizes
39 | - --list='diagnostics.map'
40 | - --diag_suppress=L6439W,L6314W,L9931W
41 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/common/common.clayer.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/clayer.schema.json
18 |
19 | layer:
20 |
21 | description: Common files and platform-agnostic components for examples based on Arm ML Embedded evaluation kit.
22 |
23 |
24 | groups:
25 | - group: Common
26 | files:
27 | - file: include/BufAttributes.hpp
28 | - file: include/ethosu_mem_config.h
29 |
30 | components:
31 | - component: ARM::CMSIS:CORE
32 | - component: ARM::CMSIS:DSP&Source
33 | - component: ARM::CMSIS:NN Lib
34 | - component: tensorflow::Data Exchange:Serialization:flatbuffers
35 | - component: tensorflow::Data Processing:Math:gemmlowp fixed-point
36 | - component: tensorflow::Data Processing:Math:kissfft
37 | - component: tensorflow::Data Processing:Math:ruy
38 | - component: tensorflow::Machine Learning:TensorFlow:Kernel Utils
39 | - component: tensorflow::Machine Learning:TensorFlow:Testing
40 | - component: ARM::ML Eval Kit:Common:API
41 | - component: ARM::ML Eval Kit:Common:Log
42 | - component: ARM::ML Eval Kit:Common:Math
43 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/common/include/BufAttributes.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BUF_ATTRIBUTES_HPP
20 | #define BUF_ATTRIBUTES_HPP
21 |
22 | #if defined(ETHOSU55) || defined(ETHOSU65) || defined(ETHOSU85)
23 | #define ARM_NPU
24 | #endif /* defined(ETHOSU55) || defined(ETHOSU65) || defined(ETHOSU85) */
25 |
26 | #if defined(ARM_NPU)
27 | /* When Arm NPU is defined, we use the config set by NPU mem parameters */
28 | #include "ethosu_mem_config.h"
29 | #define BYTE_ALIGNMENT ETHOS_U_MEM_BYTE_ALIGNMENT
30 | #else /* defined(ARM_NPU) */
31 | /* otherwise, we use the default ones here. */
32 | #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
33 | #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
34 | #define BYTE_ALIGNMENT 16
35 | #endif /* defined(ARM_NPU) */
36 |
37 | #ifdef __has_attribute
38 | #define HAVE_ATTRIBUTE(x) __has_attribute(x)
39 | #else /* __has_attribute */
40 | #define HAVE_ATTRIBUTE(x) 0
41 | #endif /* __has_attribute */
42 |
43 | #if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
44 |
45 | /* We want all buffers/sections to be aligned to 16 byte. */
46 | #define ALIGNMENT_REQ aligned(BYTE_ALIGNMENT)
47 |
48 | #define MODEL_SECTION section("nn_model")
49 |
50 | /* Label section name */
51 | #define LABEL_SECTION section("labels")
52 |
53 | #ifndef ACTIVATION_BUF_SZ
54 | #warning "ACTIVATION_BUF_SZ needs to be defined. Using default value"
55 | #define ACTIVATION_BUF_SZ 0x00200000
56 | #endif /* ACTIVATION_BUF_SZ */
57 |
58 | /* IFM section name. */
59 | #define IFM_BUF_SECTION section("ifm")
60 |
61 | /* Form the attributes, alignment is mandatory. */
62 | #define MAKE_ATTRIBUTE(x) __attribute__((ALIGNMENT_REQ, x))
63 | #define MODEL_TFLITE_ATTRIBUTE MAKE_ATTRIBUTE(MODEL_SECTION)
64 | #define ACTIVATION_BUF_ATTRIBUTE MAKE_ATTRIBUTE(ACTIVATION_BUF_SECTION)
65 | #define IFM_BUF_ATTRIBUTE MAKE_ATTRIBUTE(IFM_BUF_SECTION)
66 | #define LABELS_ATTRIBUTE MAKE_ATTRIBUTE(LABEL_SECTION)
67 |
68 | #else /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
69 |
70 | #define MODEL_TFLITE_ATTRIBUTE
71 | #define ACTIVATION_BUF_ATTRIBUTE
72 | #define IFM_BUF_ATTRIBUTE
73 | #define LABELS_ATTRIBUTE
74 |
75 | #endif /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
76 |
77 | #endif /* BUF_ATTRIBUTES_HPP */
78 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/common/include/ethosu_mem_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, 2024 Arm Limited. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #ifndef ETHOS_U_NPU_MEM_CONFIG_H
19 | #define ETHOS_U_NPU_MEM_CONFIG_H
20 |
21 | #define ETHOS_U_NPU_MEMORY_MODE_SRAM_ONLY 0
22 | #define ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM 1
23 | #define ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM 2
24 |
25 | #define ETHOS_U_MEM_BYTE_ALIGNMENT 16
26 |
27 | #ifndef ETHOS_U_NPU_MEMORY_MODE
28 | #if defined(ETHOSU65) || defined(ETHOSU85)
29 | #define ETHOS_U_NPU_MEMORY_MODE ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM
30 | #else
31 | #define ETHOS_U_NPU_MEMORY_MODE ETHOS_U_MEMORY_MODE_SHARED_SRAM
32 | #endif /* defined (ETHOSU65) || defined(ETHOSU85) */
33 | #endif /* ETHOS_U_NPU_MEMORY_MODE */
34 |
35 | #if (ETHOS_U_NPU_MEMORY_MODE == ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM)
36 | #ifndef ETHOS_U_NPU_CACHE_SIZE
37 | #define ETHOS_U_CACHE_BUF_SZ (393216U) /* See vela doc for reference */
38 | #else
39 | #define ETHOS_U_CACHE_BUF_SZ ETHOS_U_NPU_CACHE_SIZE
40 | #endif /* ETHOS_U_NPU_CACHE_SIZE */
41 | #else
42 | #define ETHOS_U_CACHE_BUF_SZ (0U)
43 | #endif /* CACHE_BUF_SZ */
44 |
45 | /**
46 | * Activation buffer aka tensor arena section name
47 | * We have to place the tensor arena in different region based on the memory config.
48 | **/
49 | #if (ETHOS_U_NPU_MEMORY_MODE == ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM)
50 | #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
51 | #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
52 | #elif (ETHOS_U_NPU_MEMORY_MODE == ETHOS_U_NPU_MEMORY_MODE_SRAM_ONLY)
53 | #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
54 | #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
55 | #elif (ETHOS_U_NPU_MEMORY_MODE == ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM)
56 | #define ACTIVATION_BUF_SECTION section("activation_buf_dram")
57 | #define CACHE_BUF_SECTION section(".bss.NoInit.ethos_u_cache")
58 | #define ACTIVATION_BUF_SECTION_NAME ("DDR/DRAM")
59 | #define CACHE_BUF_ATTRIBUTE __attribute__((aligned(ETHOS_U_MEM_BYTE_ALIGNMENT), CACHE_BUF_SECTION))
60 | #endif
61 |
62 | #endif /* ETHOS_U_NPU_MEM_CONFIG_H */
63 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/include/BoardAudioUtils.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BOARD_AUDIO_UTILS_HPP
20 | #define BOARD_AUDIO_UTILS_HPP
21 |
22 | #include
23 | #include
24 |
25 | /**
26 | * @brief Audio buffer descriptor
27 | */
28 | extern "C" typedef struct _audio_buf {
29 | void* data; /**< Pointer to buffer data. */
30 | uint32_t n_elements; /**< Number of elements in this buffer. */
31 | uint32_t n_bytes; /**< Total number of bytes occupied by this buffer. */
32 | } audio_buf;
33 |
34 | /**
35 | * @brief Audio utility class.
36 | */
37 | class AudioUtils {
38 | public:
39 | AudioUtils();
40 | ~AudioUtils();
41 |
42 | /**
43 | * @brief Sets the input volume
44 | * @param[in] vol Volume to be set (value between 0-min and 100-max)
45 | */
46 | void SetVolumeIn(uint8_t vol);
47 |
48 | /**
49 | * @brief Sets the output volume
50 | * @param[in] vol Volume to be set (value between 0-min and 100-max)
51 | */
52 | void SetVolumeOut(uint8_t vol);
53 |
54 | /**
55 | * @brief Initialises the audio input interface.
56 | * @param[in] audioBufferIn Buffer descriptor for the audio interface to use.
57 | * @return True if successful, false otherwise.
58 | */
59 | bool AudioInit(audio_buf* audioBufferIn);
60 |
61 | /**
62 | * @brief Checks if the audio buffer has been populated.
63 | * @return True if buffer is full, false otherwise.
64 | */
65 | bool IsAudioAvailable();
66 |
67 | /**
68 | * @brief Sets the audio buffer as empty - useful to restart populating
69 | * the audio buffer.
70 | */
71 | void SetAudioEmpty();
72 |
73 | /**
74 | * @brief Starts recording the audio stream into the buffer provided at initialisation.
75 | */
76 | void StartAudioRecording();
77 |
78 | /**
79 | * @brief Stops recording the audio stream.
80 | */
81 | void StopAudioRecording();
82 |
83 | /**
84 | * @brief Gets if the recorded audio is stereo
85 | */
86 | bool IsStereo() const;
87 | };
88 |
89 | #endif /* BOARD_AUDIO_UTILS_HPP */
90 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/include/BoardInit.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BOARD_INIT_HPP
20 | #define BOARD_INIT_HPP
21 |
22 | /**
23 | * @brief Board initialisation - sets up all peripherals required.
24 | */
25 | void BoardInit(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/include/BoardPlotUtils.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | #ifndef PLOT_UTILS_HPP
19 | #define PLOT_UTILS_HPP
20 |
21 | #include
22 | #include
23 |
24 | /** Class for plotting/displaying to the on-board LCD on Alif Ensemble Boards */
25 | class PlotUtils {
26 |
27 | public:
28 | /**
29 | * Constructors and destructors
30 | */
31 | PlotUtils();
32 | ~PlotUtils() = default;
33 |
34 | /**
35 | * @brief Clears the LCD
36 | */
37 | void ClearAll();
38 |
39 | /**
40 | * @brief Clears the string at a specific line
41 | * @param[in] line Line number for the string be be cleared at.
42 | * @note line number limits depend on the font being used and the
43 | * vertical span of the LCD. For default font the number
44 | * should be between 0 and 9. For smaller fonts available,
45 | * it could be [0-19] or [0-29].
46 | * @return none
47 | */
48 | void ClearStringLine(int line);
49 |
50 | /**
51 | * @brief Displays the given string at the specified location.
52 | * @param[in] line Line number to display the text at.
53 | * @param[in] text Text to be displayed.
54 | * @note line number limits depend on the font being used and the
55 | * vertical span of the LCD. For default font the number
56 | * should be between 0 and 9. For smaller fonts available,
57 | * it could be [0-19] or [0-29].
58 | * @return none
59 | */
60 | void DisplayStringAtLine(uint16_t line, std::string& text);
61 |
62 | /**
63 | * @brief Plots an audio waveform (or any sequence of 16-bit signed integers).
64 | * @param[in] data Pointer to the buffer.
65 | * @param[in] nElements Number of elements in the buffer.
66 | * @return none
67 | */
68 | void PlotWaveform(const int16_t* data, uint32_t nElements);
69 | };
70 |
71 | #endif /* PLOT_UTILS_HPP */
72 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/src/BoardPlotUtils.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | #include "BoardPlotUtils.hpp"
19 |
20 | PlotUtils::PlotUtils()
21 | {}
22 |
23 | void PlotUtils::ClearAll()
24 | {}
25 |
26 | void PlotUtils::ClearStringLine(int line)
27 | {}
28 |
29 | void PlotUtils::DisplayStringAtLine(uint16_t line, std::string& text)
30 | {
31 | (void)line;
32 | (void)text;
33 | }
34 |
35 | void PlotUtils::PlotWaveform(const int16_t* data, uint32_t nElements)
36 | {
37 | (void)data;
38 | (void)nElements;
39 | }
40 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/src/GpioSignal.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "GpioSignal.hpp"
20 |
21 | #include "log_macros.h"
22 |
23 | #include
24 |
25 | namespace arm {
26 | namespace app {
27 |
28 | GpioSignal::GpioSignal(SignalPort port, SignalPin pin, SignalDirection dir) :
29 | m_port(static_cast(port)), m_pin(static_cast(pin)), m_direction(dir)
30 | {
31 | bool isInput = (this->m_direction == SignalDirection::DirectionInput);
32 | gpio_init(this->m_port, this->m_pin, isInput);
33 | }
34 |
35 | void GpioSignal::Send(bool signalValue)
36 | {
37 | if (this->m_direction == SignalDirection::DirectionOutput) {
38 | if (true == gpio_set_pin(this->m_port, this->m_pin, signalValue)) {
39 | debug(
40 | "Sent signal to port %d pin %d: %d\n", this->m_port, this->m_pin, signalValue);
41 | return;
42 | }
43 | }
44 | printf_err("Failed to set port %d pin %d: %d\n", this->m_port, this->m_pin, signalValue);
45 | }
46 |
47 | bool GpioSignal::Recv()
48 | {
49 | if (this->m_direction == SignalDirection::DirectionInput) {
50 | bool signalValue = false;
51 | if (true == gpio_get_pin(this->m_port, this->m_pin, &signalValue)) {
52 | debug(
53 | "Got signal from port %d pin %d: %d\n", this->m_port, this->m_pin, signalValue);
54 | return signalValue;
55 | }
56 | }
57 | printf_err("Failed to get signal from port %d pin %d.\n", this->m_port, this->m_pin);
58 | return false;
59 | }
60 |
61 | bool GpioSignal::WaitForSignal(service_handler handler)
62 | {
63 | if (this->m_direction == SignalDirection::DirectionInput) {
64 | return wait_for_gpio_signal(this->m_port, this->m_pin, handler);
65 | }
66 | return false;
67 | }
68 |
69 | } /* namespace app */
70 | } /* namespace arm */
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/src/gpio_wrapper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | #ifndef PLATFORM_GPIO_H
19 | #define PLATFORM_GPIO_H
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include
26 | #include
27 |
28 | /* A service handler function pointer */
29 | typedef void (*service_handler)(void);
30 |
31 | /**
32 | * @brief Initialise the GPIO port/pin
33 | * @param[in] gpio_port GPIO port number
34 | * @param[in] gpio_pin pin number for the GPIO port
35 | * @param[in] is_input to be set to true to set the GPIO pin direction
36 | * as input. If false, the direction is set as
37 | * output.
38 | */
39 | void gpio_init(uint8_t gpio_port, uint8_t gpio_pin, bool is_input);
40 |
41 | /**
42 | * @brief Set the signal for GPIO port/pin
43 | * @param[in] gpio_port GPIO port number
44 | * @param[in] gpio_pin pin number for the GPIO port
45 | * @param[in] value the signal is driven high if this is set as true,
46 | * driven low otherwise.
47 | * @return true if successful, false otherwise.
48 | */
49 | bool gpio_set_pin(uint8_t gpio_port, uint8_t gpio_pin, bool value);
50 |
51 | /**
52 | * @brief Get the current signal from GPIO port/pin
53 | * @param[in] gpio_port GPIO port number
54 | * @param[in] gpio_pin pin number for the GPIO port
55 | * @param[out] value pointer to bool; set to true if signal is high,
56 | * set to false otherwise.
57 | * @return true if successful, false otherwise.
58 | */
59 | bool gpio_get_pin(uint8_t gpio_port, uint8_t gpio_pin, bool* value);
60 |
61 | /**
62 | * @brief Waits for a GPIO signal to be driven high
63 | * @param[in] gpio_port GPIO port number
64 | * @param[in] gpio_pin pin number for the GPIO port
65 | * @param[in] service a function that needs to be run while
66 | * waiting for the signal. It can be set
67 | * to NULL if unrequired.
68 | * @return true if successful, false otherwise.
69 | */
70 | bool wait_for_gpio_signal(uint8_t gpio_port, uint8_t gpio_pin, service_handler service);
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | #endif /* PLATFORM_GPIO_H */
77 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/alif-ensemble/src/uart_stdout.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | #ifndef UART_STDOUT_H
19 | #define UART_STDOUT_H
20 |
21 | #include
22 | #include
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /**
29 | * @brief Initialised the UART block.
30 | **/
31 | extern int32_t UartStdOutInit(void);
32 |
33 | /**
34 | * @brief Transmits a character over UART (blocking call).
35 | * @param[in] my_ch Character to be transmitted.
36 | * @return Character transmitted.
37 | **/
38 | extern unsigned char UartPutc(unsigned char my_ch);
39 |
40 | /**
41 | * @brief Receives a character from the UART block (blocking call).
42 | * @return Character received.
43 | **/
44 | extern unsigned char UartGetc(void);
45 |
46 | /**
47 | * @brief Receives a character from the UART block (NON blocking call).
48 | * @return Character received, or 0xFF if no character
49 | **/
50 | extern unsigned char UartGetcNoBlock(void);
51 |
52 | /**
53 | * @brief Reads characters from the UART block until a line feed or
54 | * carriage return terminates the function. NULL character
55 | * also terminates the function, error is returned.
56 | * @param[out] lp Characters read from the UART block.
57 | * @param[in] len Character to be transmitted.
58 | * @return true if successful, false otherwise.
59 | **/
60 | extern bool GetLine(char *lp, unsigned int len);
61 |
62 | /**
63 | * @brief Terminates UART simulation. This is useful when a Fixed
64 | * Virtual Platform's session needs to be gracefully terminated.
65 | * @param[in] code Terminating code displayed on the UART before the end of the simulation.
66 | **/
67 | extern void UartEndSimulation(int code);
68 |
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 |
73 | #endif /* UART_STDOUT_H */
74 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/corstone-device.clayer.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/clayer.schema.json
18 |
19 | layer:
20 |
21 | description: Arm Corstone reference package related components and files.
22 |
23 | groups:
24 | - group: Retarget
25 | for-context:
26 | - +AVH-SSE-300
27 | - +AVH-SSE-300-U55
28 | - +AVH-SSE-300-U65
29 | - +AVH-SSE-310
30 | - +AVH-SSE-310-U55
31 | - +AVH-SSE-310-U65
32 | - +AVH-SSE-315
33 | - +AVH-SSE-315-U65
34 | - +AVH-SSE-320
35 | - +AVH-SSE-320-U85
36 |
37 | files:
38 | - file: src/retarget.c
39 | - file: src/uart_cmsdk_apb.c
40 | - file: src/BoardInit.cpp
41 | - file: src/uart_config.h
42 | - file: src/uart_stdout.h
43 | - file: include/BoardInit.hpp
44 |
45 | define:
46 | # For profiling under micro_time.cpp in TensorFlow Lite Micro pack
47 | - ARM_MODEL_USE_PMU_COUNTERS
48 |
49 | components:
50 | - component: ARM::Device:Definition
51 | - component: ARM::Device:Startup&C Startup
52 | - component: ARM::Device:Native Driver:Timeout
53 | - component: ARM::Device:Native Driver:SysCounter
54 | - component: ARM::Device:Native Driver:SysTimer
55 | - component: Arm::Machine Learning:NPU Support:Ethos-U Driver&Generic U55
56 | for-context:
57 | - +AVH-SSE-300-U55
58 | - +AVH-SSE-310-U55
59 | - component: Arm::Machine Learning:NPU Support:Ethos-U Driver&Generic U65
60 | for-context:
61 | - +AVH-SSE-300-U65
62 | - +AVH-SSE-310-U65
63 | - +AVH-SSE-315-U65
64 | - component: Arm::Machine Learning:NPU Support:Ethos-U Driver&Generic U85
65 | for-context:
66 | - +AVH-SSE-320-U85
67 | - component: tensorflow::Machine Learning:TensorFlow:Kernel&Ethos-U
68 | for-context:
69 | - +AVH-SSE-300-U55
70 | - +AVH-SSE-310-U55
71 | - +AVH-SSE-300-U65
72 | - +AVH-SSE-310-U65
73 | - +AVH-SSE-315-U65
74 | - +AVH-SSE-320-U85
75 | - component: tensorflow::Machine Learning:TensorFlow:Kernel&CMSIS-NN
76 | for-context:
77 | - +AVH-SSE-300
78 | - +AVH-SSE-310
79 | - +AVH-SSE-315
80 | - +AVH-SSE-320
81 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/fvp-configs/mps3_fvp_config.txt:
--------------------------------------------------------------------------------
1 | # Parameters:
2 | # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max]
3 | #---------------------------------------------------------------------------------------------------
4 | mps3_board.visualisation.disable-visualisation=1 # (bool , init-time) default = '0' : Enable/disable visualisation
5 | mps3_board.uart0.shutdown_on_eot=1 # (bool , init-time) default = '0' : Shutdown simulation when a EOT (ASCII 4) char is transmitted (useful for regression tests when semihosting is not available)
6 | ethosu.num_macs=256 # (int , init-time) default = '0x80' : Number of 8x8 MACs performed per cycle
7 | #---------------------------------------------------------------------------------------------------
8 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/fvp-configs/mps4_fvp_config.txt:
--------------------------------------------------------------------------------
1 | # Parameters:
2 | # instance.parameter=value #(type, mode) default = 'def value' : description : [min..max]
3 | #---------------------------------------------------------------------------------------------------
4 | mps4_board.visualisation.disable-visualisation=1 # (bool , init-time) default = '0' : Enable/disable visualisation
5 | vis_hdlcd.disable_visualisation=1 # (bool , init-time) default = '0' : Enable/disable visualisation
6 | mps4_board.uart0.shutdown_on_eot=1 # (bool , init-time) default = '0' : Shutdown simulation when a EOT (ASCII 4) char is transmitted (useful for regression tests when semihosting is not available)
7 | mps4_board.subsystem.ethosu.num_macs=256 # (int , init-time) default = '0x100' : Number of 8x8 MACs performed per cycle (256 or 512)
8 | #---------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/include/BoardInit.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BOARD_INIT_HPP
20 | #define BOARD_INIT_HPP
21 |
22 | /**
23 | * @brief Board initialisation - sets up all peripherals required.
24 | */
25 | void BoardInit(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/src/uart_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef _UART_CONFIG_H_
20 | #define _UART_CONFIG_H_
21 |
22 | #define UART0_BAUDRATE (115200)
23 | #define SYSTEM_CORE_CLOCK (25000000)
24 |
25 | #endif
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/src/uart_stdout.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef UART_STDOUT_H
20 | #define UART_STDOUT_H
21 |
22 | #if __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | /**
27 | * @brief UART initialisation - to enable printf output redirection.
28 | */
29 | void UartStdOutInit(void);
30 |
31 | /**
32 | * @brief Sends a character over UART
33 | *
34 | * @param[in] my_ch Character to be sent.
35 | * @return Character sent.
36 | * @note This is a blocking function.
37 | */
38 | unsigned char UartPutc(unsigned char my_ch);
39 |
40 | /**
41 | * @brief Reads a character over UART.
42 | * @return Character read.
43 | * @note This is a blocking function.
44 | */
45 | unsigned char UartGetc(void);
46 |
47 | #if __cplusplus
48 | }
49 | #endif
50 |
51 | #endif /* UART_STDOUT_H */
52 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/vsi/provenance.md:
--------------------------------------------------------------------------------
1 | # Origin of files in this directory
2 |
3 | - `include`: https://github.com/ARM-software/AVH/tree/1d9e2b02001a6e5d8f2fd622e5cf301144604007/interface/include
4 | - `video`: https://github.com/ARM-software/AVH/tree/1d9e2b02001a6e5d8f2fd622e5cf301144604007/interface/video
5 |
6 | **Note**: Files in this repository and files from [AVH repository](https://github.com/ARM-software/AVH/)
7 | should be under the same license terms.
8 |
9 | * See [AVH repository LICENSE](https://github.com/ARM-software/AVH/blob/1d9e2b02001a6e5d8f2fd622e5cf301144604007/LICENSE)
10 | * This repository's [LICENSE](../../../LICENSE)
11 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/corstone/vsi/vsi.clayer.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/clayer.schema.json
18 |
19 | layer:
20 |
21 | description: VSI video components and files.
22 |
23 | groups:
24 | - group: VSI
25 | files:
26 | - file: ./include/arm_vsi.h
27 | - file: ./video/include/video_drv.h
28 | - file: ./video/source/video_drv.c
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/frdm-k64f/frdm-k64f-device.clayer.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/clayer.schema.json
18 |
19 | layer:
20 |
21 | description: NXP FRDM-K64F device related components and files.
22 |
23 | groups:
24 | - group: Retarget
25 | for-context:
26 | - +FRDM-K64F
27 | files:
28 | - file: src/uart_stdout.h
29 | - file: src/uart_stdout.c
30 | - file: src/retarget.c
31 | - file: src/BoardInit.cpp
32 | - file: include/BoardInit.hpp
33 |
34 | components:
35 | - component: NXP::Device:CMSIS:MK64F12_header
36 | - component: NXP::Device:CMSIS:MK64F12_system
37 | - component: NXP::Device:SDK Drivers:adc
38 | - component: NXP::Device:SDK Drivers:button
39 | - component: NXP::Device:SDK Drivers:clock
40 | - component: NXP::Device:SDK Drivers:common
41 | - component: NXP::Device:SDK Drivers:ftm
42 | - component: NXP::Device:SDK Drivers:ftm_adapter
43 | - component: NXP::Device:SDK Drivers:gpio
44 | - component: NXP::Device:SDK Drivers:gpio_adapter
45 | - component: NXP::Device:SDK Drivers:i2c
46 | - component: NXP::Device:SDK Drivers:lists
47 | - component: NXP::Device:SDK Drivers:port
48 | - component: NXP::Device:SDK Drivers:rtc
49 | - component: NXP::Device:SDK Drivers:smc
50 | - component: NXP::Device:SDK Drivers:timer_manager
51 | - component: NXP::Device:SDK Drivers:uart
52 | - component: NXP::Device:SDK Drivers:uart_adapter
53 | - component: NXP::Device:SDK Utilities:debug_console
54 | - component: NXP::Device:SDK Utilities:serial_manager
55 | - component: NXP::Device:SDK Utilities:serial_manager_uart
56 | - component: NXP::Device:Startup
57 | - component: NXP::Board Support:SDK Project Template:project_template&frdmk64f
58 | - component: tensorflow::Machine Learning:TensorFlow:Kernel&CMSIS-NN
59 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/frdm-k64f/include/BoardInit.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BOARD_INIT_HPP
20 | #define BOARD_INIT_HPP
21 |
22 | /**
23 | * @brief Board initialisation - sets up all peripherals required.
24 | */
25 | void BoardInit(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/frdm-k64f/src/BoardInit.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "BoardInit.hpp"
20 |
21 | #if defined(__cplusplus)
22 | extern "C" {
23 | #include "board.h"
24 | #include "pin_mux.h"
25 | #include "uart_stdout.h"
26 | }
27 | #endif // defined(__cplusplus)
28 |
29 | void BoardInit(void)
30 | {
31 | BOARD_InitBootPins();
32 | UartStdOutInit();
33 | }
34 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/frdm-k64f/src/uart_stdout.c:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "uart_stdout.h"
20 |
21 | #include "board.h"
22 | #include "pin_mux.h"
23 |
24 | void UartStdOutInit(void)
25 | {
26 | BOARD_InitDebugConsole();
27 | }
28 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/frdm-k64f/src/uart_stdout.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef _UART_STDOUT_H_
20 | #define _UART_STDOUT_H_
21 |
22 | #if __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | /**
27 | * @brief UART initialisation to enable printf output redirection.
28 | */
29 | void UartStdOutInit(void);
30 |
31 | #if __cplusplus
32 | }
33 | #endif
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/include/BoardAudioUtils.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /*
20 | * Description: Keyword spotting wrapper class.
21 | */
22 |
23 | #ifndef BOARD_AUDIO_UTILS_HPP
24 | #define BOARD_AUDIO_UTILS_HPP
25 |
26 | #include
27 | #include
28 |
29 | /**
30 | * @brief Audio buffer descriptor
31 | */
32 | extern "C" typedef struct _audio_buf {
33 | void* data; /**< Pointer to buffer data. */
34 | uint32_t n_elements; /**< Number of elements in this buffer. */
35 | uint32_t n_bytes; /**< Total number of bytes occupied by this buffer. */
36 | } audio_buf;
37 |
38 | /**
39 | * @brief Audio utility class.
40 | */
41 | class AudioUtils {
42 | public:
43 | AudioUtils();
44 |
45 | /**
46 | * @brief Sets the input volume
47 | * @param[in] vol Volume to be set (value between 0-min and 100-max)
48 | */
49 | void SetVolumeIn(uint8_t vol);
50 |
51 | /**
52 | * @brief Sets the output volume
53 | * @param[in] vol Volume to be set (value between 0-min and 100-max)
54 | */
55 | void SetVolumeOut(uint8_t vol);
56 |
57 | /**
58 | * @brief Initialises the audio input interface.
59 | * @param[in] audioBufferInStereo Buffer descriptor for the audio interface to use.
60 | * @return True if successful, false otherwise.
61 | */
62 | bool AudioInit(audio_buf* audioBufferInStereo);
63 |
64 | /**
65 | * @brief Checks if the audio buffer has been populated.
66 | * @return True if buffer is full, false otherwise.
67 | */
68 | bool IsAudioAvailable();
69 |
70 | /**
71 | * @brief Sets the audio buffer as empty - useful to restart populating
72 | * the audio buffer.
73 | */
74 | void SetAudioEmpty();
75 |
76 | /**
77 | * @brief Starts recording the audio stream into the buffer provided at initialisation.
78 | */
79 | void StartAudioRecording();
80 |
81 | /**
82 | * @brief Stops recording the audio stream.
83 | */
84 | void StopAudioRecording();
85 |
86 | /**
87 | * @brief Gets if the recorded audio is stereo
88 | */
89 | bool IsStereo();
90 |
91 | private:
92 | /**
93 | * @brief Low level initialisation required for audio streaming initialisation.
94 | */
95 | uint8_t SetSysClock_PLL_HSE_200MHz();
96 | };
97 |
98 | #endif /* BOARD_AUDIO_UTILS_HPP */
99 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/include/BoardInit.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef BOARD_INIT_HPP
20 | #define BOARD_INIT_HPP
21 |
22 | /**
23 | * @brief Board initialisation - sets up all peripherals required.
24 | */
25 | void BoardInit(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/include/BoardPlotUtils.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | #ifndef PLOT_UTILS_HPP
19 | #define PLOT_UTILS_HPP
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | #define LCD_COLOR_ARM_BLUE ((uint32_t)0xFF00C1DE)
26 | #define LCD_COLOR_ARM_DARK ((uint32_t)0xFF333E48)
27 |
28 | /** Class for plotting/displaying to the on-board LCD on STM32 Discovery boards */
29 | class PlotUtils {
30 |
31 | public:
32 | /**
33 | * Constructors and destructors
34 | */
35 | PlotUtils();
36 | ~PlotUtils() = default;
37 |
38 | /**
39 | * @brief Clears the LCD
40 | */
41 | void ClearAll();
42 |
43 | /**
44 | * @brief Clears the string at a specific line
45 | * @param[in] line Line number for the string be be cleared at.
46 | * @note line number limits depend on the font being used and the
47 | * vertical span of the LCD. For default font the number
48 | * should be between 0 and 9. For smaller fonts available,
49 | * it could be [0-19] or [0-29].
50 | * @return none
51 | */
52 | void ClearStringLine(int line);
53 |
54 | /**
55 | * @brief Displays the given string at the specified location.
56 | * @param[in] line Line number to display the text at.
57 | * @param[in] text Text to be displayed.
58 | * @note line number limits depend on the font being used and the
59 | * vertical span of the LCD. For default font the number
60 | * should be between 0 and 9. For smaller fonts available,
61 | * it could be [0-19] or [0-29].
62 | * @return none
63 | */
64 | void DisplayStringAtLine(uint16_t line, std::string& text);
65 |
66 | /**
67 | * @brief Plots an audio waveform (or any sequence of 16-bit signed integers).
68 | * @param[in] data Pointer to the buffer.
69 | * @param[in] nElements Number of elements in the buffer.
70 | * @return none
71 | */
72 | void PlotWaveform(const int16_t* data, uint32_t nElements);
73 |
74 | private:
75 | uint32_t m_screenSizeX; /* Horizontal span of the LCD in pixels */
76 | uint32_t m_screenSizeY; /* Vertical span of the LCD in pixels */
77 | };
78 |
79 | #endif /* PLOT_UTILS_HPP */
80 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/src/stm32f7xx/drivers/cmsis/device/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This software component is provided to you as part of a software package and
2 | applicable license terms are in the Package_license file. If you received this
3 | software component outside of a package or without applicable license terms,
4 | the terms of the Apache-2.0 license shall apply.
5 | You may obtain a copy of the Apache-2.0 at:
6 | https://opensource.org/licenses/Apache-2.0
7 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/src/stm32f7xx/drivers/cmsis/device/Readme.md:
--------------------------------------------------------------------------------
1 | # STM32F746 device template files
2 |
3 | Files under this directory have been derived from Keil CMSIS-pack STM32F7xx_DFP
4 | version 2.15.1 (at the time of writing). In the original package too, they were
5 | shared under Apache 2.0 license, as they are within this repository. See
6 | [License.txt](LICENSE.txt).
7 |
8 | These files are meant to be used as templates that users can override. See other
9 | examples under Arm CMSIS GitHub repository here:
10 |
11 | * [ARMCM7/Source directory](https://github.com/ARM-software/CMSIS_5/tree/5.9.0/Device/ARM/ARMCM7/Source)
12 | * [startup_ARMCM7.s](https://github.com/ARM-software/CMSIS_5/blob/5.9.0/Device/ARM/ARMCM7/Source/ARM/startup_ARMCM7.s)
13 | * [system_ARMCM7.c](https://github.com/ARM-software/CMSIS_5/blob/5.9.0/Device/ARM/ARMCM7/Source/system_ARMCM7.c)
14 |
15 | The only change we have made to the startup assembly file is to the stack and heap sizes:
16 |
17 | ```asm
18 | Stack_Size EQU 0x00004000
19 | Heap_Size EQU 0x00014000
20 | ```
21 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/src/uart_stdout.c:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "uart_stdout.h"
20 |
21 | static UART_HandleTypeDef s_uart;
22 |
23 | void UartStdOutInit(void)
24 | {
25 | UART_InitTypeDef* init = &s_uart.Init;
26 | init->BaudRate = 115200;
27 | init->WordLength = UART_WORDLENGTH_8B;
28 | init->Parity = 0;
29 | init->StopBits = 1;
30 | init->HwFlowCtl = UART_HWCONTROL_NONE;
31 | init->Mode = UART_MODE_TX;
32 | init->OverSampling = UART_OVERSAMPLING_16;
33 | init->OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
34 |
35 | BSP_COM_Init(COM1, &s_uart);
36 | }
37 |
38 | UART_HandleTypeDef* GetUartHandle(void)
39 | {
40 | return &s_uart;
41 | }
42 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/device/stm32f746-discovery/src/uart_stdout.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef _UART_STDOUT_H_
20 | #define _UART_STDOUT_H_
21 |
22 | #if __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 | #include "stm32746g_discovery.h"
27 |
28 | /**
29 | * @brief UART initialisation.
30 | */
31 | void UartStdOutInit(void);
32 |
33 | /**
34 | * @brief Gets the current UART handle object.
35 | * @return Pointer to the UART object handle.
36 | */
37 | UART_HandleTypeDef* GetUartHandle(void);
38 |
39 | #if __cplusplus
40 | }
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/docs/01-install-cmsis-packs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/cmsis-pack-examples/docs/01-install-cmsis-packs.png
--------------------------------------------------------------------------------
/cmsis-pack-examples/docs/02-build-run.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/cmsis-pack-examples/docs/02-build-run.png
--------------------------------------------------------------------------------
/cmsis-pack-examples/kws/include/InputFiles.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef GENERATED_AUDIOCLIPS_H
20 | #define GENERATED_AUDIOCLIPS_H
21 |
22 | #include
23 | #include
24 |
25 | #define NUMBER_OF_FILES (1U)
26 |
27 | extern const int16_t audio0[16000];
28 |
29 | const char* get_filename(const uint32_t idx);
30 | const int16_t* get_audio_array(const uint32_t idx);
31 | uint32_t get_audio_array_size(const uint32_t idx);
32 |
33 | #endif /* GENERATED_AUDIOCLIPS_H */
--------------------------------------------------------------------------------
/cmsis-pack-examples/kws/include/Labels.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef LABELS_HPP
20 | #define LABELS_HPP
21 |
22 | #include
23 | #include
24 |
25 | /**
26 | * @brief Gets the label vector corresponding to the model
27 | * @param[out] labels Vector of strings.
28 | * @return true if successful, false otherwise.
29 | */
30 | extern bool GetLabelsVector(std::vector& labels);
31 |
32 | #endif /* LABELS_HPP */
33 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/kws/linker/stm32f746-disco.sct:
--------------------------------------------------------------------------------
1 | ; Copyright (c) 2021-2022 Arm Limited. All rights reserved.
2 | ; SPDX-License-Identifier: Apache-2.0
3 | ;
4 | ; Licensed under the Apache License, Version 2.0 (the "License");
5 | ; you may not use this file except in compliance with the License.
6 | ; You may obtain a copy of the License at
7 | ;
8 | ; http://www.apache.org/licenses/LICENSE-2.0
9 | ;
10 | ; Unless required by applicable law or agreed to in writing, software
11 | ; distributed under the License is distributed on an "AS IS" BASIS,
12 | ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | ; See the License for the specific language governing permissions and
14 | ; limitations under the License.
15 |
16 | ; load region size_region
17 | LOAD_REGION_0 0x08000000 0x100000
18 | {
19 | ER_IROM1 0x08000000 0x00100000 { ; load address = execution address
20 | *.o (RESET, +First)
21 | *(InRoot$$Sections)
22 | .ANY (+XO)
23 | .ANY (+RO)
24 | }
25 |
26 | RW_IRAM1 0x20000000 ALIGNALL 4 0x50000 {
27 | .ANY (+RW +ZI)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/kws/src/InputFiles.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "InputFiles.hpp"
20 |
21 | static const char* audio_clip_filenames[] = {
22 | "ks_down.wav",
23 | };
24 |
25 | static const int16_t* audio_clip_arrays[] = {
26 | audio0,
27 | };
28 |
29 | static const size_t audio_clip_sizes[NUMBER_OF_FILES] = {
30 | 16000,
31 | };
32 |
33 | const char* get_filename(const uint32_t idx)
34 | {
35 | if (idx < NUMBER_OF_FILES) {
36 | return audio_clip_filenames[idx];
37 | }
38 | return nullptr;
39 | }
40 |
41 | const int16_t* get_audio_array(const uint32_t idx)
42 | {
43 | if (idx < NUMBER_OF_FILES) {
44 | return audio_clip_arrays[idx];
45 | }
46 | return nullptr;
47 | }
48 |
49 | uint32_t get_audio_array_size(const uint32_t idx)
50 | {
51 | if (idx < NUMBER_OF_FILES) {
52 | return audio_clip_sizes[idx];
53 | }
54 | return 0;
55 | }
56 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/kws/src/Labels.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "BufAttributes.hpp"
20 |
21 | #include
22 | #include
23 |
24 | static const char* labelsVec[] LABELS_ATTRIBUTE = {
25 | "down",
26 | "go",
27 | "left",
28 | "no",
29 | "off",
30 | "on",
31 | "right",
32 | "stop",
33 | "up",
34 | "yes",
35 | "_silence_",
36 | "_unknown_",
37 | };
38 |
39 | bool GetLabelsVector(std::vector& labels)
40 | {
41 | constexpr size_t labelsSz = 12;
42 | labels.clear();
43 |
44 | if (!labelsSz) {
45 | return false;
46 | }
47 |
48 | labels.reserve(labelsSz);
49 |
50 | for (size_t i = 0; i < labelsSz; ++i) {
51 | labels.emplace_back(labelsVec[i]);
52 | }
53 |
54 | return true;
55 | }
56 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/object-detection/include/InputFiles.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #ifndef GENERATED_IMAGES_H
20 | #define GENERATED_IMAGES_H
21 |
22 | #include
23 |
24 | #define NUMBER_OF_FILES (1U)
25 | #define IMAGE_DATA_SIZE (110592U)
26 |
27 | extern const uint8_t im0[IMAGE_DATA_SIZE];
28 |
29 | const char* get_filename(const uint32_t idx);
30 | const uint8_t* get_img_array(const uint32_t idx);
31 |
32 | #endif /* GENERATED_IMAGES_H */
--------------------------------------------------------------------------------
/cmsis-pack-examples/object-detection/object-detection.clayer.yml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its
2 | # affiliates
3 | # SPDX-License-Identifier: Apache-2.0
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/schemas/projmgr/2.4.0/tools/projmgr/schemas/cproject.schema.json
18 |
19 | layer:
20 | description: Common layer for object detection project
21 |
22 | groups:
23 | - group: Use Case
24 | files:
25 | - file: src/yolo-fastest_192_face_v4.tflite.cpp
26 | for-context:
27 | - +AVH-SSE-300
28 | - +AVH-SSE-310
29 | - +AVH-SSE-315
30 | - +AVH-SSE-320
31 | - file: src/yolo-fastest_192_face_v4_vela_H256.tflite.cpp
32 | for-context:
33 | - +AVH-SSE-300-U55
34 | - +AVH-SSE-310-U55
35 | - +Alif-E7-M55-HP
36 | - file: src/yolo-fastest_192_face_v4_vela_Y256.tflite.cpp
37 | for-context:
38 | - +AVH-SSE-300-U65
39 | - +AVH-SSE-310-U65
40 | - +AVH-SSE-315-U65
41 | - file: src/yolo-fastest_192_face_v4_vela_Z256.tflite.cpp
42 | for-context:
43 | - +AVH-SSE-320-U85
44 |
45 | - group: Device Files
46 | files:
47 | - file: linker/mps3-sse-300.sct
48 | for-context:
49 | - +AVH-SSE-300
50 | - +AVH-SSE-300-U55
51 | - +AVH-SSE-300-U65
52 |
53 | - file: linker/mps3-sse-310.sct
54 | for-context:
55 | - +AVH-SSE-310
56 | - +AVH-SSE-310-U55
57 | - +AVH-SSE-310-U65
58 |
59 | - file: linker/mps4-sse-315.sct
60 | for-context:
61 | - +AVH-SSE-315
62 | - +AVH-SSE-315-U65
63 | - +AVH-SSE-320
64 | - +AVH-SSE-320-U85
65 |
66 | - file: linker/alif-e7-m55-hp.sct
67 | for-context: +Alif-E7-M55-HP
68 |
69 | define:
70 | - ACTIVATION_BUF_SZ: 532480
71 |
72 | components:
73 | - component: ARM::ML Eval Kit:Vision:Object detection
74 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/object-detection/src/InputFiles.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its
3 | * affiliates
4 | * SPDX-License-Identifier: Apache-2.0
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "InputFiles.hpp"
20 |
21 | static const char* img_filenames[] = {"sample_image.png"};
22 |
23 | static const uint8_t* img_arrays[] = {im0};
24 |
25 | const char* get_filename(const uint32_t idx)
26 | {
27 | if (idx < NUMBER_OF_FILES) {
28 | return img_filenames[idx];
29 | }
30 | return nullptr;
31 | }
32 |
33 | const uint8_t* get_img_array(const uint32_t idx)
34 | {
35 | if (idx < NUMBER_OF_FILES) {
36 | return img_arrays[idx];
37 | }
38 | return nullptr;
39 | }
40 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/resources/files.md:
--------------------------------------------------------------------------------
1 | # cmsis-pack-examples resources
2 |
3 | * sample_image.png
4 | * sample_audio.wav
5 |
6 | # Sample data
7 |
8 | The sample image and audio files are provided under the Apache 2.0 license, see [License](../LICENSE).
9 |
--------------------------------------------------------------------------------
/cmsis-pack-examples/resources/sample_audio.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/cmsis-pack-examples/resources/sample_audio.wav
--------------------------------------------------------------------------------
/cmsis-pack-examples/resources/sample_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/cmsis-pack-examples/resources/sample_image.png
--------------------------------------------------------------------------------
/cmsis-pack-examples/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "032d9d0820db290ce9ff644dabfdf564343013ae",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "name": "arm",
10 | "kind": "artifact",
11 | "location": "https://artifacts.tools.arm.com/vcpkg-registry"
12 | }
13 | ],
14 | "requires": {
15 | "arm:tools/open-cmsis-pack/cmsis-toolbox": "^2.4.0",
16 | "arm:tools/kitware/cmake": "^3.28.4",
17 | "arm:tools/ninja-build/ninja": "^1.12.0",
18 | "arm:compilers/arm/armclang": "^6.22.0",
19 | "arm:models/arm/avh-fvp": "^11.27.31"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ethos-u-corstone-300/README.md:
--------------------------------------------------------------------------------
1 | #Train and Deploy your NPU-enabled models
2 |
3 | Using the Arm® Corstone™-300 with Arm® Cortex™-M55 and Arm® Ethos™-U55 NPU.
4 |
5 | ## Summary
6 | This notebook presents a flow to help bridge the gap between data scientists and embedded engineers.
7 |
--------------------------------------------------------------------------------
/kleidiai-examples/audiogen/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | # vs-code
8 | .vscode/*
9 |
10 | # python
11 | __pycache__/
12 |
13 | # env
14 | env
15 | venv
16 |
17 | # build
18 | build/**
19 | app/build/**
20 |
21 | # models
22 | *.tflite
23 | *.onnx
24 | *.pb
25 | *variable*
26 | saved_model/**
--------------------------------------------------------------------------------
/kleidiai-examples/audiogen/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | cmake_minimum_required(VERSION 3.16)
8 | project(audiogen_runner)
9 |
10 | if(NOT CMAKE_CXX_STANDARD)
11 | set(CMAKE_CXX_STANDARD 17)
12 | endif()
13 |
14 | if(NOT ROOT_PATH)
15 | set(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/..)
16 | endif()
17 |
18 | set(srcs audiogen.cpp)
19 |
20 | # TFLite
21 | if(NOT TF_LIB_PATH)
22 | message( FATAL_ERROR "TenserFlow library path is required, Flag TF_LIB_PATH must be set" )
23 | endif()
24 |
25 | if(NOT TF_INCLUDE_PATH)
26 | message( FATAL_ERROR "TenserFlow include path is required, Flag TF_INCLUDE_PATH must be set" )
27 | endif()
28 |
29 | # Flatbuffer
30 | if(NOT FLATBUFFER_INCLUDE_PATH)
31 | message( FATAL_ERROR "Flatbuffer include path is required, Flag FLATBUFFER_INCLUDE_PATH must be set" )
32 | endif()
33 |
34 | include(FetchContent)
35 |
36 | FetchContent_Declare(
37 | sentencepiece_src
38 | GIT_REPOSITORY https://github.com/google/sentencepiece.git
39 | GIT_TAG v0.2.0
40 | )
41 |
42 | FetchContent_Populate(sentencepiece_src)
43 | add_subdirectory(${sentencepiece_src_SOURCE_DIR} ${sentencepiece_src_BINARY_DIR})
44 |
45 | list(APPEND common_link_directories
46 | ${TF_LIB_PATH}/)
47 |
48 | list(APPEND common_include_directories
49 | ${ROOT_PATH}/runner
50 | ${TF_INCLUDE_PATH}
51 | ${FLATBUFFER_INCLUDE_PATH} )
52 |
53 | list(APPEND audiogen_runner_deps tensorflowlite)
54 |
55 | add_executable(audiogen ${srcs})
56 |
57 | target_include_directories(audiogen PUBLIC
58 | ${common_include_directories}
59 | ${sentencepiece_SOURCE_DIR}/src)
60 |
61 | target_link_directories(audiogen PUBLIC ${common_link_directories})
62 |
63 | add_dependencies(audiogen sentencepiece)
64 |
65 | # It is required to avoid the linking with libsentencepiece.so
66 | list(APPEND audiogen_runner_deps ${sentencepiece_src_BINARY_DIR}/src/libsentencepiece.a)
67 |
68 | if(ANDROID)
69 | list(APPEND audiogen_runner_deps log)
70 | endif()
71 |
72 | target_link_libraries(audiogen
73 | ${audiogen_runner_deps}
74 | )
75 |
76 | target_compile_options(audiogen PUBLIC)
77 |
--------------------------------------------------------------------------------
/kleidiai-examples/audiogen/install_requirements.sh:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 |
7 | #!/bin/bash
8 |
9 | # Install individual packages
10 | echo "Installing required packages for the Audiogen module..."
11 |
12 | # ai-edge-torch
13 | pip install ai-edge-torch==0.4.0 \
14 | "tf-nightly>=2.19.0.dev20250208" \
15 | "ai-edge-litert-nightly>=1.1.2.dev20250305" \
16 | "ai-edge-quantizer-nightly>=0.0.1.dev20250208"
17 |
18 | # Stable audio tools
19 | pip install "stable_audio_tools==0.0.19"
20 |
21 |
22 | # Working out dependency issues, this combination of packages has been tested on different systems (Linux and MacOS).
23 | pip install --no-deps "torch==2.6.0" \
24 | "torchaudio==2.6.0" \
25 | "torchvision==0.21.0" \
26 | "protobuf==5.29.4" \
27 | "numpy==1.26.4" \
28 |
29 | # Packages to convert via onnx
30 | pip install --no-deps onnx \
31 | onnxsim \
32 | onnx2tf \
33 | tensorflow \
34 | tf_keras \
35 | onnx_graphsurgeon \
36 | ai_edge_litert \
37 | sng4onnx
38 |
39 | echo "Finished installing required packages for AudioGen submodules conversion."
40 | echo "To start converting the Conditioners, DiT and Autoencoder modules conversion, use the following command:"
41 | echo "python ./scripts/export_{MODEL-T0-CONVERT}.py"
42 |
--------------------------------------------------------------------------------
/kleidiai-examples/audiogen/model.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/kleidiai-examples/audiogen/model.png
--------------------------------------------------------------------------------
/kleidiai-examples/llama_cpp/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Arm Limited
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/audio/README.md:
--------------------------------------------------------------------------------
1 | The wav files were generated by Apple's Speech Synthesis Manager (say -v Fiona -o output.aiff) and were converted to .wav format with Audacity (http://www.audacityteam.org).
2 |
3 | The file epic.mp3 used in the demo video was Epic Inspire Trailer by Alex Che, used under licence from Jamendo:
4 | https://licensing.jamendo.com/en/track/1414456/epic-inspire-trailer
5 |
6 | That file is not redistributed here. Feel free to use your own favourite soundtrack - any mp3 will work!
7 |
8 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/audio/alarm-active.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/multi-gesture-recognition/audio/alarm-active.wav
--------------------------------------------------------------------------------
/multi-gesture-recognition/audio/good-evening.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/multi-gesture-recognition/audio/good-evening.wav
--------------------------------------------------------------------------------
/multi-gesture-recognition/audio/good-night.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/multi-gesture-recognition/audio/good-night.wav
--------------------------------------------------------------------------------
/multi-gesture-recognition/camera.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | A simple wrapper around PiCamera that can randomly vary the exposure and
14 | white balance during image capture as a form of data augmentation.
15 | """
16 | from time import sleep
17 | from random import choice, uniform
18 |
19 | from picamera.array import PiRGBArray
20 | from picamera import PiCamera
21 |
22 |
23 |
24 | class Camera:
25 | """ A simple PiCamera wrapper. Setting training_mode will randomly vary
26 | exposure and white balance between captured images. The capture stream
27 | is truncated before capture to reduce recognition latency at the expense
28 | of frame rate. """
29 | def __init__(self, training_mode):
30 | self.training_mode = training_mode
31 | self.camera = PiCamera()
32 | self.camera.resolution = (128, 128)
33 | self.camera.framerate = 30
34 | self.capture = PiRGBArray(self.camera, size=self.camera.resolution)
35 | self.stream = self.camera.capture_continuous(self.capture,
36 | format='rgb',
37 | use_video_port=True)
38 | if training_mode:
39 | # We allow picamera's auto exposure settings to settle for 5 seconds then we
40 | # lock them so they don't change in response to actions as this can cause problems.
41 | # If waving your hands causes the camera to shift its exposure settings during training
42 | # as then the network will likely learn to detect the exposure setting not your hands!
43 | sleep(5)
44 | self.camera.shutter_speed = self.camera.exposure_speed
45 | self.camera.exposure_mode = 'off'
46 | self.base_awb = self.camera.awb_gains
47 | self.camera.awb_mode = 'off'
48 |
49 |
50 | def next_frame(self):
51 | """ Capture a frame from the camera. By truncating the frame buffer we
52 | exchange FPS for lower latency. When responding to gestures latency is
53 | more important to the user experience. """
54 | self.capture.truncate(0)
55 | if self.training_mode:
56 | self.camera.iso = choice([100, 200, 320, 400, 500, 640, 800])
57 | awb_r = max(0., uniform(-.5, .5) + self.base_awb[0])
58 | awb_b = max(0., uniform(-.5, .5) + self.base_awb[1])
59 | self.camera.awb_gains = (awb_r, awb_b)
60 |
61 | frame = next(self.stream).array
62 | return frame
63 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/merge.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | Merge multiple datasets:
14 | merge.py day1+2 day1 day2
15 | The above copies all files in day1 and day2 into day1+2 whilst preserving directory structure and
16 | introducing unique names to avoid overwriting/conflicts.
17 | """
18 | from sys import argv, exit
19 | from os import system
20 | from glob import glob
21 |
22 |
23 |
24 | if len(argv) < 3:
25 | print("""Usage: merge.py OUTPUT_DIR INPUT_DIRS...
26 | Copy images from INPUT_DIRS to class folders in OUTPUT_DIR without overwriting duplicate names""")
27 | exit(1)
28 |
29 | output = argv[1][:-1] if argv[-1] == '/' else argv[1]
30 | directories = argv[2:]
31 |
32 | system('mkdir -p "%s"' % output)
33 |
34 | total = 0
35 |
36 | for directory in directories:
37 | directory = directory[:-1] if directory[-1] == '/' else directory
38 | subdirs = glob('%s/[0-9]/' % directory)
39 |
40 | for subdir in sorted(subdirs):
41 | print('Processing %s' % subdir)
42 | subdir = subdir[:-1]
43 | label = int(subdir.split('/')[-1])
44 | base = subdir.split('/')[-2]
45 | images = glob('%s/*.png' % subdir)
46 |
47 | system("mkdir -p '%s/%s'" % (output, label))
48 | for filename in images:
49 | system('cp "%s" "%s/%s/%s-%s"' % (filename, output, label, base, filename.split('/')[-1]))
50 | total += 1
51 |
52 | print('%d images copied to %s' % (total, output))
53 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/preview.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """
15 | Show a camera preview using the same resolution and FPS settings
16 | as will be used for training, but without randomly adjusting
17 | the exposure (training_mode=False). Enable this to see what it does.
18 | """
19 |
20 | from sys import stderr
21 | from time import time
22 |
23 | import pygame
24 | from camera import Camera
25 |
26 |
27 | def main():
28 | camera = Camera(training_mode=False)
29 | pygame.display.init()
30 | pygame.display.set_caption("PiCamera preview")
31 | screen = pygame.display.set_mode((512, 512))
32 |
33 | while True:
34 | total = time()
35 | frame = camera.next_frame()
36 | surface = pygame.surfarray.make_surface(frame)
37 | screen.blit(pygame.transform.scale(surface, (512, 512)), (0, 0))
38 | pygame.display.flip()
39 |
40 | for evt in pygame.event.get():
41 | if evt.type == pygame.QUIT:
42 | pygame.quit()
43 | break
44 |
45 | total = time() - total
46 | stderr.write("\r%4.0f ms per frame, %2.1f FPS " % (total*1000, 1.0/total))
47 |
48 | if __name__ == '__main__':
49 | main()
50 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/record.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | Record frames from the camera and save them to as PNG files.
14 | """
15 | from time import time, sleep
16 | from sys import argv, exit, stdout
17 | from os import mkdir, path
18 | import errno
19 | from PIL import Image
20 | from camera import Camera
21 |
22 |
23 |
24 | def main():
25 | if len(argv) != 3:
26 | print("""Usage: %s DIRECTORY SECONDS
27 | Record frames from the camera for SECONDS seconds and save them in DIRECTORY""" % argv[0])
28 | exit(1)
29 | name = argv[1]
30 | seconds = int(argv[2])
31 |
32 | # Initialize the camera and record video frames for a few seconds
33 | # We select a random exposure for each frame to generate a wide range
34 | # of lighting samples for training
35 | camera = Camera(training_mode=True)
36 | record(camera, name, seconds)
37 |
38 |
39 | def status(text):
40 | """Helper function to show status updates"""
41 | stdout.write('\r%s' % text)
42 | stdout.flush()
43 |
44 |
45 | def record(camera, dirname, seconds):
46 | """ Record from the camera """
47 |
48 | delay = 3 # Give people a 3 second warning to get ready
49 | started = time()
50 | while time() - started < delay:
51 | status("Recording in %.0f..." % max(0, delay - (time() - started)))
52 | sleep(0.1)
53 |
54 | try:
55 | mkdir(dirname)
56 | except OSError as err:
57 | if err.errno != errno.EEXIST:
58 | raise err
59 |
60 | num_frames = 0
61 |
62 | started = time()
63 | while time() - started < seconds or seconds == -1:
64 | frame = camera.next_frame()
65 | image = Image.fromarray(frame)
66 | filename = (path.join(dirname, '%05d.png') % num_frames)
67 | image.save(filename, "PNG")
68 | num_frames += 1
69 |
70 | # Update our progress
71 | if seconds != -1:
72 | status("Recording [ %d frames, %3.0fs left ]" % (num_frames,
73 | max(0, seconds - (time() - started))))
74 | else:
75 | status("Recording [ %d frames, %3.0fs so far ]" % (num_frames,
76 | max(0, (time() - started))))
77 |
78 | print('')
79 |
80 | # Save the frames to a file, appending if one already exists
81 | print('Wrote %d frames to %s\n' % (num_frames, dirname))
82 |
83 |
84 | if __name__ == '__main__':
85 | main()
86 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/test.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | Test the model trained on one dataset on the images in another dataset and report its accuracy and
14 | the images that it mispredicted:
15 | python test.py day1 day2
16 | The above assumes day1/model.h5 has been created with train.py.
17 | """
18 | from sys import argv, exit
19 | from glob import glob
20 | from collections import defaultdict
21 |
22 | import numpy as np
23 | from tensorflow.keras.models import load_model
24 | from PIL import Image
25 |
26 |
27 |
28 | def main():
29 | if len(argv) != 3 or argv[1] == '--help':
30 | print("""Usage: test.py TRAIN_DIR TEST_DIR...
31 | Load TRAIN_DIR/model.h5 and report on its accuracy and mispredicted items from TEST_DIR.""")
32 | exit(1)
33 |
34 | train_data_dir = argv[1]
35 | test_data_dir = argv[2]
36 | image_files = glob('%s/*/*.png' % test_data_dir)
37 |
38 | model = load_model('%s/model.h5' % train_data_dir)
39 |
40 | correct = 0
41 | correct_by_class = defaultdict(int)
42 | total_by_class = defaultdict(int)
43 | for filename in sorted(image_files):
44 | try:
45 | image = Image.open(filename)
46 | x = np.array(image.getdata()).reshape((128, 128, 3)) / 255.0
47 | l = int(filename.split('/')[-2])
48 | p = model.predict([np.array([x])])[0]
49 | y = np.argmax(p)
50 | if y == l:
51 | correct += 1
52 | correct_by_class[l] += 1
53 | else:
54 | print('%s: actual %d, predicted %d (%s)' % (filename, l, y,
55 | ', '.join('%.1f' % d for d in p)))
56 | total_by_class[l] += 1
57 | except:
58 | print('Error processing %s' % filename)
59 |
60 | for c in total_by_class.keys():
61 | print('Class %d: %5d/%5d: %.0f %% accurate' % (c, correct_by_class[c], total_by_class[c],
62 | 100.0 * correct_by_class[c] / total_by_class[c]))
63 |
64 | print('Overall %5d/%5d: %.0f %% accurate' % (correct, len(image_files),
65 | 100.0* correct / len(image_files)))
66 |
67 |
68 | if __name__ == '__main__':
69 | main()
70 |
--------------------------------------------------------------------------------
/multi-gesture-recognition/validate_split.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | Split a classified dataset into two - keep 90% of the files the original set for training and
14 | create a new dataset prefixed by val_ with the other 10%.
15 | """
16 | from sys import argv, exit
17 | from os import system
18 | from glob import glob
19 | from random import shuffle
20 |
21 |
22 |
23 | def main():
24 | if len(argv) != 2 or argv[1] == '--help':
25 | print("""Usage: validate_split.py DIRECTORY
26 | Move 10% of the images in subdirectories of DIRECTORY to a new val_DIRECTORY.""")
27 | exit(1)
28 |
29 | directory = argv[1]
30 | subdirs = glob('%s/*/' % directory)
31 |
32 | moved = 0
33 | for subdir in sorted(subdirs):
34 | subdir = subdir[:-1]
35 |
36 | print('Splitting %s' % subdir)
37 | valdir = 'val_%s' % subdir
38 | system('mkdir -p %s' % valdir)
39 | images = glob('%s/*.png' % subdir)
40 | shuffle(images)
41 | k = len(images) // 10
42 | for i in images[:k]:
43 | system('mv %s val_%s' % (i, i))
44 | moved += k
45 |
46 |
47 | print('Moved %d images from %s to val_%s' % (moved, directory, directory))
48 |
49 |
50 | if __name__ == '__main__':
51 | main()
52 |
--------------------------------------------------------------------------------
/pruning-clustering-ethos-u/README.md:
--------------------------------------------------------------------------------
1 | This repository contains a Jupyter notebook that will demonstrate how to train a Neural Network in TensorFlow
2 | and demonstrate the benefit of [pruning](https://blog.tensorflow.org/2019/05/tf-model-optimization-toolkit-pruning-API.html) and [clustering](https://www.tensorflow.org/model_optimization/guide/clustering) before deploying onto [Arm Ethos-U55](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u55) and [Arm Ethos-U65 NPU](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u65).
--------------------------------------------------------------------------------
/pruning-clustering-ethos-u/resources/pruning_clustering.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pruning-clustering-ethos-u/resources/pruning_clustering.png
--------------------------------------------------------------------------------
/pyarmnn-fire-detection/fire_detection.tflite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pyarmnn-fire-detection/fire_detection.tflite
--------------------------------------------------------------------------------
/pyarmnn-fire-detection/predict_pyarmnn.py:
--------------------------------------------------------------------------------
1 | import pyarmnn as ann
2 | import numpy as np
3 | import argparse
4 | import cv2
5 | from timeit import default_timer as timer
6 |
7 | print(f"Working with ARMNN {ann.ARMNN_VERSION}")
8 |
9 | #Load an image
10 | parser = argparse.ArgumentParser(
11 | formatter_class=argparse.ArgumentDefaultsHelpFormatter)
12 | parser.add_argument(
13 | '--image', help='File path of image file', required=True)
14 | args = parser.parse_args()
15 |
16 | image = cv2.imread(args.image)
17 | image = cv2.resize(image, (128, 128))
18 | image = np.array(image, dtype=np.float32) / 255.0
19 | print(image.shape)
20 |
21 | # ONNX, Caffe and TF parsers also exist.
22 | parser = ann.ITfLiteParser()
23 | network = parser.CreateNetworkFromBinaryFile('./fire_detection.tflite')
24 |
25 | graph_id = 0
26 | input_names = parser.GetSubgraphInputTensorNames(graph_id)
27 | input_binding_info = parser.GetNetworkInputBindingInfo(graph_id, input_names[0])
28 | input_tensor_id = input_binding_info[0]
29 | input_tensor_info = input_binding_info[1]
30 | print(f"""
31 | tensor id: {input_tensor_id},
32 | tensor info: {input_tensor_info}
33 | """)
34 |
35 | # Create a runtime object that will perform inference.
36 | options = ann.CreationOptions()
37 | runtime = ann.IRuntime(options)
38 |
39 | # Backend choices earlier in the list have higher preference.
40 | preferredBackends = [ann.BackendId('CpuAcc'), ann.BackendId('CpuRef')]
41 | opt_network, messages = ann.Optimize(network, preferredBackends, runtime.GetDeviceSpec(), ann.OptimizerOptions())
42 |
43 | # Load the optimized network into the runtime.
44 | net_id, _ = runtime.LoadNetwork(opt_network)
45 | print(f"Loaded network, id={net_id}")
46 | # Create an inputTensor for inference.
47 | input_tensors = ann.make_input_tensors([input_binding_info], [image])
48 |
49 | # Get output binding information for an output layer by using the layer name.
50 | output_names = parser.GetSubgraphOutputTensorNames(graph_id)
51 | output_binding_info = parser.GetNetworkOutputBindingInfo(0, output_names[0])
52 | output_tensors = ann.make_output_tensors([output_binding_info])
53 |
54 | start = timer()
55 | runtime.EnqueueWorkload(0, input_tensors, output_tensors)
56 | end = timer()
57 | print('Elapsed time is ', (end - start) * 1000, 'ms')
58 |
59 | output = ann.workload_tensors_to_ndarray(output_tensors)
60 | print(output)
61 | j = np.argmax(output)
62 | if j == 0:
63 | print("Non-Fire")
64 | else:
65 | print("Fire")
66 |
67 |
--------------------------------------------------------------------------------
/pyarmnn-fire-detection/predict_tflite.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 |
3 | import argparse
4 | import io
5 | import time
6 | import cv2
7 | import numpy as np
8 | from timeit import default_timer as timer
9 |
10 | # Load TFLite model and allocate tensors.
11 | interpreter = tf.lite.Interpreter(model_path="./fire_detection.tflite")
12 | interpreter.allocate_tensors()
13 |
14 | # Get input and output tensors.
15 | input_details = interpreter.get_input_details()
16 | output_details = interpreter.get_output_details()
17 | _,height,width,_ = input_details[0]['shape']
18 | floating_model = False
19 | if input_details[0]['dtype'] == np.float32:
20 | floating_model = True
21 |
22 | parser = argparse.ArgumentParser(
23 | formatter_class=argparse.ArgumentDefaultsHelpFormatter)
24 | parser.add_argument(
25 | '--image', help='File path of image file', required=True)
26 | args = parser.parse_args()
27 |
28 | image = cv2.imread(args.image)
29 | image = cv2.resize(image, (width, height))
30 | image = np.expand_dims(image, axis=0)
31 | if floating_model:
32 | image = np.array(image, dtype=np.float32) / 255.0
33 | print(image.shape)
34 |
35 | # Test model on image.
36 | interpreter.set_tensor(input_details[0]['index'], image)
37 | start = timer()
38 | interpreter.invoke()
39 | end = timer()
40 | print('Elapsed time is ', (end-start)*1000, 'ms')
41 |
42 | # The function `get_tensor()` returns a copy of the tensor data.
43 | # Use `tensor()` in order to get a pointer to the tensor.
44 | output_data = interpreter.get_tensor(output_details[0]['index'])
45 | print(output_data)
46 | j = np.argmax(output_data)
47 | if j == 0:
48 | print("Non-Fire")
49 | else:
50 | print("Fire")
51 |
--------------------------------------------------------------------------------
/pytorch-to-tflite/README.md:
--------------------------------------------------------------------------------
1 | # PyTorch to TFLite
2 |
3 | This repository contains a Jupyter notebook that will demonstrate how to convert a model trained in [PyTorch](https://pytorch.org/) to [TensorFlow Lite](https://www.tensorflow.org/lite) format by using [ONNX](https://onnx.ai/).
4 |
5 | It also shows how to quantize your model so that it is ready to be optimized by [Vela](https://pypi.org/project/ethos-u-vela/) in order for the model to be deployed onto [Arm Ethos-U55](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u55) or [Arm Ethos-U65](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u65) NPU.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/onnx_model.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/onnx_model.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/pad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/pad.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/pytorch_arm_ethos_flow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/pytorch_arm_ethos_flow.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/pytorch_model.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/pytorch_model.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/relu6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/relu6.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/reshape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/reshape.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/transpose.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/transpose.png
--------------------------------------------------------------------------------
/pytorch-to-tflite/resources/vela.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/pytorch-to-tflite/resources/vela.png
--------------------------------------------------------------------------------
/rnn-unrolling-tflite/README.md:
--------------------------------------------------------------------------------
1 | # RNN unrolling for TFLite
2 |
3 | This repository contains a Jupyter notebook that will demonstrate how to train a Recurrent Neural Network (RNN) in TensorFlow and then prepare it for exporting to [TensorFlow Lite](https://www.tensorflow.org/lite) format by unrolling it.
4 |
5 | It also shows how to quantize your unrolled model so that it is ready to be optimized by [Vela](https://pypi.org/project/ethos-u-vela/) in order for the model to be deployed onto [Arm Ethos-U55](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u55) or [Arm Ethos-U65](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u65) NPU.
6 |
--------------------------------------------------------------------------------
/rnn-unrolling-tflite/resources/gru_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/rnn-unrolling-tflite/resources/gru_network.png
--------------------------------------------------------------------------------
/rnn-unrolling-tflite/resources/rnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/rnn-unrolling-tflite/resources/rnn.png
--------------------------------------------------------------------------------
/rnn-unrolling-tflite/resources/unroll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/rnn-unrolling-tflite/resources/unroll.png
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the License); you may
7 | # not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | cmake_minimum_required(VERSION 3.21.0)
20 |
21 | set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
22 | set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
23 | set(APP_TARGET tools_project)
24 |
25 | include(${MBED_PATH}/tools/cmake/app.cmake)
26 |
27 | project("mbed-tflm-image-recognition")
28 |
29 | add_executable("${PROJECT_NAME}" "")
30 |
31 | add_subdirectory("tensorflow")
32 | add_subdirectory(${MBED_PATH})
33 | add_subdirectory("BSP")
34 | add_subdirectory("image_recognition")
35 |
36 | mbed_configure_app_target(${PROJECT_NAME})
37 |
38 | target_include_directories(${PROJECT_NAME}
39 | PUBLIC
40 | image_recognition
41 | ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/tools/make/downloads/flatbuffers/include
42 | ${CMAKE_CURRENT_SOURCE_DIR}
43 | )
44 |
45 | target_link_libraries(${PROJECT_NAME}
46 | mbed-baremetal
47 | )
48 |
49 | if("${MAINFILE}" STREQUAL "test")
50 | set(mainfile test.cpp)
51 | else()
52 | set(mainfile main.cpp)
53 | endif()
54 |
55 | target_sources(${PROJECT_NAME}
56 | PUBLIC
57 | image_recognition/${mainfile}
58 | )
59 |
60 | mbed_set_post_build(${PROJECT_NAME})
61 |
62 | option(VERBOSE_BUILD "Have a verbose build process")
63 | if(VERBOSE_BUILD)
64 | set(CMAKE_VERBOSE_MAKEFILE ON)
65 | endif()
66 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/clean.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved.
5 | #
6 | # SPDX-License-Identifier: Apache-2.0
7 | #
8 | # Licensed under the Apache License, Version 2.0 (the License); you may
9 | # not use this file except in compliance with the License.
10 | # You may obtain a copy of the License at
11 | #
12 | # www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing, software
15 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT
16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | # See the License for the specific language governing permissions and
18 | # limitations under the License.
19 | #
20 |
21 | rm -rf tflite-micro
22 | rm -rf tensorflow
23 | rm -rf mbed-os
24 | rm -rf BSP
25 | rm -f test_batch.bin
26 | rm -f image_recognition/50_cifar_images.h
27 | rm -rf cmake_build
28 |
29 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the License); you may
7 | # not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | cmake_minimum_required(VERSION 3.21.0)
20 |
21 | target_sources(${PROJECT_NAME}
22 | PUBLIC
23 | stm32f746_discovery/display_util.cc
24 | stm32f746_discovery/image_provider.cc
25 | stm32f746_discovery/image_util.cc
26 | )
27 |
28 | target_include_directories(${PROJECT_NAME}
29 | PUBLIC
30 | stm32f746_discovery
31 | )
32 |
33 | target_sources(${PROJECT_NAME}
34 | PUBLIC
35 | image_recognition_model/image_recognition_model.cc
36 | )
37 |
38 | target_include_directories(${PROJECT_NAME}
39 | PUBLIC
40 | image_recognition_model
41 | )
42 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/image_dims.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
3 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #define CHANNEL_SIZE 1024
21 | #define R_CHANNEL_OFFSET 0
22 | #define G_CHANNEL_OFFSET (CHANNEL_SIZE)
23 | #define B_CHANNEL_OFFSET (CHANNEL_SIZE * 2)
24 | #define IMAGE_BYTES 3072
25 | #define LABEL_BYTES 1
26 | #define ENTRY_BYTES (IMAGE_BYTES + LABEL_BYTES)
27 | #define NUM_OUT_CH 3
28 | #define CNN_IMG_SIZE 32
29 | #define NUM_IN_CH 2
30 | #define IN_IMG_WIDTH 160
31 | #define IN_IMG_HEIGHT 120
32 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/image_provider.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #include "tensorflow/lite/micro/micro_error_reporter.h"
21 | #include "tensorflow/lite/c/c_api_types.h"
22 |
23 | TfLiteStatus InitCamera(tflite::ErrorReporter* error_reporter);
24 |
25 | // This is an abstraction around an image source like a camera, and is
26 | // expected to return 8-bit sample data. The assumption is that this will be
27 | // called in a low duty-cycle fashion in a low-power application. In these
28 | // cases, the imaging sensor need not be run in a streaming mode, but rather can
29 | // be idled in a relatively low-power mode between calls to GetImage(). The
30 | // assumption is that the overhead and time of bringing the low-power sensor out
31 | // of this standby mode is commensurate with the expected duty cycle of the
32 | // application. The underlying sensor may actually be put into a streaming
33 | // configuration, but the image buffer provided to GetImage should not be
34 | // overwritten by the driver code until the next call to GetImage();
35 | //
36 | // The reference implementation can have no platform-specific dependencies, so
37 | // it just returns a static image. For real applications, you should
38 | // ensure there's a specialized implementation that accesses hardware APIs.
39 | TfLiteStatus GetImage(tflite::ErrorReporter* error_reporter, int image_width,
40 | int image_height, int channels, uint8_t* image_data);
41 |
42 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/image_recognition_model.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | // This is a standard TensorFlow Lite model file that has been converted into a
21 | // C data array, so it can be easily compiled into a binary for devices that
22 | // don't have a file system. It can be created using the command:
23 | // xxd -i image_recognition_model.tflite > image_recognition_model.cc
24 |
25 | extern const unsigned char image_recognition_model_data[];
26 | extern const unsigned int image_recognition_model_data_len;
27 |
28 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/stm32f746_discovery/display_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #include
21 |
22 | void init_lcd();
23 |
24 | void display_image_rgb888(int x_dim, int y_dim, const int8_t* image_data,
25 | int x_loc, int y_loc);
26 |
27 | void display_image_rgb565(int x_dim, int y_dim, const uint8_t* image_data,
28 | int x_loc, int y_loc);
29 |
30 | void print_prediction(const char* prediction);
31 |
32 | void print_confidence(int8_t max_score);
33 |
34 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/stm32f746_discovery/image_provider.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #include "image_recognition/image_provider.h"
21 | #include "BSP/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_camera.h"
22 |
23 | TfLiteStatus InitCamera(tflite::ErrorReporter* error_reporter) {
24 | if (BSP_CAMERA_Init(RESOLUTION_R160x120) != CAMERA_OK) {
25 | TF_LITE_REPORT_ERROR(error_reporter, "Failed to init camera.\n");
26 | return kTfLiteError;
27 | }
28 |
29 | return kTfLiteOk;
30 | }
31 |
32 | TfLiteStatus GetImage(tflite::ErrorReporter* error_reporter, int frame_width,
33 | int frame_height, int channels, uint8_t* frame) {
34 | (void)error_reporter;
35 | (void)frame_width;
36 | (void)frame_height;
37 | (void)channels;
38 | BSP_CAMERA_ContinuousStart(frame);
39 | return kTfLiteOk;
40 | }
41 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/stm32f746_discovery/image_util.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #include "image_recognition/stm32f746_discovery/image_util.h"
21 |
22 | void ResizeConvertImage(tflite::ErrorReporter* error_reporter,
23 | int in_frame_width, int in_frame_height,
24 | int num_in_channels, int out_frame_width,
25 | int out_frame_height, int channels,
26 | const uint8_t* in_image, int8_t* out_image) {
27 | // offset so that only the center part of rectangular image is selected for
28 | // resizing
29 | int width_offset = ((in_frame_width - in_frame_height) / 2) * num_in_channels;
30 |
31 | int yresize_ratio = (in_frame_height / out_frame_height) * num_in_channels;
32 | int xresize_ratio = (in_frame_width / out_frame_width) * num_in_channels;
33 | int resize_ratio =
34 | (xresize_ratio < yresize_ratio) ? xresize_ratio : yresize_ratio;
35 |
36 | for (int y = 0; y < out_frame_height; y++) {
37 | for (int x = 0; x < out_frame_width; x++) {
38 | int orig_img_loc =
39 | y * in_frame_width * resize_ratio + x * resize_ratio + width_offset;
40 | // correcting the image inversion here
41 | int out_img_loc = ((out_frame_height - 1 - y) * out_frame_width +
42 | (out_frame_width - 1 - x)) *
43 | channels;
44 | uint8_t pix_lo = in_image[orig_img_loc];
45 | uint8_t pix_hi = in_image[orig_img_loc + 1];
46 | // convert RGB565 to RGB888 and convert from uint8 to int8
47 | out_image[out_img_loc] = (0xF8 & pix_hi) - 128;
48 | out_image[out_img_loc + 1] =
49 | (((0x07 & pix_hi) << 5) | ((0xE0 & pix_lo) >> 3)) - 128;
50 | out_image[out_img_loc + 2] = ((0x1F & pix_lo) << 3) - 128;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/stm32f746_discovery/image_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | #include "tensorflow/lite/c/common.h"
20 | #include "tensorflow/lite/micro/micro_error_reporter.h"
21 | #include "image_recognition/image_dims.h"
22 |
23 | void ResizeConvertImage(tflite::ErrorReporter* error_reporter,
24 | int in_frame_width, int in_frame_height,
25 | int num_in_channels, int out_frame_width,
26 | int out_frame_height, int channels,
27 | const uint8_t* in_frame, int8_t* out_frame);
28 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/image_recognition/util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3 | * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | *
5 | * SPDX-License-Identifier: Apache-2.0
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the License); you may
8 | * not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include "image_recognition/image_dims.h"
24 |
25 | int get_top_prediction(const int8_t* predictions, int num_categories) {
26 | int max_score = predictions[0];
27 | int guess = 0;
28 |
29 | for (int category_index = 1; category_index < num_categories;
30 | category_index++) {
31 | const int8_t category_score = predictions[category_index];
32 | if (category_score > max_score) {
33 | max_score = category_score;
34 | guess = category_index;
35 | }
36 | }
37 |
38 | return guess;
39 | }
40 |
41 | void reshape_cifar_image(uint8_t* image_data, int8_t* signed_image_data) {
42 | int8_t* temp_data = new int8_t[IMAGE_BYTES];
43 | memcpy(temp_data, image_data, IMAGE_BYTES);
44 | int k = 0;
45 | for (int i = 0; i < CHANNEL_SIZE; i++) {
46 | int r_ind = R_CHANNEL_OFFSET + i;
47 | int g_ind = G_CHANNEL_OFFSET + i;
48 | int b_ind = B_CHANNEL_OFFSET + i;
49 | signed_image_data[k] = temp_data[r_ind] - 128;
50 | k++;
51 | signed_image_data[k] = temp_data[g_ind] - 128;
52 | k++;
53 | signed_image_data[k] = temp_data[b_ind] - 128;
54 | k++;
55 | }
56 | delete [] temp_data;
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/mbed-os.lib:
--------------------------------------------------------------------------------
1 | https://github.com/ARMmbed/mbed-os/#14e5d307bb6cdccb554b591ab2602d8d47e0b2d0
2 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/mbed_app.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": ["bare-metal"]
3 | ,"target_overrides": {
4 | "*": {
5 | "target.printf_lib": "std"
6 | }
7 | }
8 | ,"config": {
9 | "main-stack-size": {
10 | "value": 65536
11 | }
12 | }
13 | ,"macros": [
14 | "DISCO_F746NG",
15 | "TF_LITE_DISABLE_X86_NEON",
16 | "TF_LITE_STATIC_MEMORY",
17 | "CMSIS_NN"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/patches/0001-Drivers-patch.patch:
--------------------------------------------------------------------------------
1 | From c40fc5a63981fe5b1cdbf050fb77957398b38348 Mon Sep 17 00:00:00 2001
2 | From: Oscar Andersson
3 | Date: Mon, 19 Jul 2021 15:15:55 +0200
4 | Subject: [PATCH] Drivers patch
5 |
6 | ---
7 | .../BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c | 10 +++++-----
8 | 1 file changed, 5 insertions(+), 5 deletions(-)
9 |
10 | diff --git a/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c b/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
11 | index 527f3aac..e0068782 100644
12 | --- a/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
13 | +++ b/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
14 | @@ -87,11 +87,11 @@ EndDependencies */
15 | /* Includes ------------------------------------------------------------------*/
16 | #include "stm32746g_discovery_lcd.h"
17 | #include "../../../Utilities/Fonts/fonts.h"
18 | -#include "../../../Utilities/Fonts/font24.c"
19 | -#include "../../../Utilities/Fonts/font20.c"
20 | -#include "../../../Utilities/Fonts/font16.c"
21 | -#include "../../../Utilities/Fonts/font12.c"
22 | -#include "../../../Utilities/Fonts/font8.c"
23 | +//#include "../../../Utilities/Fonts/font24.c"
24 | +//#include "../../../Utilities/Fonts/font20.c"
25 | +//#include "../../../Utilities/Fonts/font16.c"
26 | +//#include "../../../Utilities/Fonts/font12.c"
27 | +//#include "../../../Utilities/Fonts/font8.c"
28 |
29 | /** @addtogroup BSP
30 | * @{
31 | --
32 | 2.25.1
33 |
34 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/requirements.txt:
--------------------------------------------------------------------------------
1 | cmake==3.21.0
2 | future==0.18.2
3 | intelhex==2.3.0
4 | mbed-tools==7.27.0
5 | prettytable==2.2.0
6 | wheel==0.37.0
7 |
--------------------------------------------------------------------------------
/tflm-cmsisnn-mbed-image-recognition/test_performance.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright (c) 2019-2021 Arm Limited. All rights reserved.
4 | #
5 | # SPDX-License-Identifier: Apache-2.0
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the License); you may
8 | # not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT
15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 | # Example usages:
20 | # ./test_performance.sh 42 DISCO_F746NG ARM
21 | # ./test_performance.sh 10 NUCLEO_F746ZG GCC_ARM
22 | if ! [ $# -eq 3 ] ; then
23 | echo "Wrong number of arguments (expected 3, SEED, TARGET and TOOLCHAIN)"
24 | exit 1
25 | fi
26 | if ! [[ $1 =~ ^[0-9]+$ ]] ; then
27 | echo "SEED should be a non-negative integer!"
28 | exit 1
29 | fi
30 | if ! [ "$3" = "GCC_ARM" ] && ! [ "$3" = "ARM" ] ; then
31 | echo $3
32 | echo "Invalid toolchain. Should be GCC_ARM or ARM"
33 | exit 1
34 | fi
35 | TARGET=$2
36 | TOOLCHAIN=$3
37 | IMAGE_SIZE=3073
38 | RANDOM=$1
39 | OFFSET=$(( RANDOM % 200 ))
40 | BYTES_OFFSET=$(( OFFSET * 153650 ))
41 | xxd -s $BYTES_OFFSET -l 153650 -i test_batch.bin image_recognition/50_cifar_images.h
42 | sed -i -E "s/unsigned char/const unsigned char/g" image_recognition/50_cifar_images.h
43 | mbedtools configure -m $TARGET -t $TOOLCHAIN -o cmake_build/$TARGET/release/$TOOLCHAIN/
44 | cmake -S . -B cmake_build/$TARGET/release/$TOOLCHAIN -DCMAKE_BUILD_TYPE=RELEASE -DMAINFILE=test -GNinja
45 | ninja -C cmake_build/$TARGET/release/$TOOLCHAIN
46 |
47 |
48 |
--------------------------------------------------------------------------------
/tflu-kws-cortex-m/README.md:
--------------------------------------------------------------------------------
1 | # Deprecation notice
2 |
3 | This repository is now deprecated and the code previously contained here has been moved to other places.
4 |
5 | To find the models along with code to recreate and evaluate them please visit the Arm ML-Zoo [here](https://github.com/ARM-software/ML-zoo/tree/master/models/keyword_spotting)
6 | where you will find new model packages that contain all the relevant models and code that were previously contained here.
7 |
8 | To deploy the Keyword spotting models to Microcontrollers, including virtual targets, please now refer to our new code
9 | [here](https://github.com/ARM-software/ML-examples/tree/main/cmsis-pack-examples)
10 | where we have made deployment even easier.
11 |
--------------------------------------------------------------------------------
/yeah-world/README.md:
--------------------------------------------------------------------------------
1 | # Yeah World!
2 | A simple set of scripts to explore gesture recognition with TensorFlow and transfer learning on the Raspberry Pi 4, Pi 3 and Pi Zero.
3 |
4 | ## Getting started
5 |
6 | This is the example code used in Arm's [Raspberry Pi gesture recognition walkthrough](https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/teach-your-raspberry-pi-yeah-world) - full installation and usage instructions can be found there.
7 |
8 | *Note: These example scripts are designed to be easy to read and follow, not to demonstrate state-of-the-art or best practice.*
9 |
10 | ## Dependencies
11 |
12 | From a base Raspian install you will need to add TensorFlow:
13 |
14 | # TensorFlow dependencies
15 | sudo apt-get install libblas-dev liblapack-dev python-dev libatlas-base-dev gfortran python3-setuptools python3-h5py
16 |
17 | # Pi Zero
18 | sudo pip3 install https://storage.googleapis.com/tensorflow/raspberrypi/tensorflow-1.14.0-cp34-none-linux_armv6l.whl
19 |
20 | # Pi 3 (Raspbian 9) or Pi 4 Model B(Raspbian 10)
21 | sudo pip3 install --upgrade tensorflow
22 | # On a low memory Pi, you will probably get a "Memory Error" error message during installation. Instead, please use the command below.
23 | sudo pip3 install --no-cache-dir tensorflow
24 |
25 | ## Example
26 |
27 | Check out the [full gesture recognition walkthrough](https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/teach-your-raspberry-pi-yeah-world). If you just need to be reminded about the syntax supported by the example scripts, read on.
28 |
29 | Make sure the camera can see you (the rotation doesn't really matter):
30 |
31 | python3 preview.py
32 |
33 | Clear the DISPLAY environment variable before proceeding to improve the frame rate, especially on a Pi Zero:
34 |
35 | unset DISPLAY
36 |
37 | Record 15 seconds of video of yourself cheering and save it as example/yeah:
38 |
39 | python3 record.py example/yeah 15
40 |
41 | Record 15 seconds of video of yourself sitting and save it as example/sitting:
42 |
43 | python3 record.py example/sitting 15
44 |
45 | Record 15 seconds of video of random behaviour (walking around, covering the camera, scratching your head):
46 |
47 | python3 record.py example/random 15
48 |
49 | Train a model to distinguish between cheering (category 0), sitting (category 1) and random (category 2):
50 |
51 | python3 train.py example/model.h5 example/yeah example/sitting example/random
52 |
53 | Run a trained model and play random sounds from sounds/ when category 0 is detected:
54 |
55 | python3 run.py example/model.h5
56 |
--------------------------------------------------------------------------------
/yeah-world/camera.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """
13 | A simple wrapper around PiCamera that can randomly vary the exposure and
14 | white balance during image capture as a form of data augmentation.
15 | """
16 | from builtins import next
17 | from builtins import object
18 | from time import sleep
19 | from random import choice, uniform
20 |
21 | from picamera.array import PiRGBArray
22 | from picamera import PiCamera
23 |
24 |
25 |
26 | class Camera(object):
27 | """ A simple PiCamera wrapper. Setting training_mode will randomly vary
28 | exposure and white balance between captured images. The capture stream
29 | is truncated before capture to reduce recognition latency at the expense
30 | of frame rate. """
31 | def __init__(self, training_mode):
32 | self.training_mode = training_mode
33 | self.camera = PiCamera()
34 | self.camera.resolution = (128, 128)
35 | self.camera.framerate = 30
36 | self.capture = PiRGBArray(self.camera, size=self.camera.resolution)
37 | self.stream = self.camera.capture_continuous(self.capture,
38 | format='rgb',
39 | use_video_port=True)
40 | if training_mode:
41 | # We allow picamera's auto exposure settings to settle for 5 seconds then we
42 | # lock them so they don't change in response to actions as this can cause problems.
43 | # If waving your hands causes the camera to shift its exposure settings during training
44 | # as then the network will likely learn to detect the exposure setting not your hands!
45 | sleep(5)
46 | self.camera.shutter_speed = self.camera.exposure_speed
47 | self.camera.exposure_mode = 'off'
48 | self.base_awb = self.camera.awb_gains
49 | self.camera.awb_mode = 'off'
50 |
51 |
52 | def next_frame(self):
53 | """ Capture a frame from the camera. By truncating the frame buffer we
54 | exchange FPS for lower latency. When responding to gestures latency is
55 | more important to the user experience. """
56 | self.capture.truncate(0)
57 | if self.training_mode:
58 | self.camera.iso = choice([100, 200, 320, 400, 500, 640, 800])
59 | awb_r = max(0., uniform(-.5, .5) + self.base_awb[0])
60 | awb_b = max(0., uniform(-.5, .5) + self.base_awb[1])
61 | self.camera.awb_gains = (awb_r, awb_b)
62 |
63 | frame = next(self.stream).array
64 | return frame
65 |
--------------------------------------------------------------------------------
/yeah-world/mnet.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/yeah-world/mnet.pb
--------------------------------------------------------------------------------
/yeah-world/pinet.py:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | """ Provides PiNet, a MobileNet-based feature extractor loaded from TensorFlow.
13 | This loads many times faster than when using keras.applications, which can take
14 | several minutes on a Pi Zero. """
15 | from __future__ import print_function
16 |
17 |
18 | from builtins import object
19 | import tensorflow as tf
20 | import numpy as np
21 |
22 |
23 |
24 | class PiNet(object):
25 | """ Load a feature extractor and provide a convenience function for 1-batch
26 | preprocessing and inference """
27 | def __init__(self):
28 | with tf.io.gfile.GFile('mnet.pb', 'rb') as f:
29 | graph_def = tf.compat.v1.GraphDef()
30 | graph_def.ParseFromString(f.read())
31 |
32 | with tf.Graph().as_default() as graph:
33 | tf.import_graph_def(graph_def)
34 |
35 | self.x = graph.get_operations()[0].outputs[0]
36 | self.y = graph.get_operations()[-1].outputs[0]
37 | self.session = tf.compat.v1.Session(graph=graph)
38 | _ = self.features(np.zeros((128, 128, 3))) # warm up
39 |
40 | def features(self, image):
41 | """ Image should be a numpy array of shape width, height, channels.
42 | The mnet.pb feature extractor expects 128, 128, 3 in RGB format
43 | Returns a (4, 4, 256) numpy array representing high-level features """
44 |
45 | preprocessed = ((np.array(image, dtype=np.float32) / 255.) - 0.5) * 2.
46 | features = self.session.run(self.y, feed_dict={self.x: [image]})[0]
47 | return features
48 |
49 |
50 | if __name__ == '__main__':
51 | darkness = np.zeros((128, 128, 3)) # NWHC
52 | net = PiNet()
53 | z = net.features(darkness)[0]
54 | print(z.shape)
55 | print(z)
56 |
--------------------------------------------------------------------------------
/yeah-world/preview.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """
15 | Show a camera preview using the same resolution and FPS settings
16 | as will be used for training, but without randomly adjusting
17 | the exposure (training_mode=False). Enable this to see what it does.
18 | """
19 |
20 | from sys import stderr
21 | from time import time
22 |
23 | import pygame
24 | from camera import Camera
25 |
26 |
27 | def main():
28 | camera = Camera(training_mode=False)
29 | pygame.display.init()
30 | pygame.display.set_caption("PiCamera preview")
31 | screen = pygame.display.set_mode((512, 512))
32 |
33 | while True:
34 | total = time()
35 | frame = camera.next_frame()
36 | surface = pygame.surfarray.make_surface(frame)
37 | screen.blit(pygame.transform.scale(surface, (512, 512)), (0, 0))
38 | pygame.display.flip()
39 |
40 | for evt in pygame.event.get():
41 | if evt.type == pygame.QUIT:
42 | pygame.quit()
43 | break
44 |
45 | total = time() - total
46 | stderr.write("\r%4.0f ms per frame, %2.1f FPS " % (total*1000, 1.0/total))
47 |
48 | if __name__ == '__main__':
49 | main()
50 |
--------------------------------------------------------------------------------
/yeah-world/randomsound.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """
15 | Provides RandomSound, a simple way to play a random sound file from a
16 | directory using pygame.
17 | """
18 |
19 | from builtins import object
20 | from os.path import join
21 | from glob import glob
22 | from random import choice
23 | from time import sleep
24 |
25 | from pygame import mixer
26 |
27 |
28 |
29 | class RandomSound(object):
30 | """ A simple way to play random sound files """
31 | def __init__(self):
32 | mixer.init()
33 | self.playing = None
34 |
35 | def play_from(self, path):
36 | """ Play a random .wav file from path if none is currently playing """
37 | if mixer.music.get_busy() and self.playing == path:
38 | return
39 |
40 | filename = choice(glob(join(path, '*.wav')))
41 | mixer.music.load(filename)
42 | mixer.music.play()
43 | self.playing = path
44 |
45 | def wait(self):
46 | """ Wait for the current sound to finish """
47 | while mixer.music.get_busy():
48 | sleep(0.1)
49 |
50 | def stop(self):
51 | """ Stop any playing sound """
52 | mixer.music.stop()
53 |
54 |
55 | def main():
56 | """ Play a single sound and wait for it to finish """
57 | from sys import argv
58 | rs = RandomSound()
59 | rs.play_from(argv[1])
60 | rs.wait()
61 |
62 |
63 | if __name__ == '__main__':
64 | main()
65 |
--------------------------------------------------------------------------------
/yeah-world/sounds/1_person_cheering-Jett_Rifkin-1851518140.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/yeah-world/sounds/1_person_cheering-Jett_Rifkin-1851518140.wav
--------------------------------------------------------------------------------
/yeah-world/sounds/5_Sec_Crowd_Cheer-Mike_Koenig-1562033255.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/yeah-world/sounds/5_Sec_Crowd_Cheer-Mike_Koenig-1562033255.wav
--------------------------------------------------------------------------------
/yeah-world/sounds/Applause-SoundBible.com-151138312.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ARM-software/ML-examples/a6434d5f6f6a187a3d84289e18033b2c03d0f41d/yeah-world/sounds/Applause-SoundBible.com-151138312.wav
--------------------------------------------------------------------------------
/yeah-world/sounds/README.md:
--------------------------------------------------------------------------------
1 | Attribution:
2 | 1_person_cheering-Jett_Rifkin-1851518140.wav - Jett Rifkin, http://soundbible.com/2103-1-Person-Cheering.html
3 | Applause-SoundBible.com-151138312.wav - Mike Koenig, http://soundbible.com/988-Applause.html
4 | 5_Sec_Crowd_Cheer-Mike_Koenig-1562033255.wav - Mike Koenig, http://soundbible.com/1700-5-Sec-Crowd-Cheer.html
5 |
6 | More are available for personal use from http://soundbible.com/suggest.php?q=cheer
7 |
8 |
--------------------------------------------------------------------------------