A sophisticated web-based application for brain tumor classification using deep learning. This project leverages transfer learning with ResNet50 to classify MRI brain images into four categories: No Tumor, Meningioma, Glioma, and Pituitary tumors.
- Features
- Technology Stack
- Project Structure
- Installation
- Usage
- Model Architecture
- Dataset Information
- Important Notes
- Future Improvements
- License
- Web-based Interface: Modern, responsive UI with gradient animations and professional design
- Real-time Image Classification: Instant brain tumor classification from uploaded MRI scans
- Transfer Learning: Powered by ResNet50 architecture with pretrained ImageNet weights
- Four-class Classification: Distinguishes between:
- No Tumor
- Meningioma
- Glioma
- Pituitary tumors
- User-Friendly Design: Intuitive file upload with visual feedback and clear results display
- Mobile Responsive: Fully responsive design for desktop, tablet, and mobile devices
- Professional UI/UX: Modern gradient animations, smooth transitions, and polished visual elements
| Component | Technology |
|---|---|
| Backend Framework | Flask 3.1.2 |
| Deep Learning | PyTorch 2.10.0 |
| Computer Vision | torchvision 0.25.0 |
| Image Processing | Pillow 12.1.0 |
| Numerical Computing | NumPy 2.4.1 |
| Frontend | HTML5, CSS3, Vanilla JavaScript |
| Python Version | 3.8+ |
Brain Tumor Analysis/
βββ app.py # Flask application main file
βββ initialize_model.py # Script to create untrained model
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
βββ models/
β βββ bt_resnet50_model.pt # Trained/untrained model weights
βββ static/
β βββ css/
β β βββ main.css # Styled CSS with animations
β βββ images/
β β βββ brain_logo.png # Project logo
β β βββ (uploaded images) # User uploaded MRI scans
βββ templates/
β βββ index.html # Home page with upload form
β βββ pred.html # Results page with classification
βββ test_images/ # Sample test images
βββ venv/ # Python virtual environment
βββ brain_tumor_dataset_preparation.ipynb # Dataset preparation notebook
- Python 3.8 or higher
- pip (Python package manager)
- 2GB RAM minimum
- CUDA 12.x (optional, for GPU acceleration)
cd "Brain Tumor Analysis"# Create virtual environment
python3 -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtpython initialize_model.pyThis creates the untrained model architecture saved to models/bt_resnet50_model.pt.
# Activate virtual environment (if not already activated)
source venv/bin/activate
# Run Flask development server
python app.pyThe application will start on http://127.0.0.1:5000
- Open Browser: Navigate to
http://127.0.0.1:5000 - Upload Image: Click the upload area or drag-and-drop a brain MRI scan (JPG, PNG, etc.)
- Analyze: Click "Analyze Image" button
- View Results: See classification result with color-coded output:
- π’ Green: No Tumor
- π Orange: Meningioma
- π΄ Red: Glioma
- π£ Purple: Pituitary tumor
- Analyze Another: Click button to return to home and analyze another image
- Base Model: ResNet50 with ImageNet pretrained weights
- Input Size: 512Γ512 RGB images
- Preprocessing:
- Resize to 512Γ512
- Normalize with ImageNet mean/std
- Convert to tensor
- Layer 1: 2048 β 512 (ReLU activation)
- Dropout: 0.5 (prevents overfitting)
- Layer 2: 512 β 256 (ReLU activation)
- Dropout: 0.3
- Layer 3: 256 β 128 (ReLU activation)
- Output Layer: 128 β 4 (softmax for multi-class classification)
Total Parameters: ~25.5 Million
Trainable Parameters: ~3.3 Million (classification head)
Frozen Parameters: ~23.5 Million (ResNet50 backbone)
The model is designed to work with the Brain Tumor MRI Dataset from Figshare:
- Source: https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset
- Classes: 4 types (No Tumor, Meningioma, Glioma, Pituitary)
- Image Count: ~7,000 total images
- Image Format: JPG/PNG
- Image Dimensions: Variable (preprocessing handles resizing)
- Training-Validation Split: 70-30
- Batch Size: 32-64
- Learning Rate: 0.0001 (Adam optimizer)
- Epochs: 50-100
- Loss Function: CrossEntropyLoss
- Early Stopping: Monitor validation accuracy
- The
initialize_model.pyscript creates an untrained ResNet50 architecture - Random predictions are returned until proper training is performed
- For resume/production use, you must train the model on actual brain tumor data
To use this project effectively:
- Obtain Dataset: Download from Kaggle or Figshare
- Prepare Data: Use
brain_tumor_dataset_preparation.ipynbnotebook - Train Model:
- Use PyTorch training loop
- Modify
app.pyto load trained weights - Test on validation set (aim for 90%+ accuracy)
- Evaluate: Test with medical MRI samples
- Deploy: Update model path in Flask app
This tool is experimental and should NOT be used for:
- Actual medical diagnosis
- Clinical decision making
- Patient treatment planning
Always consult qualified medical professionals for brain tumor diagnosis and treatment.
Edit in app.py line ~45:
class_names = ['None', 'Meningioma', 'Glioma', 'Pituitary']Edit in app.py line ~30:
UPLOAD_FOLDER = 'static/images'Edit in app.py line ~35:
IMG_SIZE = 512 # Change as needed- Description: Render home page
- Response: HTML page with upload form
- Description: Upload image and get classification
- Parameters: Form data with
bt_imagefile - Response: HTML results page with prediction
- Description: API endpoint for JSON predictions
- Request: JSON with base64 encoded image
- Response: JSON with classification results
- Color Scheme: Professional navy blue (#0f172a) and medical teal (#0891b2)
- Animations: Smooth fade-in, slide-up, and pulse animations
- Responsive Design: Works on 320px to 4K+ screens
- Accessibility: High contrast ratios and readable typography
- Interactive Feedback: Hover effects on buttons and cards
Customize colors in static/css/main.css:
--primary: #0f172a; /* Navy blue */
--secondary: #0891b2; /* Medical teal */
--accent-success: #059669; /* Green */
--accent-warning: #d97706; /* Orange */
--accent-danger: #dc2626; /* Red */- Train ResNet50 on brain tumor dataset
- Implement class imbalance handling
- Add confidence scores to predictions
- Create model evaluation metrics dashboard
- Image preprocessing filters (brightness, contrast adjustment)
- Batch image upload and analysis
- Export results to PDF/CSV
- User authentication and history
- Dark mode toggle
- Explainable AI (Grad-CAM visualization)
- Ensemble models for better accuracy
- DICOM file support
- Real-time prediction API
- Docker containerization
- Unit and integration testing
- Error handling and logging
- Load balancing for multiple users
- Database for predictions history
- API rate limiting
- Deployment to cloud (AWS/GCP/Azure)
| File | Purpose |
|---|---|
app.py |
Main Flask application with routes and model inference |
initialize_model.py |
Creates untrained model weights for development |
brain_tumor_dataset_preparation.ipynb |
Jupyter notebook for dataset preparation and exploration |
requirements.txt |
Python package dependencies |
templates/index.html |
Home page template with upload form |
templates/pred.html |
Results page template showing predictions |
static/css/main.css |
Comprehensive styling with animations and gradients |
static/images/ |
Directory for uploaded and logo images |
Solution: Run python initialize_model.py to create model weights
# Kill process using port 5000
lsof -ti:5000 | xargs kill -9
# Or run on different port
python -c "from app import app; app.run(port=5001)"# Use CPU instead in app.py
device = torch.device('cpu')Solution: Ensure templates/ folder exists and check Flask upload folder permissions
This project is provided as-is for educational and portfolio purposes.
Medical Disclaimer: This tool is not approved for medical diagnosis. Always consult qualified medical professionals for any health-related decisions.
Adithya
Portfolio Project: Brain Tumor Analysis System
- β Deep Learning (PyTorch, Transfer Learning)
- β Full-Stack Web Development (Flask, HTML/CSS/JS)
- β Computer Vision (ResNet50, Image Classification)
- β UI/UX Design (Responsive, Modern CSS)
- β Project Structure & Documentation
- β Version Control & Best Practices