Skip to content

Susreel7/neurostroke-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NeuroStroke AI ๐Ÿง 

Python TensorFlow Streamlit License

NeuroStroke AI is an advanced deep learning system designed to detect brain strokes from CT scan images. Using state-of-the-art Convolutional Neural Networks (CNN) with transfer learning, this project aims to assist medical professionals in early and accurate stroke diagnosis, ultimately improving patient outcomes.

Brain Stroke Detection Demo


๐Ÿ“‹ Table of Contents


๐ŸŽฏ About the Project

Brain stroke is a critical medical emergency that occurs when blood supply to part of the brain is interrupted, preventing oxygen and nutrients from reaching brain cells. There are two main types:

  • Ischemic Stroke: Caused by a blood clot blocking blood flow
  • Hemorrhagic Stroke: Caused by bleeding in the brain

Early detection is crucial for effective treatment and improved recovery outcomes. While medical imaging techniques such as CT and MRI scans are essential for diagnosis, manual interpretation can be time-consuming and prone to human error.

NeuroStroke AI leverages deep learning to automate stroke detection from CT scans, providing:

  • โœ… Fast and accurate predictions
  • โœ… Support for medical professionals in diagnosis
  • โœ… Scalable solution for healthcare facilities
  • โœ… User-friendly web interface for easy deployment

โœจ Key Features

  • ๐Ÿ”ฌ Deep Learning Model: CNN-based architecture with VGG19 transfer learning
  • ๐ŸŽฏ Neural Focus Map (Grad-CAM): Visualizes the regions of the CT scan the model focuses on for its prediction
  • ๐Ÿ“Š Research Insights Dashboard: Interactive visualizations of dataset statistics and model performance
  • ๐Ÿ“ Research Paper Generator: Automatically generates a draft research abstract based on results
  • ๐Ÿ“š Literature Review: Curated list of academic papers related to AI in stroke detection
  • ๐Ÿš€ Real-time Predictions: Instant stroke detection from uploaded images
  • ๐Ÿ’ป Premium Interactive UI: Modern, responsive interface built with Streamlit and custom CSS
  • ๐Ÿ“ˆ Model Evaluation: Comprehensive metrics including accuracy, precision, recall, and F1-score

๐Ÿ“Š Dataset

The model is trained on the Brain Stroke CT Image Dataset from Kaggle:

  • Source: Brain Stroke CT Image Dataset
  • Total Images: ~2,000+ CT scan images
  • Classes:
    • Normal (No Stroke)
    • Stroke
  • Image Format: JPG/PNG
  • Image Size: Resized to 224x224 pixels for model input

Dataset Structure

Brain_Data_Organised/
โ”œโ”€โ”€ Normal/          # CT scans without stroke
โ””โ”€โ”€ Stroke/          # CT scans with stroke indicators

Preprocessing Steps

  1. Resizing: All images resized to 224x224 pixels
  2. Color Conversion: Converted to RGB format (3 channels)
  3. Normalization: Pixel values normalized to [0, 1] range
  4. Data Augmentation:
    • Random rotation
    • Brightness adjustment
    • Horizontal flipping
    • Zoom variations

๐Ÿ—๏ธ Model Architecture

CNN Architecture

The model uses a custom Convolutional Neural Network with the following structure:

Input Layer (224x224x3)
    โ†“
Conv2D (32 filters, 3x3) + ReLU
    โ†“
MaxPooling2D (2x2)
    โ†“
Conv2D (64 filters, 3x3) + ReLU
    โ†“
MaxPooling2D (2x2)
    โ†“
Conv2D (128 filters, 3x3) + ReLU
    โ†“
MaxPooling2D (2x2)
    โ†“
Flatten
    โ†“
Dense (256 units) + ReLU + Dropout(0.2)
    โ†“
Dense (128 units) + ReLU + Dropout(0.2)
    โ†“
Dense (1 unit) + Sigmoid

Transfer Learning

The project also implements VGG19 transfer learning for enhanced performance:

  • Pre-trained on ImageNet
  • Fine-tuned on medical CT scan images
  • Frozen early layers, trainable later layers

Training Configuration

  • Optimizer: Adam
  • Loss Function: Binary Crossentropy
  • Metrics: Accuracy
  • Batch Size: 32
  • Epochs: 10
  • Train/Test Split: 90/10

๐Ÿš€ Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • (Optional) Virtual environment tool (venv, conda)

