Skip to content

mouradboutrid/TurboGuard

Repository files navigation

✈️ TurboGuard: Turbofan Engine Anomaly Detection

Python TensorFlow Streamlit

A deep learning framework for predictive maintenance and anomaly detection in turbofan engines using dual LSTM architectures and the CMAPSS dataset.

Overview

TurboGuard implements a comprehensive anomaly detection and forecasting system for turbofan engines by leveraging two complementary deep learning approaches:

  • LSTM AutoEncoder: Reconstruction-based anomaly detection through sequence-to-sequence learning
  • Forecasting LSTM: Next-step prediction for early fault detection

The system provides robust, interpretable insights into engine health, enabling proactive maintenance strategies and reducing operational costs.

Key Features

  • Dual Model Architecture: Combines reconstruction and forecasting approaches for comprehensive anomaly detection
  • Interactive Dashboard: Real-time Streamlit applications for engine health monitoring and visualization
  • Multivariate Analysis: Processes 21 sensor channels with temporal dependencies and inter-correlations
  • Modular Design: Scalable pipeline supporting both research and production deployment
  • Advanced Preprocessing: Robust data normalization, sequence generation, and feature selection
  • Multiple Detection Methods: LSTM-based reconstruction error and statistical anomaly detection
  • Comprehensive Evaluation: Performance metrics including MSE, MAE, precision-recall, and accuracy

System Architecture

LSTM AutoEncoder Pipeline

graph TD
    A[DataLoader] --> B[DataPreprocessor]
    B --> C[LSTMAutoEncoder]
    C --> D[AnomalyDetector]
    D --> E[Visualizer]
    E --> F[CMAPSSAnomalyAnalyzer]
    F --> G[ModelManager]
    
    style A fill:#e1f5fe
    style C fill:#f3e5f5
    style D fill:#fff3e0
    style F fill:#e8f5e8
Loading

Forecasting LSTM Pipeline

graph TD
    A[DataProcessor] --> B[PrognosticFeatureSelector]
    B --> C[PrognosticLSTMModel]
    C --> D[PrognosticVisualizationSuite]
    D --> E[CMAPSSPrognosticHealthMonitor]
    E --> F[AnomalyDetectionEngine]
    
    style A fill:#e1f5fe
    style B fill:#f1f8e9
    style C fill:#f3e5f5
    style E fill:#fff8e1
    style F fill:#ffebee
Loading

πŸ“ Repository Structure

TurboGuard/
β”œβ”€β”€ app/                                  # Streamlit Applications
β”‚   β”œβ”€β”€ analyzer_app.py                     
β”‚   β”œβ”€β”€ app.py                             
β”‚   β”œβ”€β”€ autoencoder_anomaly_detector_app.py 
β”‚   β”œβ”€β”€ forecaster_anomaly_predictor_app.py 
β”‚   β”œβ”€β”€ loader_app.py                     # Data loading interface
β”‚   └── preprocessor_app.py                
β”œβ”€β”€ data/                                 # CMAPSS Dataset Files
β”‚   β”œβ”€β”€ RUL_FD00X.txt                     # Remaining Useful Life labels
β”‚   β”œβ”€β”€ test_FD00X.txt                    # Test dataset
β”‚   β”œβ”€β”€ cmpass++.png                      #sonsors infos
β”‚   β”œβ”€β”€ train_FD00X.txt                   # Training dataset
β”‚   └── readme.txt                        # Dataset documentation
β”œβ”€β”€ data_overview/                        # Data exploration
β”œβ”€β”€ results/                              # Model outputs and metrics
β”‚   β”œβ”€β”€ autoencoder_/                     # AutoEncoder results
β”‚   └── forecaster/                       # Forecasting model results
β”œβ”€β”€ src/                                  # Core Implementation
β”‚   β”œβ”€β”€ LSTM_AutoEncoder/                 # AutoEncoder architecture
β”‚   β”‚   β”œβ”€β”€ anomaly_analyzer.py           
β”‚   β”‚   β”œβ”€β”€ anomaly_detector.py           
β”‚   β”‚   β”œβ”€β”€ data_loader.py               
β”‚   β”‚   β”œβ”€β”€ data_preprocessor.py         
β”‚   β”‚   β”œβ”€β”€ lstm_autoencoder.py          
β”‚   β”‚   β”œβ”€β”€ model_manager.py             
β”‚   β”‚   └── visualizer.py               
β”‚   β”œβ”€β”€ Forecasting_LSTM/                # Prognostic forecasting system
β”‚   β”‚   β”œβ”€β”€ anomaly_detection_engine.py   
β”‚   β”‚   β”œβ”€β”€ forecasting_data_processor.py 
β”‚   β”‚   β”œβ”€β”€ main_training_.py            
β”‚   β”‚   β”œβ”€β”€ prognostic_LSTMModel.py     
β”‚   β”‚   β”œβ”€β”€ prognostic_feature_selector.py 
β”‚   β”‚   β”œβ”€β”€ prognostic_health_monitor.py 
β”‚   β”‚   └── prognostic_visualization_suite.py
β”‚   β”œβ”€β”€ forecaster_anomaly_predictor_test.py  
β”‚   └── autoencoder_anomaly_predictor_test.py 
β”œβ”€β”€ trained_models/                      # Saved Model Artifacts
β”‚   β”œβ”€β”€ autoencoder_models/              
β”‚   └── forecaster_model/                
β”œβ”€β”€ requirements.txt                      # Python dependencies
β”œβ”€β”€ README.md
β”œβ”€β”€ Damage Propagation Modeling.pdf      # Technical documentation
└── LICENSE

