Skip to content

LSTM based anomaly detection, training with built in generator (can be replaced to suit) and LSTM detector. Tensorflow Keras framework.

Notifications You must be signed in to change notification settings

stanleyoz/LSTM_anomaly_detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Anomaly Detection for Signal Analysis

Project Overview

This project implements a real-time anomaly detection system using a deep learning autoencoder model. The system is designed to detect anomalies in time-series signals, specifically simulating vibration sensor data from a mechanical system.

Key Features

  • Synthetic signal generation
  • LSTM-based autoencoder for anomaly detection
  • Real-time visualization of signals
  • Interactive anomaly injection and detection

Project Structure

  • training.py: Data generation, model training, and saving
  • test_random.py: Real-time anomaly detection and visualization script

Prerequisites

Dependencies

  • Python 3.8+
  • Libraries:
    • numpy
    • pandas
    • tensorflow
    • scikit-learn
    • plotly
    • dash
    • keras

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/signal-anomaly-detector.git
cd signal-anomaly-detector
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  1. Install required packages:
pip install numpy pandas tensorflow scikit-learn plotly dash keras

Usage

Training the Model

  1. Run the training script to generate synthetic data and train the model:
python training.py

This will generate and save anomaly_detector_model.h5

Running Real-Time Anomaly Detection

  1. Start the real-time anomaly detection:
python test_random.py
  1. During runtime:
  • The script will open a live dashboard in your default web browser
  • Press 'a' + Enter to manually inject a random anomaly
  • Anomalies will be highlighted in red on the graph

Model Details

  • Model Type: LSTM Autoencoder
  • Input: Time-series signals with a 10-step lookback
  • Training Data: Synthetic sinusoidal signals with noise
  • Anomaly Detection: Based on reconstruction error threshold

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Preparing to Push to GitHub

  1. Initialize Git repository (if not already done):
git init
  1. Add files:
git add training.py test_random.py README.md
  1. Commit changes:
git commit -m "Initial commit: Real-time Anomaly Detection project"
  1. Create a new repository on GitHub

  2. Link local repository to GitHub:

git remote add origin https://github.com/yourusername/signal-anomaly-detector.git
  1. Push to GitHub:
git branch -M main
git push -u origin main

License

Distributed under the MIT License. See LICENSE for more information.

Contact

stanleyoz

Project Link: https://github.com/stanleyoz/signal_anomaly-detector

About

LSTM based anomaly detection, training with built in generator (can be replaced to suit) and LSTM detector. Tensorflow Keras framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages