Skip to content

RGK1305/boneage-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

title BoneAge AI
emoji 🦴
colorFrom blue
colorTo indigo
sdk docker
app_port 7860
pinned true
license mit
short_description Automated Bone Age Assessment with Grad-CAM Explainability

🦴 BoneAge AI

Automated Bone Age Assessment using Deep Learning Ensemble with Explainable AI

Python FastAPI React PyTorch Docker

A production-ready web application for pediatric bone age assessment from hand radiographs, powered by a ResNet50 + XGBoost + Ridge ensemble with Grad-CAM explainability.


πŸ“‹ Table of Contents


πŸ”¬ Overview

BoneAge AI automates skeletal maturity assessment from pediatric hand X-rays. It combines:

  • ResNet50 deep learning backbone for feature extraction
  • XGBoost + Ridge ensemble for robust regression
  • Grad-CAM heatmaps highlighting anatomically relevant regions
  • Gender-aware predictions using biological sex as an input feature

The system processes a hand radiograph and returns a predicted bone age (in months/years), developmental stage classification, and an explainable heatmap overlay.


πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React Frontendβ”‚  POST   β”‚             FastAPI Backend               β”‚
β”‚   (Vite :5173)  │────────▢│               (:8000)                    β”‚
β”‚                 β”‚         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚         β”‚  β”‚         ModelManager (Singleton)    β”‚  β”‚
β”‚  β”‚ Upload Zoneβ”‚ β”‚         β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚ Sex Input  β”‚ β”‚         β”‚  β”‚  β”‚ ResNet50 β”‚ β”‚XGBoostβ”‚ β”‚ Ridge β”‚  β”‚  β”‚
β”‚  β”‚ Age Input  β”‚ β”‚         β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚         β”‚  β”‚       β”‚           β”‚         β”‚      β”‚  β”‚
β”‚                 │◀────────│  β”‚  Feature Ext.  β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚  JSON   β”‚  β”‚       β”‚      Ensemble Weighted     β”‚  β”‚
β”‚  β”‚ Results    β”‚ β”‚         β”‚  β”‚       β–Ό           Prediction       β”‚  β”‚
β”‚  β”‚ Dashboard  β”‚ β”‚         β”‚  β”‚   Grad-CAM ──▢ Heatmap Overlay     β”‚  β”‚
β”‚  β”‚ + Grad-CAM β”‚ β”‚         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ›  Tech Stack

Layer Technology
Frontend React 19 Β· Vite 7 Β· Vanilla CSS
Backend FastAPI Β· Uvicorn Β· Python-Multipart
ML/DL PyTorch Β· torchvision Β· XGBoost Β· scikit-learn
Explainability Grad-CAM (layer4 hooks) Β· OpenCV
Containerization Docker Β· Docker Compose Β· Nginx

πŸ“ Project Structure

prmlpro/
β”œβ”€β”€ πŸ“„ README.md
β”œβ”€β”€ πŸ“„ .gitignore
β”œβ”€β”€ πŸ“„ docker-compose.yml          # Container orchestration
β”œβ”€β”€ πŸ“„ save_models.py              # One-time model export script
β”œβ”€β”€ πŸ“„ PRML_CODE.ipynb             # Training notebook
β”‚
β”œβ”€β”€ πŸ“‚ backend/
β”‚   β”œβ”€β”€ main.py                    # FastAPI app + endpoints
β”‚   β”œβ”€β”€ model_manager.py           # Singleton model loader
β”‚   β”œβ”€β”€ pipeline_orchestrator.py   # Inference pipeline
β”‚   β”œβ”€β”€ explainability.py          # Grad-CAM generator
β”‚   β”œβ”€β”€ requirements.txt           # Python dependencies
β”‚   └── Dockerfile
β”‚
└── πŸ“‚ frontend/
    β”œβ”€β”€ index.html
    β”œβ”€β”€ Dockerfile
    └── src/
        β”œβ”€β”€ main.jsx
        β”œβ”€β”€ index.css              # Clinical design system
        β”œβ”€β”€ App.jsx                # State management
        └── components/
            β”œβ”€β”€ UploadWorkspace.jsx
            β”œβ”€β”€ ProcessingIndicator.jsx
            └── ResultsDashboard.jsx

