/k2arm

Contains the k2arm framework, results and slides from the presentation at Forum Künstliche Intelligenz

Primary LanguageCGNU General Public License v3.0GPL-3.0

k2arm - Forum Künstliche Intelligenz

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.

Requirements and Preparation

  1. 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
  2. Follwoing hardware is required:

  3. Checkout the repository

git clone https://github.com/InES-HPMM/k2arm.git
  1. Build stlink
cd k2arm/ST/stlink
make

Reproduce k2arm Measurements

  1. Switch into the ARM host directory and generate the C-code with the k2arm framework
cd ../../ARM/host/
python3 generateCMSISCode.py
  1. Switch into the target directory and build the firmware
cd ../target/
make
  1. 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
  1. Switch into the top level dir
cd ../..
  1. Open the file eval.py and adjust the settings serDev and modelPath
serDev = '/dev/ttyUSB1'
modelPath = 'models/modelMid/model.keras'
  1. Connect the serial device
PA0-WKUP Board ------> TX Serial device host
PA1      Board ------> RX Serial device host
GND      Board ------> GND host
  1. Tun the evaluation script:
python3 eval.py
  1. To measure the run-time of the neural net connect the GPIO PIN0 of GPIOB to an oscilloscope

Reproduce X-Cube-AI Measurements

  1. Start STM32CubeMX
  2. In the section File chose the option to Load Project and select the file: ST/St.ioc
  3. In the section Additional Software chose the desired network in the network section, then press GENERATE CODE
  4. 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
  1. Build the firmware
make
  1. Connect the STM32F4-Discovery board to your computer, and flash the firmware
sudo ./stlink/build/Release/st-flash --format ihex write ./build/ST.hex
  1. Switch into the top level dir
cd ..
  1. Open the file eval.py and adjust the settings
serDev = '/dev/ttyUSB1'
modelPath = 'models/modelL/model.keras'
  1. Connect the serial device
PA0-WKUP Board ------> TX Serial device host
PA1      Board ------> RX Serial device host
GND      Board ------> GND host
  1. Run the evaluation script
python3 eval.py
  1. To measure the run-time of the neural net connect the GPIO PIN0 of GPIOB to an oscilloscope