Brain Tumor Classification
CNN-based classification of brain tumor types from MRI scans.
Dataset
Source: Brain Tumor MRI Dataset (Kaggle)
Dataset Structure:
The dataset contains MRI images organized into 4 classes:
glioma- Glioma brain tumorsmeningioma- Meningioma brain tumorsnotumor- Healthy brain scans (no tumor)pituitary- Pituitary brain tumors
Each class has images split into Training/ and Testing/ folders.
Model Architecture
SimpleCNN with 10.7M parameters:
- 3 Convolutional blocks (32, 64, 128 filters)
- Batch Normalization + Dropout
- 2 Dense layers (256, 128 neurons)
- Softmax output (4 classes)
Results
| Configuration | Accuracy | Loss | Change |
|---|---|---|---|
| Baseline | 42.39% | 3.2599 | - |
| Fine-tuned | 46.70% | 2.8472 | +4.31% |
Fine-tuned hyperparameters: LR=0.0005, Batch=16, Epochs=40
Per-Class Performance (Fine-tuned)
| Class | Precision | Recall | F1-Score |
|---|---|---|---|
| Glioma | 1.00 | 0.14 | 0.24 |
| Meningioma | 1.00 | 0.21 | 0.35 |
| No Tumor | 0.37 | 0.92 | 0.53 |
| Pituitary | 0.54 | 0.66 | 0.59 |
Installation
Step 1: Install UV
Install uv if you haven't already:
curl -LsSf https://astral.sh/uv/install.sh | sh
Step 2: Setup Project
# Create virtual environment and install dependencies
uv sync
Step 3: Download Dataset
Use the automated download script:
# Make script executable
chmod +x download_dataset.sh
# Run the script (it will guide you through the setup)
./download_dataset.sh
What the script does:
- Checks UV installation
- Sets up virtual environment
- Installs Kaggle CLI
- Asks for Kaggle credentials (get from: https://www.kaggle.com/settings โ API โ Create New Token)
- Downloads dataset to
./data/ - Shows statistics
Manual download (alternative):
uv add kaggle
mkdir -p ~/.kaggle
# Create ~/.kaggle/kaggle.json with: {"username":"your_username","key":"your_api_key"}
chmod 600 ~/.kaggle/kaggle.json
uv run kaggle datasets download -d masoudnickparvar/brain-tumor-mri-dataset -p ./data --unzip
Legacy Installation (pip)
pip install -r requirements.txt
Requirements: TensorFlow, NumPy, Pandas, Matplotlib, Seaborn, Scikit-learn, Pillow
Usage
Data Exploration
# With uv
uv run python scripts/data_exploration.py
# Or with activated venv
python scripts/data_exploration.py
Training
# With uv
uv run python scripts/train_models.py
# Or with activated venv
python scripts/train_models.py
Training time: ~2 hours. Saves model to models/SimpleCNN_best.h5.
Prediction
# With uv (example with actual filename)
uv run python scripts/predict_single_image.py data/Testing/glioma/Te-gl_1.jpg
# Or with activated venv
python scripts/predict_single_image.py data/Testing/glioma/Te-gl_1.jpg
# Available folders: glioma, meningioma, notumor, pituitary
Limitations
- Low accuracy (46.70%) insufficient for clinical use
- Poor glioma detection (14% recall)
- Simple architecture inadequate for medical imaging
Additional Resources
- Dataset Source: Brain Tumor MRI Dataset on Kaggle
- Repository: GitHub
License
MIT License - Educational and research purposes.