πŸš€ Getting Started

Prerequisites

  • Python 3.10+ with pip
  • Node.js 18+ with npm
  • RSNA Bone Age dataset (for model export step)
  • (Optional) Docker & Docker Compose

πŸ“₯ Download Model Weights

Because the pre-trained model weights exceed GitHub's file size limits, they are hosted externally.

Before running the FastAPI backend, please download the following artifacts and place them directly into the folder directory:

Required Files:

  1. best_bone_age_model.pth (ResNet50 Backbone)
  2. xgb_model.joblib (XGBoost Regressor)
  3. ridge_model.joblib (Ridge Regressor)
  4. ensemble_weights.joblib (Optimized Blend Weights)
  5. scaler.joblib (Tabular Feature Scaler)

1. Clone the Repository

git clone https://github.com/RGK1305/boneage-ai.git
cd boneage-ai

2. Export Model Artifacts (One-time)

The PyTorch model (best_bone_age_model.pth) must be downloaded separately due to its size (~100MB). Place it in the project root, then:

# Create/activate Python environment
python -m venv bone_env
bone_env\Scripts\activate        # Windows
# source bone_env/bin/activate   # Linux/Mac

pip install torch torchvision xgboost scikit-learn pandas joblib

# Export XGBoost, Ridge, and scaler
python save_models.py

Note: This requires the RSNA dataset. Update BASE_DIR in save_models.py if your dataset is at a different path.

3. Start Backend

cd backend
pip install -r requirements.txt
python -m uvicorn main:app --reload --port 8000

Verify: open http://localhost:8000/api/v1/health

4. Start Frontend

cd frontend
npm install
npm run dev

Open http://localhost:5173 in your browser.


πŸ“‘ API Reference

Health Check

GET /api/v1/health

Response:

{
  "status": "healthy",
  "models_loaded": true,
  "device": "cuda"
}

Predict Bone Age

POST /api/v1/predict
Content-Type: multipart/form-data
Field Type Required Description
image File βœ… Hand radiograph (JPEG, PNG, BMP, TIFF)
patient_sex String βœ… "M" or "F"
chronological_age_months Float ❌ Patient's actual age for delta

Response:

{
  "status": "success",
  "predicted_bone_age_months": 142.5,
  "developmental_stage": "Adolescent",
  "gradcam_overlay_base64": "data:image/png;base64,...",
  "processing_time_ms": 850,
  "chronological_age_months": 150,
  "delta_months": -7.5
}

🐳 Docker Deployment

# Build and start both services
docker-compose up --build

# Frontend: http://localhost:3000
# Backend:  http://localhost:8000

The Nginx reverse proxy in the frontend container forwards /api/ requests to the backend automatically.


🧠 Model Details

Component Details
Backbone ResNet50 (ImageNet pretrained)
Input 384Γ—384 RGB image + biological sex
Feature Dim 2048 (backbone) + 1 (sex Γ— 5.0) = 2049
Ensemble DL (~3.6%) + XGBoost (~87.3%) + Ridge (~9.1%)
Normalization ImageNet mean/std: [0.485, 0.456, 0.406] / [0.229, 0.224, 0.225]
Output Scale MAX_AGE_SCALE = 240.0 months
Explainability Grad-CAM on backbone.layer4
Dataset RSNA Pediatric Bone Age Challenge

Developmental Stages

Stage Age Range
Child 0–143 months
Adolescent 144–215 months
Adult 216+ months

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit changes (git commit -m 'Add feature')
  4. Push to branch (git push origin feature/improvement)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


Built with ❀️ for pediatric radiology

About

Automated Bone Age Assessment system built with PyTorch (ResNet50), XGBoost, FastAPI, and React. Includes Grad-CAM heatmaps for model explainability.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors