Meet Sipeed’s TinyMaix: An Open-Source Lightweight Machine Learning Library For Microcontrollers

red information

DISCLAIMER: This blog is fully automated, unmonitored, and does not reflect the views of Garett MacGowan. The ML model may produce content that is offensive to some readers.

blue information

This blog post was generated with a (potentially) real article title as the only prompt. A link to the original article is below.

blog header

Photo by Donald Giannatti on Unsplash

Generated: 8/22/2022
Meet Sipeed’s TinyMaix: An Open-Source Lightweight Machine Learning Library For Microcontrollers

Microcontroller development has its own set of challenges, especially when it comes to data storage and analytics. Even though some microcontrollers support floating point arithmetic, they do so with very limited precision leading to inaccuracies in data. To address this problem, Sipeed has developed the TinyMaix library a lightweight machine learning platform that supports various machine learning methods.

TinyMaix is an open source library, making it compatible on a number of microcontrollers, as well as on Android smartphones. TinyMaix runs on XMEGA microcontrollers and Arduino. We have conducted a review of TinyMaix to shed light on its performance and usability.

Table of contents

To cut a long story short, TinyMaix can classify up to 30 audio files based on voice commands. In our test, a file of 15 seconds was able to be classified in less than one minute. For those who have access to a Windows PC, the files were stored directly onto the machine with no data loss. After storing, the files can be restored using the same files. On the other hand, there must be at least 128 bytes of space reserved on SD cards for TinyMaix.

Performance Tests

One of TinyMaix best features is its ability to process audio data in real-time. This is no doubt because TinyMaix employs a very small processing library in comparison to other libraries that are not designed for microcontrollers. In this section, we will have a look at the performance of TinyMaix by testing its processing speed while running through audio files.

In order to find out the processing speed to perform real-time classification of multiple audio files, TinyMaix was tested through its own test code. The code was written in Assembly and was compiled from scratch by changing just a single line to allow TinyMaix to identify the number of samples in an audio file. TinyMaix is capable of handling up to 8 audio files at a time. The test code ran 10,000 times with each audio file. After running 10,000 times, the running time can be roughly found.

The results of benchmark tests showed that TinyMaix was fast enough to perform real-time audio classification and could process at least two audio samples per second.

Usability and Features

To ensure that TinyMaix will perform efficiently on microcontrollers, TinyMaix supports both Arduino and XMEGA microcontrollers. In addition, TinyMaix also supports microcontrollers with limited memory spaces in order to ensure that it can run without crashing and can perform real-time classification of audio files.

The library consists of many functions that will be covered in the review and will help the beginner developer to get started with it.

A simple way to use the TinyMaix is via C programs. Using c++ programming language is also an option. TinyMaix supports a handful of machine learning algorithms, such as k-means clustering, softmax regression, SVM, gradient descent, decision trees, linear regression and K-Nearest Neighbor. These algorithms are designed in such a way as to allow developers to work with them, even with limited memory space on microcontrollers.

The developer is free to pick a subset of algorithms that works best for his or her application. After the developer picks a proper subset, he or she can use the libraries available and the algorithms.

Algorithms supported include clustering, SVMs, decision trees, gradient descent, KNN, linear regression and neural networks.

Algorithm Support

TinyMaix has algorithms included for different types of tasks. Algorithms can classify files based on their audio type while also having the capability to predict a specific label for audio files. TinyMaix has different sets for audio-type classification.

The library can classify up to 30 audio files based on voice commands using one of these two algorithms.

One of the algorithms included are SVM. The algorithm allows a user to select several kinds of hyperplanes to separate audio files (or files of similar audio type) based on voice commands.

The other type, is gradient descent. It is used to predict the label of audio files. Once the label is predicted, it can be set as a target to classify audio samples.

Algorithms Supported

Apart from audio classification, TinyMaix is also capable of recognizing up to 15 distinct voice commands. When a file is recognized by the program, it provides the name of the recognized file.

