This repository contains the k2arm software framework, related code and the presentation from the "Forum Künstliche Intelligenz" talk in Stuttgart , 14.05.2019.
The k2arm software framework can be used to translate a custom keras model into C-code. The generated C-code can, in combination with the ARM-CMSIS-NN functions, be used to run neural-net calculations in an efficient way on an embedded microcontroller such as the Cortex-M4. Those generated networks are compared to networks which are generated with the x-Cube-AI tool from ST.
Three different sized MNIST classifiers are compared, the results are included in the presentation.
-
Following additional software and versions is required:
- ubnntu 18.04
- python 3.6
- tensorflow 1.10.0
- keras version 2.2.4
- STM32CubeMX
- X-Cube-AI
- arm-none-eabi-gcc 6.3.1
-
Follwoing hardware is required:
-
Checkout the repository
git clone https://github.com/InES-HPMM/k2arm.git
- Build stlink
cd k2arm/ST/stlink
make
- Switch into the ARM host directory and generate the C-code with the k2arm framework
cd ../../ARM/host/
python3 generateCMSISCode.py
- Switch into the target directory and build the firmware
cd ../target/
make
- Connect the STM32F4-Discovery board to your computer, and flash the firmware
sudo ../../ST/stlink/build/Release/st-flash --format ihex write ./build/k2arm.hex
- Switch into the top level dir
cd ../..
- Open the file
eval.py
and adjust the settings serDev and modelPath
serDev = '/dev/ttyUSB1'
modelPath = 'models/modelMid/model.keras'
- Connect the serial device
PA0-WKUP Board ------> TX Serial device host
PA1 Board ------> RX Serial device host
GND Board ------> GND host
- Tun the evaluation script:
python3 eval.py
- To measure the run-time of the neural net connect the GPIO
PIN0
ofGPIOB
to an oscilloscope
- Start STM32CubeMX
- In the section
File
chose the option toLoad Project
and select the file:ST/St.ioc
- In the section
Additional Software
chose the desired network in thenetwork
section, then pressGENERATE CODE
- Go into the ST dir and checkout the wrong changed files (Makefile and application code)
cd ST/
git checkout Src/main.c Src/app_x-cube-ai.c Inc/app_x-cube-ai.h Makefile
- Build the firmware
make
- Connect the STM32F4-Discovery board to your computer, and flash the firmware
sudo ./stlink/build/Release/st-flash --format ihex write ./build/ST.hex
- Switch into the top level dir
cd ..
- Open the file
eval.py
and adjust the settings
serDev = '/dev/ttyUSB1'
modelPath = 'models/modelL/model.keras'
- Connect the serial device
PA0-WKUP Board ------> TX Serial device host
PA1 Board ------> RX Serial device host
GND Board ------> GND host
- Run the evaluation script
python3 eval.py
- To measure the run-time of the neural net connect the GPIO
PIN0
ofGPIOB
to an oscilloscope