Develop an IoT Edge device to Capture and Classify Species using Sounds to Support Wildlife Conservation Activities
Please go to /wiki
for more information.
The ML model that was developed during the final year project is made publicly here.
By following the described procedures, you would be able to run either of the frameworks on the Raspberry Pi 4 Model B. Before starting, the correct version of Raspberry Pi OS should be installed:
- Using Raspberry Pi Imager, write Debian Bullseye 64-bit OS to the SD card.
- Go through the setup wizard to set name, password and connect the RPI to the network.
- For easier development, enable SSH and VNC through Preferences > Raspberry Pi Configuration > Interfaces, allowing to connect to the RPI wirelessly through the network instead of by the cable.
- Make sure that Python >=3.9 version is installed
python --version
. - Update the OS by
sudo apt-get update
andsudo apt-get upgrade
.
Connect via SSH:
ssh <user>@<host>
Connect via VNC: Download VNC Viewer and install it on your computer.
pip install scipy
pip install soundfile
# Install PyAudio for Edge Impulse Python SDK.
sudo apt-get install portaudio19-dev
sudo pip install pyaudio
# Finally install Edge Impulse Python SDK itself.
pip install edge_impulse_linux
By default, the added microphone will have 40% volume. Increase it to 100% using alsamixer
.
By default, the AudioImpulseRunner returns small fragments of audio captured by microphone.
Instead, we want to return audio features that were classified. Go to audio.py
(location can be found by pip show edge_impulse_linux
) and return features instead of audio.
For more information here.
- Install Dependencies using the guide here.
- Download the model
edge-impulse-linux-runner --download <filename>.eim
You can verify the model is working on the device using edge-impulse-linux-runner
Use "Using with Raspberry Pi" guide to change jumpers on the transceiver and enable Serial port. Then download /tools/sx126x.py
file and place it in the same directory as the edge_framework.py
.
- First make the system to open terminal on startup by adding
@lxterminal
to/etc/xdg/lxsession/LXDE-pi/autostart
. - Then add
python /home/pi/final_year_project/edge_framework.py test.eim 10
at the end of.bashrc
file. 10 is the OS's default microphone.
Running the Microsoft Acoustic Bird Detection model on RPI.
pip install sounddevice
pip install soundfile
pip install scipy
pip install pandas
pip install python_speech_features
pip install joblib
pip install sklearn
pip install tflite_runtime
Use this guide to install Tensorflow 2.8.0 version on RPI.
Microsoft Framework relies on preprocess.py
file from Microsoft to extract features.
Download the file and put it in the same directory as the framework. Can be found here.
The ML models can be accessed through Jupyter Notebook tutorial found on git. Run the whole notebook and add a cell at the end with the following code:
# Exporting Feature Model
feature_model.save(<export_path>)
# Exporting SVM Classifer
# Choosing maximum compression = 9 to make the file size as small as possible.
joblib.dump(svm, '<export_path>/<file_name>.pkl', compress=9)
Afterwards, copy both models to the /ml_models
directory under the Microsoft Framework.
pip install pandas
# Install SQLite3 command tool
sudo apt-get install sqlite3
- Create database using
sqlite3 gateway_storage.db
- Create table with the following command
CREATE TABLE classification_results(id INTEGER PRIMARY KEY AUTOINCREMENT, audio_file_name TEXT, confidence_level REAL, classification TEXT, time DATETIME);
- Launching the Framework on Startup
- Setup Lora Transceiver
Gateway Raspberry Pi can download audio saved on the Edge Raspberry Pi when they are connected to the same network. To not be prompted for password for every audio file download, use this tutorial to generate SSH keys and copy them over to the Edge.
By following the described procedures, you would be able to run edge Arduino framework on the Arduino Nano 33 BLE Sense. Before starting, install Arduino IDE which will be used to upload Edge Framework to your Arduino device:
- Navigate to arduino website, download and install Arduino IDE 1.8.19 on your computer.
- On launching IDE, install core for Nano board by going to Tools > Board > Board Manager. Install
Arduino Mbed OS Nano Boards
core.
Upload edge framework sketch by navigating to Sketch > Add File.
Download machine learning model as Arduino library using Edge Impulse GUI by going to Deployment > Arduino Library > Build. This will download a .zip folder, do not unzip it.
Before starting, make sure that old library has been removed if installed previously, can be found in /Users/<user>/Documents/Arduino/libraries/final-year-project_inferencing
.
Import the downloaded Arduino library by going to Sketch > Include Library > Add .ZIP library, select your downloaded .zip folder.
Before starting, connect your Arduino to your computer using USB. To be able to upload the model and sketch to Arduino device, you will need to configure its board and port. Navigate to Tools > Boards > Arduino Mbed OS Nano Boards and select Arduino Nano 33 BLE Sense. After, go to Tools > Port and select the USB port your Arduino is connected to.
To compile and upload your sketch to your Arduino Device, click the "Upload" button. After the upload is finished, the library will start inferencing straight away. To see the logs, click on "Serial Monitor".