See more info attached -https://www.linkedin.com/posts/douglasbyfield_this-weekend-i-had-the-pleasure-of-participating-activity-7112239121237991424-g2xa?utm_source=share&utm_medium=member_desktop
This project won the first-ever JAIA Hackathon. It's designed to detect and classify gunshots in real-time. When a gunshot is detected, the audio is parsed, processed, and sent through two machine learning models. The first model identifies whether the sound is a gunshot or not. If it is, the second model classifies the type of gun the shot originated from. All the data, along with geolocation and timestamp, is then displayed on a real-time map interface built with React. π οΈ Tech Stack
- Machine Learning Models: Python, Torch
- Audio Preprocessing: Python scripts to convert .wav to MFCCs
- Backend: Django
- Frontend: React
- Communication: Webhooks, Django channel server
- Model Selection: CNN for audio classification.
- Train Model: Used preprocessed audio data to train the model.
- Prediction: Made predictions and sent data to David's script.
- Collected audio data of common gunshots in Kingston.
- Preprocessed the raw audio into MFCCs.
mfccs = librosa.feature.mfcc(audio_data, sr)
Performed data augmentation for model robustness.
predictions = model.predict(preprocessed_audio)
-
Created a system to alert authorities in real-time.
-
Ensured seamless communication between the Django backend, ml models, and React frontend.
def initiate_client(data):
ws = create_connection("ws://localhost:8000/ws/chat/gunsession/")
ws.send(json.dumps({"message": data}))
ws.close()
- Built a real-time dashboard using React and Leaflet.
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
const message = data.message;
console.log('Received:', message);
if (message && message.geo) {
const [x, y] = message.geo;
setGunShot(message)
// console.log(gunShot)
flyMap(x, y, 11);
}
setGunShots(prevGunshots => [...prevGunshots, message]);
console.log(gunShot,gunShots)
};
-
Create a Python Virtual Environment
- Use Python 3.10.
-
Activate the Virtual Environment
- Activate the virtual environment that you just created.
-
Install Required Packages
- Run the command
pip install -r requirements.txt
in the root of the project.
- Run the command
-
Make Migrations
- Navigate to the
gun_shot_detector
folder. - Run the command
python manage.py makemigrations
. (This file should already exist in most cases).
- Navigate to the
-
Apply Migrations
- Run the command
python manage.py migrate
.
- Run the command
- Download the Redis server for your respective environment.
- Run the command
brew install redis
.
- Follow the instructions outlined in this article or install using Docker.
sudo apt install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
-
Start Redis Server
- Run the command
redis-server --port 6379
.
- Run the command
-
Start Django Server
- Navigate to the
gun_shot_detector
folder. - Make sure the virtual environment is activated.
- Run the command
python manage.py runserver
.
- Navigate to the
-
Navigate to Frontend Directory
- Go to the
/frontend
folder.
- Go to the
-
Install Node Modules
- Run the command
npm install
to install modules frompackage.json
.
- Run the command
-
Start the Frontend
- Run the command
npm start
. - Make sure the webhook address matches what you have in the Django channel configs.
// Example from line 89 const ws = new WebSocket('ws://***.***.**.**:8000/ws/chat/gunsession/');
- Run the command
- Run main.py in each ml folder to train model.