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.
- About the Project
- Key Features
- Dataset
- Model Architecture
- Installation
- Usage
- Project Structure
- Results
- Technologies Used
- Challenges & Solutions
- Future Enhancements
- Contributing
- License
- Acknowledgments
- Contact
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
- ๐ฌ 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
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
Brain_Data_Organised/
โโโ Normal/ # CT scans without stroke
โโโ Stroke/ # CT scans with stroke indicators
- Resizing: All images resized to 224x224 pixels
- Color Conversion: Converted to RGB format (3 channels)
- Normalization: Pixel values normalized to [0, 1] range
- Data Augmentation:
- Random rotation
- Brightness adjustment
- Horizontal flipping
- Zoom variations
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
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
- Optimizer: Adam
- Loss Function: Binary Crossentropy
- Metrics: Accuracy
- Batch Size: 32
- Epochs: 10
- Train/Test Split: 90/10
- Python 3.8 or higher
- pip package manager
- (Optional) Virtual environment tool (venv, conda)
-
Clone the repository
git clone https://github.com/yourusername/neurostroke-ai.git cd neurostroke-ai -
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
-
Install required dependencies
pip install -r requirements.txt
-
Download the dataset (if training from scratch)
- Visit Kaggle Dataset
- Download and extract to a
data/folder in the project root
-
Download pre-trained model (optional)
- The
stroke_detection_model.h5file is included in the repository - If missing, you'll need to train the model (see Training section)
- The
The easiest way to use NeuroStroke AI is through the web interface:
streamlit run app.pyThis will:
- Start a local web server (usually at
http://localhost:8501) - Open the application in your default browser
- Display the upload interface
Using the Web App:
- Click "Browse files" or drag and drop a CT scan image
- Supported formats: JPG, JPEG, PNG
- Click the "Predict" button
- View the prediction result and confidence score
To train the model from scratch using the Jupyter notebook:
-
Install Jupyter
pip install jupyter
-
Launch Jupyter Notebook
jupyter notebook
-
Open the training notebook
- Navigate to
brain-stroke-prediction-cnn.ipynb - Run all cells sequentially
- Navigate to
-
Save the trained model
- The model will be saved as
stroke_detection_model.h5 - This file is used by the Streamlit app
- The model will be saved as
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}%")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
| Metric | Training Set | Test Set |
|---|---|---|
| Accuracy | ~95% | ~92% |
| Loss | ~0.12 | ~0.18 |
| Precision | ~94% | ~91% |
| Recall | ~96% | ~93% |
| F1-Score | ~95% | ~92% |
Predicted
Normal Stroke
Actual Normal [TN] [FP]
Stroke [FN] [TP]
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
- Python 3.10+: Primary programming language
- TensorFlow 2.x: Deep learning framework
- Keras: High-level neural networks API
- Streamlit: Interactive web application framework
- NumPy: Numerical computing
- Pandas: Data manipulation and analysis
- PIL (Pillow): Image processing
- OpenCV: Computer vision operations
- Matplotlib: Plotting and visualization
- Seaborn: Statistical data visualization
- Scikit-learn: Model evaluation metrics
- TensorFlow Hub: Pre-trained model integration
- Jupyter Notebook: Interactive development environment
- VS Code: Code editor
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
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
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
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
-
Multi-Modal Data Integration
- Incorporate patient medical history
- Include clinical reports and vital signs
- Combine MRI and CT scan analysis
-
Model Improvements
- Experiment with other architectures (ResNet, EfficientNet)
- Implement ensemble methods
- Increase dataset size with synthetic data generation
-
User Interface Enhancements
- Add batch processing capability
- Implement image annotation tools
- Create detailed prediction reports (PDF export)
-
Real-Time Clinical Deployment
- Integration with hospital PACS systems
- Real-time processing pipeline
- DICOM format support
-
Explainable AI (XAI)
- Implement Grad-CAM for visual explanations
- Show which regions influenced the prediction
- Generate attention maps
-
Mobile Application
- Develop iOS/Android apps
- Enable offline predictions
- Secure cloud storage for medical data
-
Multi-Class Classification
- Detect different types of strokes
- Identify stroke severity levels
- Predict stroke location and size
-
Regulatory Compliance
- Pursue FDA/CE certification
- Implement HIPAA compliance
- Clinical trial validation
Contributions are what make the open-source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated!
-
Fork the Project
# Click the 'Fork' button on GitHub -
Create your Feature Branch
git checkout -b feature/AmazingFeature
-
Commit your Changes
git commit -m 'Add some AmazingFeature' -
Push to the Branch
git push origin feature/AmazingFeature
-
Open a Pull Request
- Go to your fork on GitHub
- Click "New Pull Request"
- Describe your changes
- 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
- ๐ Bug fixes and issue resolution
- โจ New features and enhancements
- ๐ Documentation improvements
- ๐งช Additional test cases
- ๐จ UI/UX improvements
- ๐ Internationalization (i18n)
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.
- 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
- Shen, D., Wu, G., & Suk, H. I. (2017). Deep learning in medical image analysis. Annual Review of Biomedical Engineering, 19, 221-248.
- Litjens, G., et al. (2017). A survey on deep learning in medical image analysis. Medical Image Analysis, 42, 60-88.
- Simonyan, K., & Zisserman, A. (2014). Very deep convolutional networks for large-scale image recognition. arXiv preprint arXiv:1409.1556.
Project Maintainer: Susreel Somavarapu
- GitHub: @Susreel7
- Email: susreel.somavarapu@gmail.com
- LinkedIn: Susreel Somavarapu
Project Link: https://github.com/Susreel7/neurostroke-ai
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