Downloads · 30 days
0
youth-ai-initiative/Brain_Tumor_Classifier_By_Group_3
Brain_Tumor_Classifier_By_Group_3 is a machine learning model from youth-ai-initiative. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
An advanced deep learning model developed to classify brain tumors from MRI scans using state-of-the-art techniques. This project leverages ResNet50 architecture with transfer learning to achieve high accuracy and rob…
Downloads · 30 days
0
Access
Public
Updated Nov 23, 2025
Repo size
94.9 MB
Likes
1
Public
Click a slice to open those files.
.pth94.4 MB · 99%
From the Hugging Face model README
An advanced deep learning model developed to classify brain tumors from MRI scans using state-of-the-art techniques. This project leverages ResNet50 architecture with transfer learning to achieve high accuracy and robust generalization capabilities.
Brain tumor classification is a critical task in medical imaging that requires high precision and reliability. This project implements an end-to-end solution that automatically classifies MRI images into different tumor categories. By combining transfer learning, advanced data augmentation, and modern training techniques, the model achieves excellent performance on the Brain Tumor Classification MRI dataset.
Key Highlights:
torch>=2.0.0
torchvision>=0.15.0
pandas>=1.5.0
numpy>=1.24.0
scikit-learn>=1.3.0
matplotlib>=3.7.0
seaborn>=0.12.0
pip install torch torchvision pandas numpy scikit-learn matplotlib seaborn
# Using Kaggle API
kaggle datasets download -d sartajbhuvaji/brain-tumor-classification-mri
unzip brain-tumor-classification-mri.zip
root_dir variable):root_dir = r"path/to/your/dataset"
The project utilizes the Brain Tumor Classification MRI dataset:
Dataset Source: Kaggle - Brain Tumor Classification MRI
python model.py
Modify the CONFIG dictionary to adjust training parameters:
CONFIG = {
'model_name': 'ResNet50_Improved',
'batch_size': 32, # Batch size for training
'lr': 0.001, # Initial learning rate
'epochs': 25, # Maximum number of epochs
'scheduler_step': 7, # Steps before LR reduction
'gamma': 0.1, # Learning rate decay factor
'weight_decay': 5e-4, # L2 regularization
'dropout_rate': 0.6, # Dropout probability
'early_stopping_patience': 5, # Epochs to wait before stopping
'early_stopping_min_delta': 0.001 # Minimum improvement threshold
}
# Load a trained model
model = get_model()
# Train with custom parameters
model_ft, logs = train_model(
model, criterion, optimizer, exp_lr_scheduler,
num_epochs=30
)
ResNet50 (ImageNet Pretrained)
↓
Global Average Pooling
↓
Dropout (60%)
↓
Fully Connected Layer (2048 → num_classes)
↓
Output (Class Predictions)
After training completes, the following files are generated in the improved_results/ directory:
| File | Description |
|---|---|
best_model.pth | Best model weights saved during training |
training_logs.csv | Per-epoch training statistics |
training_curves.png | Loss and accuracy curves |
confusion_matrix.png | Confusion matrix heatmap |
class_metrics.png | Per-class precision, recall, and F1-score |
The model is evaluated using standard classification metrics:
==================================================
Epoch 5/25
==================================================
TRAIN | Loss: 0.2345 | Acc: 0.9123 (91.23%)
TEST | Loss: 0.2789 | Acc: 0.8945 (89.45%)
✅ NEW RECORD! Test Acc: 0.8945
...
==================================================
SUMMARY REPORT
==================================================
Model: ResNet50_Improved
Total Epochs: 18
Best Test Accuracy: 0.9234 (92.34%)
Final Test Accuracy: 0.9156
Final Train Accuracy: 0.9512
Overfitting Gap: 0.0356
==================================================
DETAILED PERFORMANCE REPORT
==================================================
precision recall f1-score support
Glioma 0.9456 0.9231 0.9342 143
Meningioma 0.9167 0.9375 0.9270 160
Pituitary 0.9545 0.9167 0.9355 120
No Tumor 0.9200 0.9286 0.9243 175
micro avg 0.9287 0.9287 0.9287 598
macro avg 0.9342 0.9265 0.9302 598
weighted avg 0.9298 0.9287 0.9292 598
Transformations applied during training to enhance model robustness:
- RandomResizedCrop(224, scale=(0.8, 1.0)) # Random cropping and resizing
- RandomHorizontalFlip() # Horizontal flip with 50% probability
- RandomRotation(20°) # Random rotation ±20 degrees
- ColorJitter(brightness=0.3, contrast=0.3, saturation=0.2) # Color variations
- RandomAffine(translate=(0.1, 0.1)) # Random translation
- Normalize(mean=[0.485, 0.456, 0.406], # ImageNet normalization
std=[0.229, 0.224, 0.225])
These augmentations help the model learn invariant features and improve generalization.
Early stopping prevents overfitting by halting training when the model stops improving:
best_model.pthThis project implements cutting-edge techniques for improved performance:
✅ Transfer Learning: Leverage pre-trained ImageNet weights to reduce training time
✅ Strong Augmentation: Diverse augmentation strategies to prevent overfitting
✅ Dropout Regularization: 60% dropout to reduce co-adaptation of neurons
✅ Weight Decay (L2): 5×10⁻⁴ regularization to penalize large weights
✅ Learning Rate Scheduling: Dynamic LR adjustment based on training progress
✅ Early Stopping: Optimal model selection without manual intervention
✅ Comprehensive Evaluation: Multi-metric assessment including ROC-AUC scores
If you encounter GPU-related errors, the script automatically falls back to CPU:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"Using device: {device}")
Solution: Ensure CUDA and cuDNN are properly installed if you want GPU acceleration.
Reduce batch size to decrease memory consumption:
CONFIG['batch_size'] = 16 # Reduce from 32 to 16
Alternative solutions:
Verify the dataset path and structure:
print(os.listdir(root_dir)) # Check directory contents
print(os.listdir(os.path.join(root_dir, 'Training'))) # Check subdirectories
Ensure the directory structure matches:
Training/
├── glioma/
├── meningioma/
├── pituitary/
└── notumor/
Try these optimization strategies:
'epochs': 50'lr': 0.0005'dropout_rate': 0.7ResNet: Deep Residual Learning for Image Recognition - He et al., 2015
ImageNet Classification with Deep Convolutional Neural Networks - AlexNet
Note: This model is intended for educational purposes.