{"id":30848303,"url":"https://github.com/imswappy/brain-tumor-detection","last_synced_at":"2026-04-13T19:31:54.253Z","repository":{"id":312404509,"uuid":"1047392324","full_name":"Imswappy/Brain-Tumor-Detection","owner":"Imswappy","description":"🧠 Deep learning project for brain tumor classification using MRI images. Built with transfer learning (VGG16 + fine-tuning), TensorFlow/Keras, and deployed via Streamlit. Dataset \u0026 model loaded dynamically from KaggleHub. Includes training notebook, evaluation, and interactive web app.","archived":false,"fork":false,"pushed_at":"2025-08-30T11:31:58.000Z","size":779,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-30T12:17:27.577Z","etag":null,"topics":["kagglehub","keras","numpy","pandas","scikit-learn","streamlit","tensorflow","vgg16-model"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Imswappy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-30T10:12:28.000Z","updated_at":"2025-08-30T11:32:01.000Z","dependencies_parsed_at":"2025-08-30T12:17:50.518Z","dependency_job_id":"3ffd63f2-9cc7-490d-b6f2-031f1ccd597e","html_url":"https://github.com/Imswappy/Brain-Tumor-Detection","commit_stats":null,"previous_names":["imswappy/brain-tumor-detection"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Imswappy/Brain-Tumor-Detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imswappy%2FBrain-Tumor-Detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imswappy%2FBrain-Tumor-Detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imswappy%2FBrain-Tumor-Detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imswappy%2FBrain-Tumor-Detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Imswappy","download_url":"https://codeload.github.com/Imswappy/Brain-Tumor-Detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imswappy%2FBrain-Tumor-Detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273990198,"owners_count":25203289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kagglehub","keras","numpy","pandas","scikit-learn","streamlit","tensorflow","vgg16-model"],"created_at":"2025-09-07T03:08:17.361Z","updated_at":"2026-04-13T19:31:54.197Z","avatar_url":"https://github.com/Imswappy.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧠 NeuroVision: Brain Tumor MRI Classification with Deep Learning\n\n![Streamlit](https://img.shields.io/badge/Framework-Streamlit-red)\n![Keras](https://img.shields.io/badge/Framework-Keras-blue)\n![TensorFlow](https://img.shields.io/badge/Framework-TensorFlow-orange)\n![Python](https://img.shields.io/badge/Python-3.10+-green)\n\n---\n\n## 📌 Project Overview\n\nThis project focuses on **automated brain tumor detection** using **MRI images**.  \nWe apply **transfer learning with VGG16**, a convolutional neural network (CNN) pre-trained on the ImageNet dataset, and fine-tune it to classify brain MRIs into:\n\n- **Meningioma**\n- **Glioma**\n- **Pituitary Tumor**\n- **No Tumor**\n\nThe trained model is deployed via a **Streamlit app**, where users can upload MRI images and get predictions with confidence scores.\n\n---\n\n## 📂 Project Structure\n\n```\nbrain-tumor-mri/\n│\n├── brain_tumour_detection.ipynb   # Training \u0026 evaluation (KaggleHub dataset)\n├── streamlit_app.py                       # Deployment UI with Streamlit\n├── requirements.txt                       # Dependencies\n└── README.md                              # Documentation\n```\n\n---\n\n## 📊 Dataset\n\nDataset is fetched from KaggleHub:\n\n```python\nimport kagglehub\npath = kagglehub.dataset_download(\"masoudnickparvar/brain-tumor-mri-dataset\")\n```\n\nStructure:\n\n```\nTraining/\n   ├── glioma/\n   ├── meningioma/\n   ├── pituitary/\n   └── notumor/\nTesting/\n   ├── glioma/\n   ├── meningioma/\n   ├── pituitary/\n   └── notumor/\n```\n\n- **Training samples:** ~2870  \n- **Testing samples:** ~394  \n- Each subdirectory corresponds to a tumor class.\n\n---\n\n## 🏗️ Model Architecture (Transfer Learning with VGG16)\n\nWe use **VGG16**, a pre-trained CNN on ImageNet, as a **feature extractor** and fine-tune its top layers.  \n\n### 🔹 Step 1: Base Model\n```python\nfrom tensorflow.keras.applications import VGG16\n\nbase_model = VGG16(\n    input_shape=(128,128,3),\n    include_top=False,\n    weights='imagenet'\n)\n```\n- **Input size:** 128 × 128 × 3 (resized MRI images).  \n- `include_top=False`: removes VGG16’s fully connected (FC) head.  \n- `weights=\"imagenet\"`: initializes weights from ImageNet (~1.4M images, 1000 classes).  \n\nMathematically, each convolutional layer applies:\n\u003cimg width=\"491\" height=\"139\" alt=\"image\" src=\"https://github.com/user-attachments/assets/4b3d794f-99f0-4c6c-9ba4-eda7f9457edc\" /\u003e\n\nwhere:\n- W^{(k)}: convolutional kernel for feature map k  \n- x: input patch  \n- σ: activation (ReLU in VGG16)  \n\n### 🔹 Step 2: Freezing and Fine-Tuning\n```python\nfor layer in base_model.layers:\n    layer.trainable = False\n\n# Unfreeze top 3 layers\nbase_model.layers[-2].trainable = True\nbase_model.layers[-3].trainable = True\nbase_model.layers[-4].trainable = True\n```\n- Lower layers retain **general features** (edges, textures).  \n- Top 3 layers fine-tuned to capture **domain-specific features** of MRI tumors.  \n\n\n### 🔹 Step 3: Custom Classification Head\n```python\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Flatten, Dropout, Dense\n\nmodel = Sequential([\n    base_model,\n    Flatten(),\n    Dropout(0.3),\n    Dense(128, activation='relu'),\n    Dropout(0.2),\n    Dense(len(unique_labels), activation='softmax')\n])\n```\n\n- **Flatten:** Reshapes VGG16 feature maps (4 × 4 × 512) → (8192,).  \n- **Dense(128, relu):** Fully connected layer learns non-linear combinations of features.  \n \u003cimg width=\"270\" height=\"52\" alt=\"image\" src=\"https://github.com/user-attachments/assets/2cf5d1ab-c611-4e93-8514-b6d4f7310f0d\" /\u003e\n\n- **Dropout(0.3, 0.2):** Randomly zeroes units during training, reducing overfitting.  \n- **Output Layer:** Softmax classifier for 4 classes:  \n\u003cimg width=\"365\" height=\"120\" alt=\"image\" src=\"https://github.com/user-attachments/assets/97e12f86-7221-4f25-a15f-b5f7f0147a2a\" /\u003e\n \n\n---\n\n## 📒 Notebook (`brain_tumour_detection_vs_code.ipynb`)\n\nSections:\n1. **Dataset loading** with KaggleHub  \n2. **EDA**: Class distributions, sample MRI visualization\n   \u003cimg width=\"1484\" height=\"678\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7c03c569-4821-4e08-a5a9-69ce111462e6\" /\u003e\n3. **Preprocessing**: Resize, normalize, split  \n4. **Model**: VGG16 base + custom classifier  \n5. **Training**: Adam optimizer, categorical crossentropy loss  \n\u003cimg width=\"340\" height=\"107\" alt=\"image\" src=\"https://github.com/user-attachments/assets/dcca8f71-eb06-4c47-a664-eabf2bd20f71\" /\u003e\n\u003cimg width=\"820\" height=\"402\" alt=\"image\" src=\"https://github.com/user-attachments/assets/361f3639-a715-4571-828f-d570024132d2\" /\u003e\n\n\n6. **Evaluation**: Accuracy, confusion matrix, classification report\n   \u003cimg width=\"662\" height=\"556\" alt=\"image\" src=\"https://github.com/user-attachments/assets/880a05e0-ead1-45e7-a58c-15fb24a928dd\" /\u003e\n   \u003cimg width=\"854\" height=\"710\" alt=\"image\" src=\"https://github.com/user-attachments/assets/db0363a0-ffbd-4ea4-8cf3-684bc7572cd8\" /\u003e\n\n\n8. **Saving model** in `.h5` format  \n\n---\n\n## 🧮 Training Statistics\n\n- **Optimizer:** Adam (β₁=0.9, β₂=0.999)  \n- **Learning Rate:** 1e-4  \n- **Batch Size:** 32  \n- **Loss:** Categorical Crossentropy  \n- **Regularization:** Dropout (0.3 \u0026 0.2)  \n\n**Performance:**\n- Training Accuracy: ~95%  \n- Test Accuracy: ~92%  \n- Balanced F1 scores across all classes  \n\n---\n\n## 🎨 Streamlit App (`streamlit_app.py`)\n\nInteractive deployment UI:\n- Upload MRI image (`png/jpg/jpeg`)  \n- Preprocessing: resize 128 × 128, normalize [0,1]  \n- Prediction from VGG16-based model  \n- Displays:\n  - Label\n  - Confidence\n  - Uploaded image\n  - Raw probabilities\n\nRun:\n```bash\nstreamlit run streamlit_app.py\n```\n\n---\n\n## ⚙️ Installation (VS Code)\n\n```bash\n# 1. Create environment\npython -m venv .venv\n.venv\\Scripts\\activate   # Windows\nsource .venv/bin/activate  # Mac/Linux\n\n# 2. Install deps\npip install -r requirements.txt\n\n# 3. Run app\nstreamlit run streamlit_app.py\n```\n\n---\n\n## 🚀 Deployment\n\n- Local: http://localhost:8501  \n- LAN: http://\u003cyour-ip\u003e:8501  \n- Global: deploy on **Streamlit Cloud**\n- \u003cimg width=\"464\" height=\"927\" alt=\"image\" src=\"https://github.com/user-attachments/assets/794eaa0d-eb8b-49ae-9ef6-356c2daf7f62\" /\u003e \u003cimg width=\"457\" height=\"929\" alt=\"image\" src=\"https://github.com/user-attachments/assets/16e4bfcb-66cb-4756-9237-a3e325e55509\" /\u003e\n\u003cimg width=\"464\" height=\"935\" alt=\"image\" src=\"https://github.com/user-attachments/assets/87bb2bbc-a614-4fc6-885e-5961376ae2b3\" /\u003e \u003cimg width=\"470\" height=\"930\" alt=\"image\" src=\"https://github.com/user-attachments/assets/31f3d85e-4915-402e-9a65-696660237b81\" /\u003e\n\n\n\n\n\n\n---\n\n## 🙌 Acknowledgements\n\n- **Dataset**: [Brain Tumor MRI Dataset](https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset)  \n- **Pre-trained Model**: [MRI Brain Tumor Model](https://www.kaggle.com/models/noorsaeed/mri_brain_tumor_model)  \n- **Base Architecture**: [VGG16](https://arxiv.org/abs/1409.1556)  \n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimswappy%2Fbrain-tumor-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimswappy%2Fbrain-tumor-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimswappy%2Fbrain-tumor-detection/lists"}