DietCNN is a Python and PyTorch based Deep Neural Network library that provides multiplication-free CNN inference. Pre-trained CNN models can be transformed or re-trained to make those multiplication-free. It works best for embedded systems, that is with smaller networks and datasets. Direct benefits are: inference energy reduction and model size reduction.
How multiplications are avoided? DietCNN provides a method to operate on the Quantization symbols (a sort of name given to each quantization centroids) instead of their actual values. This allows pre-computing of multiplication offline and only the use of lookups at inference time
Please have a look at A-Sample-Code-Walkthrough-MNIST-LeNet-full (code) , for an overall idea of how a network is converted to DietCNN, end-to-end. This also covers all the experiments. There is a similar file for each of the dataset-network combination e.g. CIFAR10-VGG Experiments (code)
Step 1: create basic virtual env:
sudo apt install python3.8-venv
python3 -m venv dietcnn
source dietcnn/bin/activate
pip install -r dietcnn_base.txt
cd MNIST_LENET
All directories have the same structure
-
go to individual directory e.g. diet_lenet_fpga
-
Start VITIS HLS
-
Create a new project
-
Add source files <conv.cpp>
-
browse top function cnn_forward
-
Add testbench.cpp
-
Finish
-
Run, c simulate, co-synthesize RTL
The same flow applies to CIFAR_VGG and IMGNET_RESNET
Each directory has a notebook <Dataset,Network>-All-Experiments.ipynb to reproduce the experiments
cd lenet_model_sig_supp_sec1.1 python lut_utils_sig.py python mnist_eval.py 2 0
cd retraining
Retraining the LeNet model python retraining_lenet_fc.py
(set PARALLEL based on your system cores)
cd discretized_inference
Create advanced virtual env:
sudo apt install python3.8-venv
python3 -m venv dietcnn_adv
source dietcnn_adv/bin/activate
pip install -r dietcnn_advanced.txt
run:
python imagenet_symencodetest.py
Set dataset path, desired #symbol parameters e.g. 2048, 512 Try to encode first, then decode test.
If you find our work useful, please consider citing:
@article{dey2023dietcnn,
author = {Swarnava Dey and Pallab Dasgupta and Partha P Chakrabarti},
journal = {ArXiv preprint arXiv:2305.05274},
title = {DietCNN: Multiplication-free Inference for Quantized CNNs},
year = {2023}
}
This code is released under MIT license.
Our code was built using several existing GitHub repositories. I will add those soon...