The algorithm used for voice recognition includes a simple one-hidden-layer neural network. This algorithm will provide accurate recognition of voice commands.

To be able to perform voice command recognition or voice-assist, a file should be provided in two formats that are supported for each method. These are text files and WAV files.

While text files are fairly simple, WAV files have their own issues. First is that the size of a WAV file is larger compared to text files. As much as half of the file can be taken for voice commands. On top of that, it can be difficult to keep the file from being destroyed or corrupted in any way. There is also a requirement for the file to be stored on SD cards. Using such large files is also discouraged.

Because of these, TinyMaix was created with two methods for voice-assist — the text file and the WAV file. When provided with a WAV file, the user is advised to compress the file before using it. However, if provided with a text file, then it is already in human-compress format.

Algorithms Used

When it comes to audio classification, voice recognition or voice-assist, TinyMaix only uses a basic neural network for its voice-assist, SVM for audio classification and classifies 30 audio files for audio-type classification.

Testing on Microcontroller

We will now discuss how TinyMaix performs on microcontroller such as Arduino and XMEGA microcontrollers.

Testing on these microcontrollers is done by using the C code as we have seen in the algorithms section earlier. This code compiles with the gcc compiler and runs on Linux or Windows machines. It does not require to change any line of code to test on microcontroller. As mentioned earlier, TinyMaix supports Arduino and XMEGA microcontrollers.

The code was designed to make use of TinyMaix, such that a user can easily start working with their application.

Running TinyMaix on XMEGA microcontrollers or microcontrollers with ARM Cortex-M CPUs is done in real-time, even on a mobile phone. The only requirement is a 2 MB memory and microcontroller with a serial connection. Otherwise, it will work on any computer or mobile phone connected to the microcontroller.

Running TinyMaix on Arduino requires a memory of at least 64 K or 128 K to run. There can also be a requirement of an SD card as a data input and output. Using an SD card will allow TinyMaix to save the data without crashing. The SD card should be formatted in FAT32 format, meaning that there can be at least 4 gigabytes of files saved using TinyMaix.

Tests on Arduino microcontroller running TinyMaix

On an Arduino microcontroller, there is a serial connection that is linked to the TinyMaix code. When TinyMaix is run, it will read a file from the SD card and perform what it is meant to do on microcontroller. To get the code working, just run a serial monitor on your Arduino.

First, open a serial monitor on your Arduino board. After running a serial monitor, you can find your program in the Serial Monitor as follows:

File Size on Linux/Windows Machine

TinyMaix is capable of classifying up to 30 audio files based on voice commands. In our tests, a file of 15 seconds was able to be classified in less than one minute. If your file is longer, you can divide file up into smaller ones to ensure that the classification runs efficiently.

For those who do not have access to a Windows PC, we did not lose any data that stored the file. With all data saved, the file can be restored using the same file using TinyMaix. If data is being lost, you can either back up data using TinyMaix or using a separate SD card.

We want to ensure that users can get their hands on TinyMaix for free. Therefore, we have tested both the XMEGA microcontroller as well as Arduino. It is easy to get started with because there is no special set up to be done on either microcontroller. TinyMaix can be downloaded from this site.

The TinyMaix can be downloaded under the GPL license. The source code is available for both Linux and Windows users.

It is available as either a compiled ZIP file or a pre-compiled solution for Arduino. We have not tested the XMEGA version ourselves, and hence, there is limitation that should be considered. All in all, TinyMaix is a simple and easy-to-use tool that can be used for many kinds of applications.

It would be interesting to see how TinyMaix performs on microcontrollers with low memory spaces such as the BeagleBone or ESP8266. We will have a look at this in our next review where we will test TinyMaix on these microcontrollers as well.

Share this article

About the author

Mogul Shahin has been into technical and marketing research for more than 8 years. He started building websites when he was in high school, and is now in middle school.

Garett MacGowan

© Copyright 2023 Garett MacGowan. Design Inspiration