This project explores the implementation of Deep Neural Networks (DNNs) on the VSDSquadron Pro board powered by the SiFive-HiFive-1 FE310-G002 microcontroller.
Target Specification:-
- Development Board:- VSDSquadron Pro
- IC:- SiFive FE310-G002
- Frequency :- 320 MHz
- SRAM :- 16 kb
- SPI Flash :- 32 Mb
- Architecture:- rv32imac_zicsr_zifencei
- Tool Suit:- riscv64-unknown-elf-toolsuite-2.0.3
- Software Used- Sifive Freedom Studio
This approach leverages model compression to enable the deployment of compact models on constrained hardware like the VSDSquadron Pro.
- Supports any model with dense (fully-connected) and ReLU layers.
- Models can be generated using PyTorch.
- Both self-generated and pre-trained models with dense and ReLU layers are deployable.
- Generate a model using BitNet MCU model generation
- Example: An MNIST Classification project demonstrates this.
- Copy the generated model file to the source folder of the SiFive BitNet MCU project.
- Update the SiFive_BitNET_MCU.c file to point to the correct model.
- Open the project in SiFive Freedom Studio and debug using its inbuilt compiler.
To classify handwritten digits (MNIST dataset), compress a dense neural network with ReLU layers using BitNet. This results in a small model deployable within the memory limits of the VSDSquadron Pro board.
The BitNet approach focuses on compact and efficient neural network deployment, making it ideal for applications with constrained resources:
- Wearable Devices: Fitness trackers for activity recognition and calorie counting.
- IoT Sensors: Smart home devices with speech keyword spotting and real time Optical Character Recognizer(OCR)
- Industrial Monitoring: Lightweight systems for detecting anomalies in equipment operations.
Note: This is under development and not yet fully deployable.
This approach facilitates the prediction of models with various layer types using the TensorFlow Lite Micro library.
- Compatible with models containing all standard layers and activations supported by Tensorflow.
- Uses TensorFlow in Python to create models and compress them into .tflite format.
- Deploys models constrained by SRAM and flash size.
Current challenges include limitations in the tool suite’s floating-point library. View the complete error log here.
- Generate your model using TensorFlow in Python.
- Example: TFLM sine wave prediction.
- Convert the model to .tflite format using TensorFlow's TFLite Model Maker.
- Use the tflite_to_c.py script to create model.cc and model.h files.
- Copy the .cc and .h files into the project's source folder.
- Generate a micro resolver for the model using micro_op_resolver.
- Update the main.cpp file to import the correct model and resolver.
- Add the TensorFlow Lite library directory to the project path.
- Open the project in SiFive Freedom Studio and update the makefile to resolve imports.
Example Makefile Updates :-
...
#############################################################
# Software
#############################################################
PROGRAM_ELF ?= $(SRC_DIR)/$(CONFIGURATION)/$(PROGRAM).elf
PROGRAM_HEX ?= $(SRC_DIR)/$(CONFIGURATION)/$(PROGRAM).hex
PROGRAM_LST ?= $(SRC_DIR)/$(CONFIGURATION)/$(PROGRAM).lst
.PHONY: all
all: software
.PHONY: software
software: $(PROGRAM_ELF)
software: $(PROGRAM_HEX)
tflm_dir= $(PWD)/tflite
PROGRAM_SRCS = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*.h) $(wildcard $(SRC_DIR)/*.hpp) $(wildcard $(SRC_DIR)/*.S)$(wildcard $(SRC_DIR)/*.cpp)$(wildcard $(SRC_DIR)/*.cc)
TFLM_INCLUDE_DIRS := $(shell find $(tflm_dir) -type d)
#RISCV_CFLAGS += -lgcc -lc -msoft-float
RISCV_CXXFLAGS += -lgcc -lc
RISCV_LDLIBS += -L$(tflm_dir) -ltflite
RISCV_LDFLAGS += $(addprefix -I, $(TFLM_INCLUDE_DIRS))
RISCV_LDFLAGS += -fno-rtti
Below is a snippet showcasing essential additions to the makefile: TFLM extends the capability to more complex models, supporting diverse layers and larger datasets, suitable for:
- Edge AI Cameras: Real-time object detection and facial recognition in security systems.
- Healthcare Gadgets: Devices like portable ECG or blood oxygen level monitors using AI for diagnostics.
- Consumer Electronics: Voice assistants and gesture-controlled devices in smart environments.