This project develops and deploys an effective deep-learning model on a Cortex-M4 microcontroller - Sony Spresense for real-time traffic light image classification. The model, successfully trained and quantized for on-device deployment, delivers an accuracy of 90%, and 500ms latency.
| MobilenetV1 | Accuracy | Memory Usage | Latency |
|---|---|---|---|
| Original | 99% | 14 MB | N/A |
| Pruned 85% | 95% | 0.55MB5 | .8 s |
| Pruned 85% + Quant | 90% | 0.21 MB | .55 s |
To install the required dependencies, follow these steps:
- Clone this repository:
git clone https://github.com/MIC-Laboratory/On-device-CNN- Navigate to the project directory:
cd On-device-CNN- Install the dependencies:
pip install -r requirements.txtTo use this project, follow these steps:
-
Configure the training parameters:
- Open the config.yaml file and set the desired hyperparameters such as batch size, learning rate, and number of epochs.
- Modify other settings such as model type, dataset path, and output directory if needed.
-
Train the model:
- Run the training script:
python training.py
- Monitor the training progress and observe the log output.
- Run the training script:
-
Generate C header file
- Run OnDeviceDepolyment.py
python OnDeviceDepolyment.py
It will generate Onnx model files, TensorFlow model files, and a C header file. We need to import the C header file on Arduino in order to access our model on microcontroller
- Run OnDeviceDepolyment.py
-
Flash the Arduino .ino file to the microcontroller.
-
Run the listener.py file to start the real-time traffic light classification.
This project includes the following pre-defined models:
The model is defined in separate Python files - mobilenetv1.py
We welcome contributions from the community to improve this project. If you encounter any issues or have suggestions for enhancements, please feel free to submit a pull request or open an issue on the GitHub repository.
This project is licensed under the MIT License.
