Environmental sound classification on the edge: A pipeline for deep acoustic networks on extremely resource-constrained devices (url: https://arxiv.org/abs/2103.03483)
@article{mohaimenuzzaman2022environmental,
title={Environmental sound classification on the edge: A pipeline for deep acoustic networks on extremely resource-constrained devices},
author={Mohaimenuzzaman, Md and Bergmeir, Christoph and West, Ian and Meyer, Bernd},
journal={Pattern Recognition},
pages={109025},
year={2022},
publisher={Elsevier}
}
Github url: https://github.com/mohaimenz/acdnet
- Create
python 3.7+
development environment - Install
torch 1.7.1
or higher. - Install
wavio 0.0.4
python library - Install
wget
for downloading ESC-50 over HTTP - Install
FFmpeg
for downsampling and upsampling audio recordings
- ACDNet is developed and tested in macOS environment. The forthcoming sections assumes that the above libraries/softwares are now installed.*
- Download/clone the repository.
- Go to the root of ACDNet directory using the terminal.
- To download and process ESC-50 dataset, run:
python common/prepare_dataset.py
- Prepare the validation data, run:
python common/val_generator.py
All the required data of ESC-50 for processing 44.1kHz
and 20kHz
are now ready at datasets/esc50
directory
There are pretrained models provided inside torch/resources/pretrained_models
directory that can be used instead of training a new model. The model names are self explanatory. There are 5 pretrained ACDNet models validated on 5-folds (5-fold cross validation), 95% Weight pruned and retrained ACDNet model for hybrid pruning, ACDNet20 pruned and fine-tuned (not trained) and ACDNet-20 trained model
However, to conduct the training of a brand new ACDNet, run: python torch/trainer.py
- Follow on-screen self-explanatory steps
- To train a brand new ACDNet, please select
training from scratch
option and keep the model pathempty
in the next step. - The trained models will be saved at
torch/trained_models directory
- The models will have names
YourGivenName_foldNo
on which it was validated. - For five fold cross validation, there will be 5 models named accordingly
- To test a trained model, run this command:
python torch/tester.py
- Follow the on-screen self explanatory steps
- A model should always be tested on the fold on which it was validated to reproduce the result.
- For example, if a model was validated on fold-1, it will reproduce the validation accuracy on that fold. For all other folds (fold 2-5), it will produce approximately 100% prediction accuracy since it was trained on those folds.
- To conduct pruning run:
python torch/pruning.py
- Follow the on-screen self explanatory steps
- To conduct
hybrid
pruning on ACDNet, please runweight pruning
on ACDNet first and then applyhybrid pruning
on the weight pruned model. - The on-screen steps are easy enough to achieve this goal.
- The pruned models will be stored inside
torch/pruned_models
directory
To conduct retraining a pruned model, follow these steps:
- Run:
python torch\trainer.py
- Choose the training options
- Provide pruned model path
- Provide fold number for the model to be validated.
- For 8-bit post training quantization, run:
python torch/quanization.py
- Provide model path.
- Provide the fold on which the model was validated.
For deployment purpose we use Tensorflow and Tensorflow Lite.
- Install tensorflow 2.2.0
There is a pretrained ACDNet-20 model inside tf/resources/pretrained_models
directory. This can be used instead.
To rebuild ACDNet-20 from scratch in TF, follow these steps:
- Run:
python tf/trainer.py
- Provide the ACDNet-20 PyTorch model path for it to retrieve the configuration of ACDNet-20 and build an equivalent TF model
- Follow the on-screen steps for finish the process.
- For this, any fold can be chosen for the model to be validated as it is going to be trained as a brand new ACDNet-20 model in TF.
- The trained model will be saved inside
tf/trained_models
directory - Once the model training is finished, we are ready to go to the deployment step.
The model will now be converted to TF Lite, quantized to 8-bit and then using TF Lite Micro, we will push the model to MCU for inferencing.
Please follow the instructions provided in README.md file inside deployment
directory