CoolFace
Modelpublic

abink/Tumor_Classification

sourceHugging Faceupdated 1mo agoView on Hugging Face
0likes16downloads
README.md371 linesDownload Raw Back to root
1# Brain MRI Tumor Classification Using Deep Learning2![head x ray hero](https://cdn-uploads.huggingface.co/production/uploads/65eea7642cc24ebc6dbf7400/h2rLOLfAqiJAlzdOvNlbr.jpeg)3 4## 1. Introduction5 6Cancer 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.7 8**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.9 10This 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**.11 12The 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.13 14---15 16## 2. Medical Imaging Dataset17 18The project uses brain MRI images representing four classification categories:19 201. **Glioma**212. **Meningioma**223. **Pituitary tumor**234. **No Tumor**24 25Gliomas, 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.26 27The dataset was organized as a four-class image-classification problem with a balanced test set of **1,600 images (400 per class)**.28 29A consistent preprocessing and augmentation pipeline was maintained across the different architectures to make the model comparison more meaningful.30 31**Input image size:** `128 × 128 × 3`32 33---34 35## 3. Project Objective36 37The 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.38 39Rather than relying on a single neural network, multiple established architectures were evaluated:40 41* **VGG16**42* **ResNet50**43* **DenseNet121**44* **EfficientNetB0**45 46The models were first evaluated using their pretrained ImageNet features and subsequently investigated through **domain-specific fine-tuning**.47 48The project also examined how changing the classification head, trainable layers, learning rate, optimizer, regularization, and fine-tuning strategy affected performance.49 50---51 52# 4. Transfer Learning and Model Development53 54All models used **ImageNet-pretrained convolutional backbones**. The original classification layers were removed and replaced with task-specific classification heads.55 56The general workflow was:57 58```text59Brain MRI Dataset60        ↓61Preprocessing & Augmentation62        ↓63Train / Validation / Test Split64        ↓65ImageNet-Pretrained CNN66        ↓67Custom Classification Head68        ↓69Initial Transfer Learning70        ↓71Layer Unfreezing & Fine-Tuning72        ↓73Performance Evaluation74        ↓75Model Comparison76```77 78For the classification heads, architectures using:79 80```text81GlobalAveragePooling2D82        ↓83Dense Layers84        ↓85Batch Normalization86        ↓87Dropout88        ↓894-Class Softmax90```91 92were investigated.93 94Fine-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.95 96---97 98# 5. Model Comparison99 100The four architectures showed substantially different behavior on the brain MRI classification task.101 102| Model              | Initial Accuracy | Fine-Tuned Accuracy | Final Status    |103| ------------------ | ---------------: | ------------------: | --------------- |104| **VGG16**          |           83.44% |          **91.50%** | ⭐ Selected      |105| **DenseNet121**    |           83.00% |          **83.00%** | Strong baseline |106| **ResNet50**       |           68.00% |          **81.00%** | Baseline        |107| **EfficientNetB0** |           33.00% |          **35.00%** | Not selected    |108 109### Best-performing model110 111**Fine-tuned VGG16**112 113* Test Accuracy: **91.50%**114* Macro F1: **0.91**115* Weighted F1: **0.91**116 117Fine-tuning improved VGG16 from **83.44% to 91.50%**, an improvement of **8.06 percentage points**.118 119---120 121# 6. VGG16122 123VGG16 was the strongest architecture evaluated in this project.124 125### Classification Architecture126 127```text128VGG16 (ImageNet pretrained)129        ↓130GlobalAveragePooling2D131        ↓132Dense(256) + BatchNorm + Dropout(0.4)133        ↓134Dense(128) + BatchNorm + Dropout(0.3)135        ↓136Dense(4, Softmax)137```138 139The initial VGG16 experiment used the pretrained backbone with a custom classification head.140 141The classification head was subsequently improved by replacing `Flatten()` with `GlobalAveragePooling2D`, reducing the number of parameters and helping control overfitting.142 143### Fine-Tuning144 145The final convolutional block was unfrozen while earlier layers remained frozen.146 147Training used:148 149* Adam optimizer150* Initial learning rate: `1 × 10⁻⁴`151* Fine-tuning learning rate: `1 × 10⁻⁵`152* Early stopping153* ReduceLROnPlateau154* Model checkpointing155 156### Performance157 158| Class      | Precision |   Recall |       F1 |159| ---------- | --------: | -------: | -------: |160| Glioma     |      0.95 |     0.98 | **0.97** |161| Meningioma |      0.92 | **1.00** | **0.96** |162| No Tumor   |      0.84 |     0.93 | **0.88** |163| Pituitary  |      0.97 |     0.75 | **0.84** |164 165**Final accuracy: 91.50%**166 167The strong performance across the tumor classes made VGG16 the selected architecture for subsequent stages of the project.168 169---170 171# 7. ResNet50172 173ResNet50 was evaluated as an alternative deep residual architecture.174 175### Architecture176 177```text178ResNet50 (ImageNet pretrained)179        ↓180GlobalAveragePooling2D181        ↓182Dense(256) + BatchNorm + Dropout(0.4)183        ↓184Dense(128) + BatchNorm + Dropout(0.3)185        ↓186Dense(4, Softmax)187```188 189The backbone was initially frozen and the classification head was trained. The final convolutional section was subsequently unfrozen for domain-specific fine-tuning.190 191### Results192 193| Class      | Precision | Recall |   F1 |194| ---------- | --------: | -----: | ---: |195| Glioma     |      0.89 |   0.91 | 0.90 |196| Meningioma |      0.78 |   0.99 | 0.87 |197| No Tumor   |      0.78 |   0.66 | 0.72 |198| Pituitary  |      0.77 |   0.68 | 0.72 |199 200**Initial accuracy:** 68.00%201 202**Fine-tuned accuracy:** 81.00%203 204Fine-tuning produced a substantial improvement of approximately **13 percentage points**, demonstrating that adaptation of pretrained features to the MRI domain was beneficial.205 206However, ResNet50 remained below the performance of fine-tuned VGG16.207 208---209 210# 8. DenseNet121211 212DenseNet121 was included because dense feature reuse and hierarchical feature propagation make it an important architecture for medical-image classification.213 214### Architecture215 216```text217DenseNet121 (ImageNet pretrained)218        ↓219GlobalAveragePooling2D220        ↓221Dense(256) + BatchNorm + Dropout(0.4)222        ↓223Dense(128) + BatchNorm + Dropout(0.3)224        ↓225Dense(4, Softmax)226```227 228### Fine-Tuning Investigation229 230The initial fine-tuning strategy reduced performance from:231 232**83% → 79%**233 234A more conservative DenseNet-specific strategy was then investigated:235 236* Later convolutional layers selectively unfrozen237* Batch Normalization layers kept frozen238* AdamW optimizer239* Learning rate: `3 × 10⁻⁶`240* Weight decay: `1 × 10⁻⁴`241* Early stopping242* ReduceLROnPlateau243 244The optimized configuration recovered the performance to **83%**, but did not provide a meaningful overall improvement over the original frozen-backbone configuration.245 246### Best Results247 248| Class      | Precision | Recall |   F1 |249| ---------- | --------: | -----: | ---: |250| Glioma     |      0.85 |   0.96 | 0.90 |251| Meningioma |      0.83 |   0.97 | 0.90 |252| No Tumor   |      0.77 |   0.72 | 0.74 |253| Pituitary  |      0.88 |   0.66 | 0.76 |254 255**Accuracy: 83.00%**256 257**Macro F1: 0.82**258 259DenseNet121 therefore provided a strong baseline but did not outperform the fine-tuned VGG16.260 261---262 263# 9. EfficientNetB0264 265EfficientNetB0 was evaluated using the same dataset and general transfer-learning framework.266 267### Architecture268 269```text270EfficientNetB0 (ImageNet pretrained)271        ↓272GlobalAveragePooling2D273        ↓274Dense(256) + BatchNorm + Dropout(0.4)275        ↓276Dense(128) + BatchNorm + Dropout(0.3)277        ↓278Dense(4, Softmax)279```280 281The backbone was initially frozen and subsequently partially fine-tuned.282 283### Results284 285**Initial accuracy: 33%**286 287**Fine-tuned accuracy: 35%**288 289The model exhibited severe class-collapse behavior and failed to reliably identify some of the tumor categories.290 291Therefore, EfficientNetB0 was not selected for further development within this project.292 293---294 295# 10. Overall Findings296 297The experiments demonstrated that **architecture selection and fine-tuning strategy have a major effect on medical-image classification performance**.298 299The results were:300 301| Architecture   | Initial | Fine-Tuned |  Improvement |302| -------------- | ------: | ---------: | -----------: |303| **VGG16**      |  83.44% | **91.50%** | **+8.06 pp** |304| ResNet50       |  68.00% |     81.00% |    +13.00 pp |305| DenseNet121    |  83.00% |     83.00% |         0 pp |306| EfficientNetB0 |  33.00% |     35.00% |     +2.00 pp |307 308An important observation was that **fine-tuning did not improve every architecture equally**.309 310* VGG16 responded strongly to domain-specific fine-tuning.311* ResNet50 showed substantial improvement.312* DenseNet121 required a more conservative fine-tuning strategy and ultimately remained around its baseline performance.313* EfficientNetB0 showed severe classification difficulties under the tested configuration.314 315This 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.316 317---318 319# 11. Final Model320 321Based on the comparative evaluation, **fine-tuned VGG16** was selected as the best-performing model.322 323### Final Performance324 325**91.50% Test Accuracy**326 327**0.91 Macro F1**328 329| Class      | F1-score |330| ---------- | -------: |331| Glioma     | **0.97** |332| Meningioma | **0.96** |333| No Tumor   | **0.88** |334| Pituitary  | **0.84** |335 336The model demonstrated particularly strong recognition of Glioma and Meningioma, while Pituitary tumor classification remained the more challenging category because of its lower recall.337 338---339 340# 12. Medical Physics and Future Development341 342This 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.343 344The 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.345 346The next stage of the project focuses on:347 348* **Confusion-matrix analysis**349* Sensitivity and specificity350* ROC-AUC analysis351* Precision-recall analysis352* False-positive and false-negative investigation353* **Grad-CAM explainability**354* Visualization of image regions influencing model predictions355* Model limitations and potential clinical considerations356* Development of a small **Streamlit demonstration interface**357 358Grad-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.359 360---361 362# Conclusion363 364This project demonstrated the application of **transfer learning and deep convolutional neural networks to brain MRI tumor classification**.365 366Four 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**.367 368The 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.369 370The 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.371