Instructions to use abink/Tumor_Classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use abink/Tumor_Classification with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://abink/Tumor_Classification") - Notebooks
- Google Colab
- Kaggle
File size: 12,946 Bytes
e39aed8 | 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | # Brain MRI Tumor Classification Using Deep Learning

## 1. Introduction
Cancer remains one of the major global health challenges, and the increasing availability of medical imaging has created opportunities to support clinicians through computer-aided image analysis. In oncology, medical imaging plays an important role in the detection, characterization, treatment planning, and follow-up of tumors.
**Brain MRI** is particularly important in the assessment of brain tumors because MRI provides detailed soft-tissue contrast without exposing the patient to ionizing radiation. However, interpretation of large numbers of medical images can be time-consuming and requires considerable clinical expertise.
This project explores the use of **deep learning for automated brain MRI tumor classification**, combining concepts from **medical imaging, artificial intelligence, machine learning, and deep learning**.
The objective was not simply to train a CNN and report its accuracy, but to investigate how different pretrained deep-learning architectures perform on brain MRI data and how **transfer learning, layer selection, fine-tuning, optimization, and regularization** affect classification performance.
---
## 2. Medical Imaging Dataset
The project uses brain MRI images representing four classification categories:
1. **Glioma**
2. **Meningioma**
3. **Pituitary tumor**
4. **No Tumor**
Gliomas, meningiomas, and pituitary tumors represent three major tumor categories considered in this classification task, while the **No Tumor** class provides a non-tumor reference category.
The dataset was organized as a four-class image-classification problem with a balanced test set of **1,600 images (400 per class)**.
A consistent preprocessing and augmentation pipeline was maintained across the different architectures to make the model comparison more meaningful.
**Input image size:** `128 Γ 128 Γ 3`
---
## 3. Project Objective
The main objective was to investigate whether transfer-learning-based CNN architectures could effectively learn discriminative features from brain MRI images and determine which architecture provided the most reliable classification performance.
Rather than relying on a single neural network, multiple established architectures were evaluated:
* **VGG16**
* **ResNet50**
* **DenseNet121**
* **EfficientNetB0**
The models were first evaluated using their pretrained ImageNet features and subsequently investigated through **domain-specific fine-tuning**.
The project also examined how changing the classification head, trainable layers, learning rate, optimizer, regularization, and fine-tuning strategy affected performance.
---
# 4. Transfer Learning and Model Development
All models used **ImageNet-pretrained convolutional backbones**. The original classification layers were removed and replaced with task-specific classification heads.
The general workflow was:
```text
Brain MRI Dataset
β
Preprocessing & Augmentation
β
Train / Validation / Test Split
β
ImageNet-Pretrained CNN
β
Custom Classification Head
β
Initial Transfer Learning
β
Layer Unfreezing & Fine-Tuning
β
Performance Evaluation
β
Model Comparison
```
For the classification heads, architectures using:
```text
GlobalAveragePooling2D
β
Dense Layers
β
Batch Normalization
β
Dropout
β
4-Class Softmax
```
were investigated.
Fine-tuning was performed by selectively unfreezing deeper convolutional layers while keeping earlier feature-extraction layers frozen. Lower learning rates were used during fine-tuning to avoid excessively changing useful pretrained features.
---
# 5. Model Comparison
The four architectures showed substantially different behavior on the brain MRI classification task.
| Model | Initial Accuracy | Fine-Tuned Accuracy | Final Status |
| ------------------ | ---------------: | ------------------: | --------------- |
| **VGG16** | 83.44% | **91.50%** | β Selected |
| **DenseNet121** | 83.00% | **83.00%** | Strong baseline |
| **ResNet50** | 68.00% | **81.00%** | Baseline |
| **EfficientNetB0** | 33.00% | **35.00%** | Not selected |
### Best-performing model
**Fine-tuned VGG16**
* Test Accuracy: **91.50%**
* Macro F1: **0.91**
* Weighted F1: **0.91**
Fine-tuning improved VGG16 from **83.44% to 91.50%**, an improvement of **8.06 percentage points**.
---
# 6. VGG16
VGG16 was the strongest architecture evaluated in this project.
### Classification Architecture
```text
VGG16 (ImageNet pretrained)
β
GlobalAveragePooling2D
β
Dense(256) + BatchNorm + Dropout(0.4)
β
Dense(128) + BatchNorm + Dropout(0.3)
β
Dense(4, Softmax)
```
The initial VGG16 experiment used the pretrained backbone with a custom classification head.
The classification head was subsequently improved by replacing `Flatten()` with `GlobalAveragePooling2D`, reducing the number of parameters and helping control overfitting.
### Fine-Tuning
The final convolutional block was unfrozen while earlier layers remained frozen.
Training used:
* Adam optimizer
* Initial learning rate: `1 Γ 10β»β΄`
* Fine-tuning learning rate: `1 Γ 10β»β΅`
* Early stopping
* ReduceLROnPlateau
* Model checkpointing
### Performance
| Class | Precision | Recall | F1 |
| ---------- | --------: | -------: | -------: |
| Glioma | 0.95 | 0.98 | **0.97** |
| Meningioma | 0.92 | **1.00** | **0.96** |
| No Tumor | 0.84 | 0.93 | **0.88** |
| Pituitary | 0.97 | 0.75 | **0.84** |
**Final accuracy: 91.50%**
The strong performance across the tumor classes made VGG16 the selected architecture for subsequent stages of the project.
---
# 7. ResNet50
ResNet50 was evaluated as an alternative deep residual architecture.
### Architecture
```text
ResNet50 (ImageNet pretrained)
β
GlobalAveragePooling2D
β
Dense(256) + BatchNorm + Dropout(0.4)
β
Dense(128) + BatchNorm + Dropout(0.3)
β
Dense(4, Softmax)
```
The backbone was initially frozen and the classification head was trained. The final convolutional section was subsequently unfrozen for domain-specific fine-tuning.
### Results
| Class | Precision | Recall | F1 |
| ---------- | --------: | -----: | ---: |
| Glioma | 0.89 | 0.91 | 0.90 |
| Meningioma | 0.78 | 0.99 | 0.87 |
| No Tumor | 0.78 | 0.66 | 0.72 |
| Pituitary | 0.77 | 0.68 | 0.72 |
**Initial accuracy:** 68.00%
**Fine-tuned accuracy:** 81.00%
Fine-tuning produced a substantial improvement of approximately **13 percentage points**, demonstrating that adaptation of pretrained features to the MRI domain was beneficial.
However, ResNet50 remained below the performance of fine-tuned VGG16.
---
# 8. DenseNet121
DenseNet121 was included because dense feature reuse and hierarchical feature propagation make it an important architecture for medical-image classification.
### Architecture
```text
DenseNet121 (ImageNet pretrained)
β
GlobalAveragePooling2D
β
Dense(256) + BatchNorm + Dropout(0.4)
β
Dense(128) + BatchNorm + Dropout(0.3)
β
Dense(4, Softmax)
```
### Fine-Tuning Investigation
The initial fine-tuning strategy reduced performance from:
**83% β 79%**
A more conservative DenseNet-specific strategy was then investigated:
* Later convolutional layers selectively unfrozen
* Batch Normalization layers kept frozen
* AdamW optimizer
* Learning rate: `3 Γ 10β»βΆ`
* Weight decay: `1 Γ 10β»β΄`
* Early stopping
* ReduceLROnPlateau
The optimized configuration recovered the performance to **83%**, but did not provide a meaningful overall improvement over the original frozen-backbone configuration.
### Best Results
| Class | Precision | Recall | F1 |
| ---------- | --------: | -----: | ---: |
| Glioma | 0.85 | 0.96 | 0.90 |
| Meningioma | 0.83 | 0.97 | 0.90 |
| No Tumor | 0.77 | 0.72 | 0.74 |
| Pituitary | 0.88 | 0.66 | 0.76 |
**Accuracy: 83.00%**
**Macro F1: 0.82**
DenseNet121 therefore provided a strong baseline but did not outperform the fine-tuned VGG16.
---
# 9. EfficientNetB0
EfficientNetB0 was evaluated using the same dataset and general transfer-learning framework.
### Architecture
```text
EfficientNetB0 (ImageNet pretrained)
β
GlobalAveragePooling2D
β
Dense(256) + BatchNorm + Dropout(0.4)
β
Dense(128) + BatchNorm + Dropout(0.3)
β
Dense(4, Softmax)
```
The backbone was initially frozen and subsequently partially fine-tuned.
### Results
**Initial accuracy: 33%**
**Fine-tuned accuracy: 35%**
The model exhibited severe class-collapse behavior and failed to reliably identify some of the tumor categories.
Therefore, EfficientNetB0 was not selected for further development within this project.
---
# 10. Overall Findings
The experiments demonstrated that **architecture selection and fine-tuning strategy have a major effect on medical-image classification performance**.
The results were:
| Architecture | Initial | Fine-Tuned | Improvement |
| -------------- | ------: | ---------: | -----------: |
| **VGG16** | 83.44% | **91.50%** | **+8.06 pp** |
| ResNet50 | 68.00% | 81.00% | +13.00 pp |
| DenseNet121 | 83.00% | 83.00% | 0 pp |
| EfficientNetB0 | 33.00% | 35.00% | +2.00 pp |
An important observation was that **fine-tuning did not improve every architecture equally**.
* VGG16 responded strongly to domain-specific fine-tuning.
* ResNet50 showed substantial improvement.
* DenseNet121 required a more conservative fine-tuning strategy and ultimately remained around its baseline performance.
* EfficientNetB0 showed severe classification difficulties under the tested configuration.
This demonstrates that pretrained architectures cannot simply be treated as interchangeable models; their layer structure, feature representations, and fine-tuning behavior need to be considered when applying deep learning to medical images.
---
# 11. Final Model
Based on the comparative evaluation, **fine-tuned VGG16** was selected as the best-performing model.
### Final Performance
**91.50% Test Accuracy**
**0.91 Macro F1**
| Class | F1-score |
| ---------- | -------: |
| Glioma | **0.97** |
| Meningioma | **0.96** |
| No Tumor | **0.88** |
| Pituitary | **0.84** |
The model demonstrated particularly strong recognition of Glioma and Meningioma, while Pituitary tumor classification remained the more challenging category because of its lower recall.
---
# 12. Medical Physics and Future Development
This project was developed at the intersection of **medical imaging, deep learning, and quantitative analysis**, with relevance to the growing role of computational methods in modern medical physics.
The current model should be considered a **research/educational classification system rather than a clinical diagnostic tool**. High classification accuracy alone is not sufficient for clinical deployment.
The next stage of the project focuses on:
* **Confusion-matrix analysis**
* Sensitivity and specificity
* ROC-AUC analysis
* Precision-recall analysis
* False-positive and false-negative investigation
* **Grad-CAM explainability**
* Visualization of image regions influencing model predictions
* Model limitations and potential clinical considerations
* Development of a small **Streamlit demonstration interface**
Grad-CAM and error analysis are particularly important because they can help investigate whether the CNN is responding to medically meaningful regions of the MRI rather than irrelevant image characteristics.
---
# Conclusion
This project demonstrated the application of **transfer learning and deep convolutional neural networks to brain MRI tumor classification**.
Four architectures were systematically evaluated under a consistent experimental framework. While DenseNet121 and ResNet50 provided useful comparative baselines, **fine-tuned VGG16 achieved the best performance with 91.50% test accuracy and a 0.91 macro F1-score**.
The project also demonstrated that successful medical-image deep learning requires more than selecting a powerful CNN. **Preprocessing, architecture selection, classification-head design, layer freezing, fine-tuning depth, learning rate, optimization and regularization** all influence model performance.
The final stage will focus on **model interpretability and clinically relevant evaluation**, moving the project beyond simple accuracy-based classification toward a more complete medical-imaging research workflow.
|