Step-by-Step Installation

  1. Clone the repository

    git clone https://github.com/yourusername/neurostroke-ai.git
    cd neurostroke-ai
  2. Create a virtual environment (recommended)

    # Using venv
    python -m venv venv
    
    # Activate on Windows
    venv\Scripts\activate
    
    # Activate on macOS/Linux
    source venv/bin/activate
  3. Install required dependencies

    pip install -r requirements.txt
  4. Download the dataset (if training from scratch)

    • Visit Kaggle Dataset
    • Download and extract to a data/ folder in the project root
  5. Download pre-trained model (optional)

    • The stroke_detection_model.h5 file is included in the repository
    • If missing, you'll need to train the model (see Training section)

๐Ÿ’ป Usage

Running the Streamlit Web App

The easiest way to use NeuroStroke AI is through the web interface:

streamlit run app.py

This will:

  1. Start a local web server (usually at http://localhost:8501)
  2. Open the application in your default browser
  3. Display the upload interface

Using the Web App:

  1. Click "Browse files" or drag and drop a CT scan image
  2. Supported formats: JPG, JPEG, PNG
  3. Click the "Predict" button
  4. View the prediction result and confidence score

Training the Model

To train the model from scratch using the Jupyter notebook:

  1. Install Jupyter

    pip install jupyter
  2. Launch Jupyter Notebook

    jupyter notebook
  3. Open the training notebook

    • Navigate to brain-stroke-prediction-cnn.ipynb
    • Run all cells sequentially
  4. Save the trained model

    • The model will be saved as stroke_detection_model.h5
    • This file is used by the Streamlit app

Using the Model Programmatically

from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np

# Load the model
model = load_model('stroke_detection_model.h5')

# Load and preprocess image
image = Image.open('path/to/ct_scan.jpg')
image = image.resize((224, 224))
image = image.convert('RGB')
image_array = np.array(image) / 255.0
image_array = np.expand_dims(image_array, axis=0)

# Make prediction
prediction = model.predict(image_array)[0][0]
result = "Stroke" if prediction >= 0.5 else "Normal"
confidence = prediction if prediction >= 0.5 else (1 - prediction)

print(f"Prediction: {result}")
print(f"Confidence: {confidence * 100:.2f}%")

๐Ÿ“ Project Structure

neurostroke-ai/
โ”‚
โ”œโ”€โ”€ app.py                              # Streamlit web application
โ”œโ”€โ”€ brain-stroke-prediction-cnn.ipynb   # Jupyter notebook for model training
โ”œโ”€โ”€ stroke_detection_model.h5           # Pre-trained model (267 MB)
โ”œโ”€โ”€ requirements.txt                    # Python dependencies
โ”œโ”€โ”€ README.md                           # Project documentation
โ”‚
โ”œโ”€โ”€ templates/                          # HTML templates (if using Flask)
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ import.html
โ”‚
โ”œโ”€โ”€ static/                             # Static files (CSS, JS, images)
โ”‚   โ””โ”€โ”€ [static assets]
โ”‚
โ”œโ”€โ”€ img/                                # Project images and screenshots
โ”‚   โ””โ”€โ”€ [demo images]
โ”‚
โ”œโ”€โ”€ upload/                             # Temporary upload folder
โ”‚
โ”œโ”€โ”€ flagged/                            # Flagged predictions (for review)
โ”‚
โ””โ”€โ”€ .vscode/                            # VS Code configuration
    โ””โ”€โ”€ settings.json

๐Ÿ“ˆ Results

Model Performance

Metric Training Set Test Set
Accuracy ~95% ~92%
Loss ~0.12 ~0.18
Precision ~94% ~91%
Recall ~96% ~93%
F1-Score ~95% ~92%

Confusion Matrix (Test Set)

                Predicted
              Normal  Stroke
Actual Normal   [TN]    [FP]
       Stroke   [FN]    [TP]

Sample Predictions

The model successfully identifies:

  • โœ… Clear stroke indicators in CT scans
  • โœ… Normal brain tissue without abnormalities
  • โœ… Various stroke sizes and locations
  • โš ๏ธ Some edge cases may require medical expert review

๐Ÿ› ๏ธ Technologies Used

Core Technologies

  • Python 3.10+: Primary programming language
  • TensorFlow 2.x: Deep learning framework
  • Keras: High-level neural networks API

Web Framework

  • Streamlit: Interactive web application framework

Data Processing

  • NumPy: Numerical computing
  • Pandas: Data manipulation and analysis
  • PIL (Pillow): Image processing
  • OpenCV: Computer vision operations

Visualization

  • Matplotlib: Plotting and visualization
  • Seaborn: Statistical data visualization

Machine Learning

  • Scikit-learn: Model evaluation metrics
  • TensorFlow Hub: Pre-trained model integration

Development Tools

  • Jupyter Notebook: Interactive development environment
  • VS Code: Code editor

๐Ÿšง Challenges & Solutions

1. Limited Labeled Data

Challenge: Medical imaging datasets are often limited due to privacy concerns and the need for expert annotations.

Solution:

  • Implemented extensive data augmentation (rotation, brightness, flipping)
  • Applied transfer learning using pre-trained VGG19 model
  • Used dropout layers to prevent overfitting

2. Handling Image Variability

Challenge: CT scans vary significantly in quality, orientation, and contrast.

Solution:

  • Standardized preprocessing pipeline (resize, normalize, color conversion)
  • Implemented histogram equalization for contrast enhancement
  • Used robust CNN architecture to handle variations

3. Preventing Overfitting

Challenge: Complex model with limited dataset risked overfitting.

Solution:

  • Added Dropout layers (0.2 rate) after dense layers
  • Used early stopping during training
  • Implemented cross-validation
  • Applied L2 regularization

4. Model Interpretability

Challenge: Medical professionals need to understand model decisions.

Solution:

  • Provided confidence scores with predictions
  • Displayed original images alongside predictions
  • Documented model architecture and training process

๐Ÿ”ฎ Future Enhancements

Short-term Goals

  1. Multi-Modal Data Integration

    • Incorporate patient medical history
    • Include clinical reports and vital signs
    • Combine MRI and CT scan analysis
  2. Model Improvements

    • Experiment with other architectures (ResNet, EfficientNet)
    • Implement ensemble methods
    • Increase dataset size with synthetic data generation
  3. User Interface Enhancements

    • Add batch processing capability
    • Implement image annotation tools
    • Create detailed prediction reports (PDF export)

Long-term Vision

  1. Real-Time Clinical Deployment

    • Integration with hospital PACS systems
    • Real-time processing pipeline
    • DICOM format support
  2. Explainable AI (XAI)

    • Implement Grad-CAM for visual explanations
    • Show which regions influenced the prediction
    • Generate attention maps
  3. Mobile Application

    • Develop iOS/Android apps
    • Enable offline predictions
    • Secure cloud storage for medical data
  4. Multi-Class Classification

    • Detect different types of strokes
    • Identify stroke severity levels
    • Predict stroke location and size
  5. Regulatory Compliance

    • Pursue FDA/CE certification
    • Implement HIPAA compliance
    • Clinical trial validation

๐Ÿค Contributing

Contributions are what make the open-source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated!

How to Contribute

  1. Fork the Project

    # Click the 'Fork' button on GitHub
  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

    • Go to your fork on GitHub
    • Click "New Pull Request"
    • Describe your changes

Contribution Guidelines

  • Write clear, commented code
  • Follow PEP 8 style guidelines for Python
  • Add tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PR

Areas for Contribution

  • ๐Ÿ› Bug fixes and issue resolution
  • โœจ New features and enhancements
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿงช Additional test cases
  • ๐ŸŽจ UI/UX improvements
  • ๐ŸŒ Internationalization (i18n)

๐Ÿ“„ License

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

MIT License

Copyright (c) 2024 NeuroStroke AI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

๐Ÿ™ Acknowledgments

  • Dataset: Afridi Rahman for the Brain Stroke CT Image Dataset on Kaggle
  • TensorFlow Team: For the excellent deep learning framework
  • Streamlit: For the intuitive web app framework
  • Medical Community: For inspiring this project and providing domain knowledge
  • Open Source Community: For continuous support and contributions

Research References

  1. Shen, D., Wu, G., & Suk, H. I. (2017). Deep learning in medical image analysis. Annual Review of Biomedical Engineering, 19, 221-248.
  2. Litjens, G., et al. (2017). A survey on deep learning in medical image analysis. Medical Image Analysis, 42, 60-88.
  3. Simonyan, K., & Zisserman, A. (2014). Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556.

๐Ÿ“ง Contact

Project Maintainer: Susreel Somavarapu

Project Link: https://github.com/Susreel7/neurostroke-ai


โš ๏ธ Disclaimer

IMPORTANT: This software is intended for research and educational purposes only. It is NOT a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of qualified healthcare providers with any questions regarding medical conditions. Never disregard professional medical advice or delay seeking it because of information provided by this software.

The developers and contributors of this project:

  • Make no warranties about the accuracy or reliability of predictions
  • Are not liable for any medical decisions made based on this software
  • Recommend thorough clinical validation before any clinical use
  • Advise consulting with medical professionals for all health-related decisions

โญ If you find this project helpful, please consider giving it a star!

Made with โค๏ธ by the NeuroStroke AI Team

About

NeuroStroke AI: An open-source deep learning system for automated brain stroke detection from CT scans. Features CNN with VGG19 transfer learning, achieving 92% accuracy. Includes interactive web interface built with Streamlit. Empowering healthcare with AI. ๐Ÿง ๐Ÿ’™ #HealthcareAI #DeepLearning

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors