This repository contains a demo of Keyword spotting for Microcontrollers.
This demo is based on the ARM KWS for MCU's simple_test, but removed the dependencies of mbed and adapt to linux platform and other arm chips.
- Install toolchains
- Clone related repositories:
git clone https://github.com/JeffyCN/ARM-KWS-demo.git
git clone https://github.com/JeffyCN/ML-KWS-for-MCU.git
git clone https://github.com/JeffyCN/CMSIS_5.git -b master
- Enter ARM-KWS-demo/ and build the demo with "make"
- Run the generated "kws_test" on the device or use qemu-arm-static:
root@jeffy:/# kws_test
Detected right (99%)
To build this demo for MCU:
make clean && make CPU=m4
Replace "test.wav" and run "./test.sh"
Run "./realtime_test.sh" and feed audio data to .kws, for example:
dd if=test.wav bs=1 skip=44 of=.kws
Or
modprobe snd-aloop
arecord -t raw -r 16000 -f S16_LE -c 1 -D hw:CARD=Loopback,DEV=0 .kws&
aplay -D hw:CARD=Loopback,DEV=1 test.wav
This demo is running ARM KWS on specified wave data with a pre-generated DS CNN quantized weights.
The quantized weights is generated by quant_test.py from trained model checkpoint.
More details about the quantized weights, please check this article
There're some handy scripts under KWS/(some of them comes from https://github.com/tpeet/ML-KWS-for-MCU).
The steps to retraining:
- Goto KWS/
- Modify params in common.sh
- Tune hyper params with "./hyper_optimize.sh"
- Apply best hyper params(recorded in the trials file) to common.sh
- Run "./train.sh" to train
- Run "./test.sh" to check the accuracy
- Run "./fold_batchnorm.sh" to fuse batch-norm layers
- Run "./quant_dump.sh" to quantize and dump params
NOTE:
- Step 3 and 4 can be skipped if you think the current hyper params is ok.
- Step 3 is an indefinitely loop, can be terminated anytime.
- Step 5 can take a very long time, can interrupt it when the accuracy becomes stable.