Quick Start

Prerequisites

  • Python 3.8 or higher
  • Virtual environment (recommended)
  • 6GB+ RAM for model training

Installation

  1. Clone the repository

    git clone https://github.com/mouradboutrid/TurboGuard.git
    cd TurboGuard
  2. Create and activate virtual environment

    python -m venv turbo_env
    source turbo_env/bin/activate  # On Windows: turbo_env\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Download CMAPSS dataset (if not included)

    • Place dataset files in the data/ directory
    • Ensure proper naming convention: train_FD00X.txt, test_FD00X.txt, RUL_FD00X.txt

Usage Options

1. Interactive Dashboard (Recommended)

Launch the main Streamlit application:

streamlit run app/app.py

2. Specific Model Testing

  • AutoEncoder Anomaly Detection:
    run src/autoencoder_anomaly_predictor_test.py
  • Forecasting-based Prediction:
    run src/forecaster_anomaly_predictor_test.py

3. Programmatic Usage

from src.LSTM_AutoEncoder.data_loader import DataLoader
from src.LSTM_AutoEncoder.data_preprocessor import DataPreprocessor
from src.LSTM_AutoEncoder.lstm_autoencoder import LSTMAutoencoder
from src.LSTM_AutoEncoder.anomaly_detector import AnomalyDetector

# Load dataset (returns a dict with keys 'train', 'test', 'rul')
loader = DataLoader(data_dir='/content/drive/MyDrive/CMAPSSData')
dataset = loader.load_dataset('FD001')

train_raw = dataset['train']  # pandas DataFrame
test_raw = dataset['test']    # pandas DataFrame
rul_raw = dataset['rul']      # pandas DataFrame

# Preprocess the train and test data
preprocessor = DataPreprocessor()
train_processed = preprocessor.preprocess_data(train_raw, calculate_rul=True, normalize=True)
test_processed = preprocessor.preprocess_data(test_raw, calculate_rul=False, normalize=True)

# Create sequences from preprocessed data
X_train, y_train = preprocessor.create_sequences(train_processed, sequence_length=50, target_col='RUL')
X_test = preprocessor.create_sequences(test_processed, sequence_length=50)

print("X_train shape:", X_train.shape)
print("X_test shape:", X_test.shape)

# Build and train the LSTM Autoencoder
autoencoder = LSTMAutoencoder()
autoencoder.build_model(input_shape=(X_train.shape[1], X_train.shape[2]))
autoencoder.train(X_train, epochs=50, batch_size=32)

# Detect anomalies on test set
detector = AnomalyDetector()
anomaly_scores, anomaly_flags, threshold = detector.detect_lstm_anomalies(X_test, autoencoder)

