This project containts a Tiny ML (WML) framework and an example of its use. The project is written on plain C and developed to be used on baremetal systems with FPU.
File structure of the project:
- wml — contains header and source files of WML framework
- main.c — the entry point of the project, containts unit tests and examples
- Makefile — the root makefile of the project
- refs — python files with reference code of training and testing neural network with pytorch
WML is a Tiny ML framework by Worm. It contains:
- wml_mat — representation of Matrix and implementation of operations with it
- wml_utils — collection of utilities (stack memory allocator, random generator, etc)
- wml_layers — representation of layers of neural network (Linear, ReLU, Softmax)
- wml_data_loader — implementation of dataloaders (from array, from file)
- wml_plot — a wrapper over
gnuplot
WML allows to train and use neural networks (NN) on microcontrollers and CPUs. For NN training the availability of FPU is mandatory.
To build project on Unix system you need to follow the next steps:
- Edit
main()
function inmain.c
file and uncomment one of functions (unit_tests, iris, mnist). Also you can change hyperparameters in the appropriate function. - Download MNIST dataset (for MNIST example only) by executing
./dl_mnist.sh
. - Execute
make
in root directory. - Start training and testing by executing
./bld/prog
.
As a result you will train and test the model and will see its accuracy.
NOTE:
The Makefile
by default does debug build and use GCC sanitizers. This allows
to make robust project but consumes CPU time. You can modify Makefile
to
change this.
To test parts of WML you can run unit_tests:
- Edit
main()
function inmain.c
file and uncommentunit\_tests()
function. - Build the project by executing
make
. - Run the tests by executing the application
./bld/prog
.
As a result unit test will be completed.
The first example project is NN with one hidden layer and Fisher Iris dataset. The NN classifies Irises by its dementions and reaches 100% accuracy.
The dataset is embedded in the header file wml_ds_iris.h
.
To reproduce Iris example follow the next steps:
- Edit
main()
function inmain.c
file and uncommentiris()
function. - Build the project by executing
make
. - Run the tests by executing the application
./bld/prog
.
The second example project is NN with two hidden layers and MNIST dataset. The NN classifies pictures of digits and reaches accuracy about 94%.
The dataset should be loaded by script dl_mnist.sh
.
To reproduce MNIST example follow the next steps:
- Edit
main()
function inmain.c
file and uncommentmnist()
function. - Download MNIST dataset by executing the script
./dl_mnist.sh
- Build the project by executing
make
. - Run the tests by executing the application
./bld/prog
.
NOTE:
The training process can take about 2 hours.
Sergey Worm, sergey.worm@gmail.com