File size: 3,485 Bytes
50a1853
e05dd7f
 
50a1853
 
 
e05dd7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50a1853
e05dd7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: BRAIN_TUMOR_DEDECTOR
app_file: app.py
sdk: gradio
sdk_version: 5.6.0
---
# 🧠 Brain Tumor MRI Classification

[![Python](https://img.shields.io/badge/Python-3.7%2B-blue.svg)](https://www.python.org/)
[![TensorFlow](https://img.shields.io/badge/TensorFlow-2.0%2B-orange.svg)](https://www.tensorflow.org/)
[![Streamlit](https://img.shields.io/badge/Streamlit-1.0%2B-red.svg)](https://streamlit.io/)

A deep learning project that uses transfer learning and custom CNN architectures to classify brain tumors from MRI scans into four categories: Glioma, Meningioma, Pituitary, and No Tumor.

## 🎯 Project Overview

This project implements two different deep learning approaches:
1. **Transfer Learning with Xception**: Leveraging a pre-trained model for enhanced accuracy
2. **Custom CNN**: A dedicated convolutional neural network built from scratch

Both models are deployed through a user-friendly Streamlit web interface that provides:
- Real-time tumor classification
- Confidence scores
- Saliency maps for model interpretability
- AI-generated explanations of the model's focus areas

## πŸ“Š Model Architecture & Performance

### Transfer Learning Model (Xception)
- Pre-trained on ImageNet dataset
- 36 convolutional layers
- 21 million parameters
- Features:
  - Max pooling
  - Dropout layers for regularization
  - Softmax activation for classification
- Performance metrics:
  - High accuracy on test set
  - Robust against overfitting

### Custom CNN Model
- 4 convolutional layers
- 4.7 million parameters
- Architecture:
  - Multiple Conv2D layers with ReLU activation
  - MaxPooling2D layers
  - Dropout for regularization
  - Dense layers with L2 regularization
  - Softmax output layer

## πŸ› οΈ Installation

```bash
# Clone the repository
git clone https://github.com/stonewerner/brain-tumor-ML.git
cd brain-tumor-ML

# Install required packages
pip install -r requirements.txt
```

## πŸ“¦ Dependencies

- tensorflow >= 2.0
- streamlit
- numpy
- pandas
- pillow
- plotly
- opencv-python
- google-generativeai
- python-dotenv

## πŸš€ Usage


### Running the Web App

```bash
streamlit run app.py
```

## πŸ–₯️ Web Interface Features

1. **Image Upload**: Support for jpg, jpeg, and png formats
2. **Model Selection**: Choose between Transfer Learning and Custom CNN
3. **Visualization**:
   - Original MRI scan
   - Saliency map highlighting model focus areas
4. **Results Display**:
   - Predicted tumor type
   - Confidence scores
   - Interactive probability chart
   - AI-generated explanation of the classification

## πŸ“ˆ Data Processing

The project includes robust data handling:
- Image preprocessing and augmentation
- Brightness adjustment for training data
- Proper train/validation/test splits
- Standardized image sizing

## πŸ” Model Interpretability

- **Saliency Maps**: Visual explanation of model decisions
- **Region Focus**: Highlights critical areas in MRI scans
- **AI Explanations**: Generated using Google's Gemini model
- **Confidence Metrics**: Probability distribution across classes

## πŸ‘₯ 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


## πŸ“§ Contact

Stone Werner - stonewerner.com

Project Link: [https://github.com/stonewerner/brain-tumor-ML](https://github.com/stonewerner/brain-tumor-ML)