print(f"Anomaly threshold: {threshold:.4f}")
print(f"Detected {np.sum(anomaly_flags)} anomalies out of {len(anomaly_flags)} test samples")
print(f"Anomaly rate: {np.sum(anomaly_flags)/len(anomaly_flags)*100:.2f}%")

Core Components

Data Processing Module (src/LSTM_AutoEncoder/ & src/Forecasting_LSTM/)

  • DataLoader: Efficient CMAPSS dataset ingestion and validation
  • DataPreprocessor: Advanced normalization, sequencing, and feature engineering
  • PrognosticFeatureSelector: ML-based feature selection for optimal prognostic performance

Model Architectures

  • LSTMAutoEncoder: Deep LSTM encoder-decoder with attention mechanisms
  • PrognosticLSTMModel: Multi-horizon forecasting with uncertainty quantification
  • AnomalyDetectionEngine: Real-time anomaly scoring and adaptive thresholding

Analysis and Visualization

  • AnomalyAnalyzer: Comprehensive analysis pipeline with performance benchmarking
  • Visualizer: Interactive plotting utilities for anomalies and training metrics
  • PrognosticVisualizationSuite: Advanced 3D visualizations and prognostic dashboards

Dataset Information

CMAPSS Dataset (Commercial Modular Aero-Propulsion System Simulation by NASA)

Dataset Fault Modes Operating Conditions Training Engines Test Engines
FD001 1 1 100 100
FD002 1 6 260 259
FD003 2 1 100 100
FD004 2 6 248 249

Sensor Measurements: 21 channels including fan speed, core speed, turbine temperatures, pressures, fuel flow, and vibration data.

Performance Metrics

AutoEncoder Model Performance

  • Reconstruction Accuracy: MSE < 0.15 on validation set
  • Anomaly Detection: F1-Score > 0.52
  • False Positive Rate: < 20% on normal operations

Forecasting Model Performance

  • Early Detection: 60%+ anomalies detected 20+ cycles before failure
  • Multi-step Forecasting: Maintains accuracy up to 50-step horizon

πŸ”§ Advanced Features

Multi-Model Anomaly Detection

  • Reconstruction-based: LSTM AutoEncoder error analysis
  • Prediction-based: Forecasting deviation detection
  • Statistical Methods: Distribution-based anomaly scoring
  • Ensemble Approach: Weighted combination of multiple methods

Production-Ready Capabilities

  • Model Versioning: Automated model management and deployment
  • Real-time Processing: Stream processing for live sensor data
  • Scalable Architecture: Containerized deployment support
  • Performance Monitoring: Continuous model performance tracking

Interpretability and Explainability

  • Attention Visualization: Understanding model focus areas
  • Feature Importance: Sensor contribution analysis
  • Anomaly Attribution: Root cause analysis for detected anomalies

Future Enhancements

  • Multi-Engine Modeling: Cross-engine anomaly pattern learning
  • Federated Learning: Distributed training across multiple datasets
  • Edge Deployment: Lightweight models for embedded systems
  • Digital Twin Integration: Real-time synchronization with physical engines

Documentation

  • Technical Report: Damage_Propagation_Modeling.pdf
  • Readthedocs Documentation: Documentation

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for complete details.

πŸ‘₯ Authors

Boutrid Mourad - AI Engineering Student

Kassimi Achraf - AI Engineering Student

Acknowledgments

  • NASA for providing the CMAPSS dataset and establishing benchmarks in prognostics research
  • TensorFlow/Keras Team for the robust deep learning framework
  • Streamlit for enabling rapid development of interactive ML applications
  • Open Source Community for the foundational libraries that made this project possible

πŸ“Š Project Status

GitHub last commit GitHub issues GitHub pull requests

Current Version: 1.0.0
Status: Active Development


If you find TurboGuard helpful for your research or projects, please consider starring this repository!

About

TurboGuard is a predictive maintenance system designed to monitor and analyze turbofan engine health using advanced time series anomaly detection techniques, enabling early fault detection and improved operational reliability.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages