Skip to content

07raghavan/threat-detection-

Repository files navigation

🎧 Multiclass Audio Event Detection with Deep Learning

image

A robust pipeline for multiclass audio event detection using deep learning. The system classifies audio into four classes:

  • 🔫 Gunshot
  • 🚗 Vehicle
  • 🪓 Wood_Cutting
  • NonThreat

It includes real-time alerting logic (e.g., via LoRa) and deployment-ready TensorFlow Lite models for edge devices.

📁 Dataset Structure

org_dataset/
├── Gunshot/
│   ├── file1.wav
│   └── ...
├── Vehicle/
│   ├── file1.wav
│   └── ...
├── Wood_Cutting/
│   ├── file1.wav
│   └── ...
└── NonThreat/
    ├── file1.wav
    └── ...
  • Format: .wav files per class
  • Holdout Set: A separate folder (e.g., realtest/) with test samples from each class
Screenshot 2025-07-21 001031

🚀 Features

  • 📊 EDA: Class distribution visualization and spectrogram previews
  • 🧹 Preprocessing: Converts audio to log-mel spectrograms; ready for CNN input
  • 🧠 Model:
    • Data augmentation
    • Batch normalization
    • Dropout
    • L2 regularization
  • 🏋️ Training:
    • Early stopping
    • Learning rate reduction
    • Checkpointing best model
  • Evaluation: Confusion matrix & classification report
  • 🛠️ Deployment: Converted to TFLite for edge inference

🛠️ Installation

1. Clone the Repository

git clone https://github.com/yourusername/audio-event-detection.git
cd audio-event-detection

2. Create Virtual Environment & Install Dependencies

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

📦 Main Dependencies

  • tensorflow
  • librosa
  • numpy
  • matplotlib
  • scikit-learn

📂 Dataset Setup

  • Place your dataset in the structure mentioned above
  • Update dataset paths in the scripts if needed
Screenshot 2025-07-20 232645

🔧 Customization

  • Class Names: Update the class_names list in scripts for custom classes
  • Alert Logic: Modify send_lora_alert() in tflite_inference_lora.py
  • Paths: Update dataset/model paths as per your directory setup
Screenshot 2025-07-21 001056

🧠 Model Architecture

ConvBlock x3 (Conv2D → BatchNorm → MaxPooling)
↓
Data Augmentation (random translation, zoom)
↓
GlobalAveragePooling2D
↓
Dense Layer → Dropout
↓
Output Layer (Softmax)

📸 Refer to cnn_model_architecture.png for a diagrammatic view.

📊 Results

  • Validation Accuracy: ~96% on holdout set
  • Evaluation Metrics: Confusion Matrix, Classification Report (from test_holdout.py)
image image

📱 Edge Deployment

  • Model File: multiclass_model.tflite (~122 KB)
  • Deploy to: Raspberry Pi, microcontrollers, IoT devices
  • Real-Time Detection: Included example with alerting logic

🙌 Credits

Built with 💡 using TensorFlow, Librosa, and open-source tools.

About

This repository contains a deep learning-based audio classification project using Convolutional Neural Networks (CNNs). The model processes audio signals, extracts relevant features like spectrograms classifies them into predefined categories. Which will be used to detect threats in the forest such as gunshots, vehicle movement, wood cutting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages