Explainable Pneumonia Detection Using Two-Phase Fine-Tuned DenseNet121 for BioFusion Hackathon 2026.
The Stitch-generated visual direction has been integrated as a plain HTML/CSS/JS frontend:
index.htmldefines the app shell, sidebar navigation, topbar, and all product screens.assets/styles.csscontains the unified responsive light/dark theme.assets/app.jshandles navigation, upload preview, diagnosis API calls, result rendering, Grad-CAM controls, and frontend configuration.backend/app.pyserves the frontend and exposes the API.backend/inference.pyloads the trained DenseNet121 model, runs inference, and generates Grad-CAM images.config/model_metrics.jsonstores exported notebook performance metrics used by/api/performance.
- Upload & Diagnose
- Diagnosis Result
- Grad-CAM Explainability
- Model Performance
- Training Method
- Dataset
- Robustness & Quality
- Research
- Settings/About
The frontend is connected to:
POST /api/diagnose
GET /api/performance
GET /api/health
Diagnosis requests are sent as multipart/form-data with one field:
image
Supported response fields are:
{
"predictionClass": "Normal or Pneumonia",
"confidence": 0.94,
"threshold": 0.25,
"inferenceTimeMs": 123,
"recommendation": "Clinical review recommended.",
"gradcamOverlayUrl": "/path/to/overlay.png",
"gradcamHeatmapUrl": "/path/to/heatmap.png"
}No backend predictions are faked in the UI. If the trained model file is missing, /api/diagnose returns 503 and the upload screen shows a clear backend error.
Export the trained notebook model and place one of these files in models/:
models/Pneumonia_DenseNet121_Final.pth
models/best_phase2.pth
The backend expects a PyTorch DenseNet121 state dict matching:
torchvision.models.densenet121(weights=IMAGENET1K_V1)
classifier replaced with Linear(1024, 2)
classes: Normal, Pneumonia
cd /home/ifaz/Coding/BioFusion
python -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/uvicorn backend.app:app --host 127.0.0.1 --port 8000Then open:
http://127.0.0.1:8000
If port 8000 is already in use:
.venv/bin/uvicorn backend.app:app --host 127.0.0.1 --port 8010Then open:
http://127.0.0.1:8010
- Start the FastAPI app with Uvicorn.
- Open the app URL in a browser.
- Go to Upload & Diagnose.
- Select a chest X-ray image.
- Click Run Diagnosis.
- Review Diagnosis Result for class, confidence, threshold, inference time, recommendation, and disclaimer.
- Open Grad-CAM to inspect the original image, overlay, or heatmap. Use the opacity slider for overlay review.
- Open Model Performance, Dataset, Training Method, Robustness & Quality, and Research for project documentation.
Diagnosis and Grad-CAM require a real trained .pth file in models/. Without it, the rest of the app still runs and diagnosis requests fail safely with an explicit model-missing message.