File size: 3,698 Bytes
b2c30c6
c703689
 
 
 
b2c30c6
 
 
 
c703689
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
title: Brain Tumor Classifier
emoji: 🧠
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
---

# 🧠 Brain Tumor Classification AI

**AI-powered MRI analysis for brain tumor detection and classification**

Using MoCo Self-Supervised Learning with Swin-Transformer backbone for high-accuracy tumor classification.

---

## ✨ Features

- 🎯 **High Accuracy**: ~95% on test dataset
- 🧠 **4-Class Classification**: Glioma, Meningioma, No Tumor, Pituitary
- πŸ“Š **GradCAM Visualization**: See which regions influenced the prediction
- πŸ“„ **PDF Reports**: Download professional analysis reports
- πŸ“± **Responsive Design**: Works on desktop, tablet, and mobile

---

## πŸš€ Quick Start

1. **Upload MRI Image**
   - Click upload area or drag & drop
   - Formats: JPEG, PNG, BMP, TIFF
   - Max size: 16 MB

2. **View Results**
   - Classification with confidence score
   - Probability distribution for all classes
   - GradCAM visualization showing influential regions

3. **Download Report**
   - Enter your name
   - Get professional PDF report
   - Includes all visualizations

---

## πŸ”¬ Model Details

**Architecture:**
- Backbone: Swin-Transformer (ImageNet pre-trained)
- Pre-training: MoCo (Momentum Contrast) - 30 epochs
- Fine-tuning: 2-stage process (30 epochs total)
- Head: Linear classifier (192 β†’ 4 classes)

**Training:**
- Dataset: 17,784 MRI images
- Classes: 4 (balanced)
- Validation: 10% held-out
- Test: 10% locked evaluation

**Performance:**
- Accuracy: ~95%
- Precision: ~95% (weighted)
- Recall: ~95% (weighted)
- F1-Score: ~95% (weighted)

---

## πŸ“Š Class Information

| Class | Description |
|-------|-------------|
| **Glioma** | Aggressive tumor from glial cells |
| **Meningioma** | Tumor from brain membranes |
| **No Tumor** | Healthy brain with no abnormalities |
| **Pituitary** | Tumor in pituitary gland |

---

## πŸŽ“ About GradCAM

The GradCAM (Gradient-weighted Class Activation Map) visualization shows:
- Which regions of the MRI influenced the model's decision
- Warmer colors (red/yellow) = higher importance
- Cooler colors (blue) = lower importance

This helps build trust in AI predictions by showing what the model "looked at" when making its decision.

---

## βš™οΈ Technical Stack

- **Framework**: Flask
- **Deep Learning**: PyTorch
- **Model**: Swin-Transformer
- **Visualization**: GradCAM
- **Reports**: ReportLab
- **Frontend**: HTML5, CSS3, JavaScript

---

## ⏱️ Performance

| Operation | Time |
|-----------|------|
| Model Load | ~10-15s (first time) |
| Classification | ~2-3s |
| GradCAM | Included in classification |
| PDF Report | ~2-3s |
| **Total** | **~15-20s per request** |

---

## πŸ›‘οΈ Data Privacy

- βœ… Images are NOT stored
- βœ… Processed in memory only
- βœ… Temporary files cleaned up
- βœ… No data collection
- βœ… Local processing (no external API calls)

---

## ⚠️ Disclaimer

**This tool is for research and educational purposes only.**

This AI model is NOT a substitute for professional medical diagnosis. All results should be verified by qualified healthcare professionals. Always consult a radiologist or medical doctor for clinical interpretation of MRI scans.

---

## πŸ“š Learn More

- **Paper**: MoCo: Momentum Contrast for Unsupervised Visual Representation Learning
- **Swin-Transformer**: Shifted Windows Transformer for CV

---

## 🀝 Contributing

Feedback and suggestions welcome!

For issues or improvements:
1. Note the problem
2. Share details about the image/results
3. Report via GitHub Issues

---

## πŸ“„ License

Academic use - Research and educational purposes

---

**Created with ❀️ for AI in Medical Imaging**

*Last Updated: 2026-04-20*