LucidMed AI: A transparent, clinical-grade platform for classifying brain tumors (Glioma, Meningioma, Pituitary) that combines Deep Learning Accuracy, Grad-CAM++ Visual Explanations, and Generative AI Clinical Reporting.
🔗 Live Demo: https://8q7jszzenm55fqes96kfw4.streamlit.app/
Unlike standard heatmaps that obscure the image, our Grad-CAM++ implementation uses dynamic thresholding to highlight only the lesion while keeping the anatomy visible.
- Method:
cv2.threshold> 30% intensity + Alpha Blending. - Result: Clear visualization of tumor boundaries without "color fog."
We simulate a dual-reader workflow by piping the MRI scan and EfficientNet prediction to Google Gemini 2.0 Flash.
- Visual Verification: The LLM independently analyzes the image features.
- Hallucination Check: If EfficientNet is wrong (e.g., predicting Tumor on a healthy scan), Gemini often flags the discrepancy.
- Automated Reporting: Generates a structured clinical draft (Findings, Impression) instantly.
We moved beyond simple baselines to implement a clinical-grade training pipeline:
- Dataset-Specific Normalization: Calculated custom Mean/Std
[0.185, 0.185, 0.185]specifically for brain MRI scans, replacing generic ImageNet defaults. - Imbalance Correction: Implemented Weighted Cross-Entropy Loss to ensure the model doesn't bias towards majority classes.
- Aggressive Augmentation: Used
ElasticTransformandRandomBrightnessContrastvia Albumentations to simulate scanner variability and anatomical deformations.
| Component | Technology | Role |
|---|---|---|
| Backbone | EfficientNet-B0 | Feature Extraction with Parameter Efficiency |
| Optimization | AdamW + Cosine Annealing | Modern training loop for better convergence |
| XAI Engine | Grad-CAM++ | High-fidelity localization of multiple lesion instances |
| LLM Agent | Gemini 2.0 Flash | Senior Neuroradiologist simulation & reporting |
| Interface | Streamlit | Interactive Clinical Dashboard |
The project includes a clinical dashboard for real-time inference.
Click here to view the live app
# 1. Install dependencies
pip install -r requirements.txt
# 2. Run the App
streamlit run src/app.pyTo use the Gemini features without pasting your key every time, create a secrets file:
- Create
.streamlit/secrets.toml - Add:
GOOGLE_API_KEY = "your_key_here" - Note: This file is git-ignored for safety.
Explainable-Brain-MRI/
├── data/ # Dataset directory
├── src/
│ ├── app.py # Streamlit Dashboard (+ Gemini Integration)
│ ├── gradcam.py # XAI Engine (Grad-CAM++)
│ └── ...
├── med-gemma/ # [Experimental] Local Med-LLM playground
├── results/ # Generated Heatmaps
└── README.md| Glioma | Meningioma | Pituitary | No Tumor |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Note: The new Smart-Masking algorithm ensures the grey matter remains visible. |
-
Accuracy: 99.30% (
$\pm$ 0.14%) — Rigorous 5-Fold Cross-Validation Average - Peak Accuracy: 99.7% (Best Single Fold)
-
Clinical-Grade Verification:
- 5-Fold Cross-Validation: Ensures the model is robust across all data splits, not just a "lucky" training set.
- Test-Time Augmentation (TTA): Validates predictions by analyzing multiple views (flips/rotations) of the patient scan.
- Label Smoothing: Prevents model overconfidence, ensuring better generalization to unseen data.
- Faithfulness (Occlusion Drop): 0.30 avg
- Noise Stability: 0.56 (Cosine Similarity)
- Rotation Stability: 0.98 (Cosine Similarity)
- Single-Slice 2D Analysis: The current EfficientNet-B0 model looks at a single 2D slice. Tumors that are clear in 3D volume but subtle in one axial slice may be missed. This is why we created the Dual-Verification System.
- Contrast Media: Our model is trained on T1-weighted images. Some tumors (e.g., small meningiomas) are isointense to brain tissue and only become visible with Gadolinium contrast, which this dataset does not consistently distinguish.
- Iftikhar et al. (2025): Importance of XAI in medical black-box models.
- Islam et al. (2025): Grad-CAM++ for improved lesion localization.
Author: Shek Lun Leung (Independent Researcher) & Sai Oop Mong, MD (Clinical Lead) License: MIT



