This repository has become obsolete as the latest version of the toolkit is now available in this repository.
Copyright (c) 2018 ETH Zurich, Ferdinand von Hagen, Michele Magno, Lukas Cavigelli
This repository contains optimized code to perform inference of FANN-trained neural network on the ARM Cortex M-series platform.
Given a data file and pre-trained network in FANN's format, all necessary files to run and test the network on the microcontroller are generated.
You should have data and a pre-trained network in the FANN format. To run the script, python2 needs to be installed. This code has been tested with the MSP432 platform.
First, you need to export your data in the FANN default format
and train a neural network with FANN. How to do this is
explained here.
You should end up with two files, a .data
file and a .net
file.
An example can be found in the sample-data
folder.
Then, you can use the generate.py
script to generate the
files to run on the microcontroller, e.g.
python2 generate.py sample-data/myNetwork
Now all the *.h and *.c files can be copied to you project.
They include all the data and code to run the network.
To call it from your code, just include fann.h
and call
fann_type *fann_run(fann_type * input);
, where
fann_type
is float
or int
depending on whether you started
with a fixed-point model or not. Don't forget to include the files
in your build scripts/makefile/project.
Constant files:
generate.py
: the script generating the network and data-specific code files based an FANN-format datafann_structs.h
andfann.c
: contain the implementation of the NN building blocks.fann.h
: the header file to be included in your code providing thefann_type *fann_run(fann_type * input);
function declaration.sample-data/{myNetwork.net, myNetwork.data}
: sample data and network pre-trained with FANN.
Generated files:
fann_net.h
: contains the trained parameters and the network structure.fann_conf.h
: contains some more meta information on the network; #layers, fixed-point parameters (if applicable), ...test_data.h
: contains the test input data and expected result
Please refer to the LICENSE file for the licensing of our code. We rely on the interfaces, specifications, and some code of the FANN project.