CardioVision is an end-to-end, explainable deep learning platform designed for clinical ECG analysis and cardiac arrhythmia detection. Built using PyTorch and Streamlit, CardioVision features a state-of-the-art hybrid deep learning pipeline that preprocesses raw ECG signals, performs safety audits, segments cardiac beats, classifies them into four diagnostic categories, and produces clinician-interpretable heatmaps via 1D Grad-CAM.
- Multi-Architecture Support: Train and evaluate four distinct hybrid deep learning architectures:
hybrid: Convolutional Neural Network (CNN) combined with a Bidirectional LSTM (BiLSTM) network.attention: CNN-BiLSTM integrated with a Self-Attention layer to highlight critical temporal dependencies.resnet: Hybrid model incorporating Residual Blocks (ResNet) to facilitate gradient flow.se: Hybrid model using Squeeze-and-Excitation (SE) Blocks for channel-wise feature calibration.
- Rule-Based Clinical Auditing: Automatically verifies ECG signal quality, calculates missing data ratios, flags low-amplitude/flatline segments, and assigns a signal severity warning (
PASS,WARNING, orCRITICAL). - Robust Signal Processing: Implements a Butterworth bandpass filter (0.5β40 Hz) for baseline wander and high-frequency noise removal, a Notch filter (60 Hz) for powerline interference reduction, and missing-value imputation.
- Explainable AI (XAI): Generates 1D Grad-CAM visual saliency maps directly overlaid on the ECG waveform, highlighting the morphological regions (e.g., P-wave, QRS-complex, T-wave) that drove the model's decision.
- Interactive Streamlit Web Dashboard: A premium, dark-themed dashboard designed for clinical simulation, allowing users to upload EDF/CSV signals, train models, run interactive inference, and explore explainability maps.
- Automated Clinical Reporting: Exports interactive or static, clean clinical reports in HTML format, combining raw signal audits, prediction probabilities, and Grad-CAM visualizations.
- Robust Test Coverage: Includes unit tests for preprocessing, model dimensions, and Grad-CAM hooks.
The CardioVision architectures have been rigorously evaluated on the MIT-BIH dataset test split, specifically optimized to achieve research-grade clinical classification.
| Architecture | Overall Accuracy | Highlight / Optimization |
|---|---|---|
| Hybrid CNN-LSTM | 98.53% | Baseline spatiotemporal feature extraction |
| Self-Attention Hybrid | ~99.2% | Captures critical long-range dependencies |
| ResNet Hybrid | 99.03% | Facilitates gradient flow using residual blocks |
| SE-Block Hybrid | 99.14% | Channel-wise feature calibration |
(Note: Training employed class-balanced square-root weighted sampling and label smoothing to maximize performance across underrepresented cardiac arrhythmias).
The CardioVision pipeline consists of six primary stages:
graph TD
A[Raw ECG Signal: CSV / EDF] --> B[Clinical Auditor: Quality Check]
B --> C[Denoising: Butterworth + Notch Filters]
C --> D[R-Peak Detection & Beat Segmentation]
D --> E[Deep Learning Models: Hybrid, ResNet, SE, Attention]
E --> F[1D Grad-CAM Saliency Extraction]
F --> G[Interactive Dashboard / HTML Clinical Report]
- Clinical Auditing: Analyzes raw signals for structural anomalies, flatlines, extreme outliers, and missing values.
- Denoising: Filters out baseline wander, electromyogram (EMG) noise, and powerline interference.
- Beat Segmentation: Extracts R-peak centered windows of 360 samples (1 second at 360 Hz) and applies Z-score normalization.
- Deep Learning Classification: Predicts the cardiac beat type across four major classes.
- Interpretability (XAI): Extracts gradients from the last convolutional layer to compute heatmaps.
- Reporting: Assembles the findings into a downloadable clinical report.
The repository has been cleaned to include only necessary source code files and setup resources:
.
βββ app.py # Streamlit web application
βββ main.py # CLI entry point (download, train, evaluate, etc.)
βββ config.py # Global settings, paths, and hyperparameters
βββ requirements.txt # Python dependency file
βββ .gitignore # Excluded directories (local datasets, models, caches)
βββ Cardio Vision.pdf # Research report / documentation file
βββ project_report.pdf # Research summary file
βββ data/ # Directory for dataset storage
β βββ processed/ # Preprocessed .npz files (gitignored)
β βββ raw/ # Raw downloaded record files (gitignored)
βββ models/ # Directory for saving model weights (gitignored)
βββ reports/ # Location for generated clinical HTML reports (gitignored)
βββ src/ # Main source package
β βββ explainability/ # 1D Grad-CAM implementation
β βββ model/ # Model architectures (hybrid, resnet, attention, se) & Trainer
β βββ preprocessing/ # Filters, loaders, auditors, and imputers
β βββ reporting/ # HTML/Matplotlib report generator
β βββ utils/ # General helpers (seeding, parameter counting, device detection)
βββ tests/ # Unit test suite
- Python: Version 3.8 to 3.11 is recommended.
- Hardware: Compatible with CPU execution, but a CUDA-capable GPU (such as RTX 4060) is highly recommended for faster model training.
git clone https://github.com/yourusername/CardioVision.git
cd CardioVisionpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCardioVision can be run using the interactive Streamlit Dashboard or via the Command-Line Interface (CLI).
To launch the interactive, browser-based clinical dashboard:
streamlit run app.pyOpen http://localhost:8501 in your browser. The app includes five sections:
- Dashboard: High-level overview of the pipeline, architecture flowcharts, and local database status.
- Upload & Preprocess: Upload your own CSV or EDF signals, run the clinical auditor, or process the complete MIT-BIH dataset.
- Train Model: Train model architectures, monitor loss curves in real-time, and view confusion matrices.
- Inference & Explain: Run inference on standard beats or uploaded files, and visualize Grad-CAM activation maps.
- Reports: Generate, preview, and download HTML clinical reports.
The main.py script serves as a multi-functional CLI for automation:
Downloads the full database (48 records) from PhysioNet:
python main.py downloadPreprocesses the downloaded signals, runs quality auditing, and saves the segmented heartbeats into data/processed/mitbih_processed.npz:
python main.py preprocessTrain a specific model variant (options: hybrid, attention, resnet, se):
python main.py train --arch hybrid --epochs 50 --batch-size 128 --lr 0.001Evaluate a trained model's performance on the test split:
python main.py evaluate --arch hybridGenerate sample HTML clinical reports with Grad-CAM overlays for each of the classification categories:
python main.py report --arch hybridVerify codebase integrity using pytest:
python main.py test(Or run pytest tests/ -v directly)
CardioVision maps the standard MIT-BIH annotation codes into four clinically meaningful classes:
| Class ID | Class Name | MIT-BIH Annotations Mapped | Clinical Description |
|---|---|---|---|
| 0 | Normal | N, L, R |
Normal beats, Left/Right bundle branch block beats. |
| 1 | AFib | A, a, J, S, e, j |
Atrial Premature, Aberrant Junctional, Nodal, or Escaped beats. |
| 2 | PVC | V, E |
Premature Ventricular Contraction and Ventricular Escape beats. |
| 3 | Global | /, f, F, Q, ! |
Paced beats, Fusion of paced/normal beats, or unclassifiable beats. |
- License: Distributed under the MIT License. See
LICENSEfor details. - Dataset: Powered by the MIT-BIH Arrhythmia Database hosted on PhysioNet.
- Reference Papers: Hybrid CNN-LSTM modeling and interpretability schemas for clinical electrocardiogram diagnostic tools.