BitNetMCU project enables machine learning on CH32V003 RISC-V MCU

Machine Learning


Neural networks and other machine learning processes are often associated with powerful processors and GPUs. However, as we have seen on this page, AI is also moving to the cutting edge, and the BitNetMCU open source project further demonstrates that low-end RISC can be used to train and run low-bit quantized neural networks for inference. Masu. An inexpensive V microcontroller such as CH32V003.

Note that CH32V003 is based on the QingKe 32-bit RISC-V2A processor, which supports two levels of interrupt nesting. It is a compact, low power, general purpose 48MHz microcontroller with 2KB SRAM with 16KB Flash. The chip is available in TSSOP20, QFN20, SOP16, or SOP8 packages.

CH32V003 Machine Learning

To run machine learning on the CH32V003 microcontroller, the BitNetMCU project performs quantization-aware training (QAT) to fine-tune the inference code and model structure. This allows over 99% test accuracy on the 16×16 MNIST dataset without using anything. Multiplication instruction. This performance is impressive considering the 48 MHz chip only has 2 kilobytes of RAM and 16 kilobytes of flash memory.

The training data pipeline for this project is based on PyTorch and consists of several Python scripts that can be run on any microcontroller. These include:

  • training parameters.yaml Configuration file to set all parameters of the training model
  • training.py The Python script trains the model and saves it as a .pth file in the model data folder (weights are saved as floats and quantized on the fly during training).
  • exportquant.py The quantized model export file converts the saved trained model to quantized format and exports it to a C header file (BitNetMCU_model.h).
  • option test reasoning.py A script that calls the DLL (compiled from the inference code) to test the results and compare them to the original Python model

BitNetMCU project structure for quantized neural networks

The inference engine (BitNetMCU_inference.c) is implemented in ANSI-C and can be ported to the CH32V003 RISC-V MCU or other microcontrollers. You can test 10-digit inference by compiling and running BitNetMCU_MNIST_test.c. The model data is located in the BitNetMCU_MNIST_test_data.h file and the test data is located in the BitNetMCU_MNIST_test_data.h file. You can try machine learning with CH32V003 by reviewing the code and following the instructions in the readme.md file on GitHub.

Support CNX Software! Donate in cryptocurrency, become a patron on Patreon, or buy on Amazon or Aliexpress



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *