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
|
Download README.md from abink/Tumor_Classification: direct link, hf CLI and curl.
- Browser
- Download file 12.9 kB
-
https://huggingface.co/abink/Tumor_Classification/resolve/main/README.md
- Command line
-
hf download hf://abink/Tumor_Classification/README.md
-
curl -L -o README.md https://huggingface.co/abink/Tumor_Classification/resolve/main/README.md
12.9 kB
| # 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. | |