How timdgn/mri_brain_tumor_detection works
Project type and purpose
• This is a full-stack machine-learning web application for brain MRI tumor classification.
• It ingests raw MRI images, cleans and preprocesses them, trains a convolutional neural network (EfficientNetV2B0), exposes an inference API via FastAPI, and provides a user interface via Streamlit.
File structure
Top-level directories and files:
• data/
– raw/ (original MRI images, split into Training/Testing, then by tumor category)
– processed/ (duplicates removed, borders cropped, same splits)
• src/
– data_cleaning.py (deduplication, border cropping)
– preprocessing.py (resizing, normalization, augmentation)
– training.py (model setup, callbacks, training loop)
– inference.py (wraps the trained model for prediction)
– fastapi_app.py (REST API endpoints for inference)
– streamlit_app.py (frontend UI)
– constants.py (shared config: paths, model params)
• models/ (saved model artifacts: .h5 weights and .json architecture)
• plots/ (visualizations: history, confusion, Grad-CAM, etc.)
• docs/ (static images for README)
• requirements.txt (dependencies)
README for additional insights
• Confirms use of transfer learning with EfficientNetV2B0.
• Details three user-facing steps in the UI: upload MRI, get prediction, display Grad-CAM.
• Specifies local launch commands: Uvicorn for backend, Streamlit for frontend.
Main components and their relationships
a. Data Layer
– Raw Data Store (data/raw/)
– Processed Data Store (data/processed/)
b. Preprocessing Service (src/data_cleaning.py + src/preprocessing.py)
– Reads raw images → cleans → outputs processed images
c. Training Pipeline (src/training.py)
– Consumes processed images → trains EfficientNetV2B0 → saves model to models/
d. Model Registry (models/)
– Versioned model artifacts (.h5, .json)
e. Inference Service (src/inference.py + src/fastapi_app.py)
– Loads model from registry → exposes /predict endpoint via FastAPI
f. Frontend UI (src/streamlit_app.py)
– Provides upload form → calls FastAPI → displays prediction and Grad-CAM overlay
g. Visualization / Reporting (plots/)
– Historical training metrics, confusion matrices, Grad-CAM outputs for end users or maintainers
Architectural patterns and design principles
• Layered separation: Data → Preprocessing → Training → Inference → Presentation
• Modular codebase: each major function in its own module
• Stateless REST API: inference is idempotent, no session state
• Reproducible model training: use of checkpoint callbacks, versioned artifacts
• Transfer Learning: reuse pretrained EfficientNetV2B0, fine-tuned on the domain dataset