This project presents an AI-based system for early detection of osteoporosis using knee X-ray images.
Leveraging a fine-tuned ResNet-18 CNN model and Grad-CAM++ visualizations, the system classifies knee X-rays as Normal or Osteoporotic.
The model is deployed as a Flask web application, where users can:
- Upload knee X-ray images and enter patient details
- Get instant predictions (Normal / Osteoporosis)
- View Grad-CAM++ heatmaps showing severity regions
- Download a detailed patient report (PDF) with uploaded + heatmapped images
- ResNet-18 based CNN trained on augmented Kaggle dataset
- Dataset expanded from ~1,900 → 8,175 X-rays using augmentation (flips, rotations, zoom, contrast)
- Achieved 93% test accuracy with balanced performance across classes
- Grad-CAM++ for explainable AI and severity region localization
- Flask app interface for real-time inference and report generation
.
├── app.py # Flask app (entry point)
├── cnn_model_train.py # Model training script
├── grad_cam_plus_plus.py # Grad-CAM++ visualization
├── run_prediction.py # Inference utilities
├── model.pth # Trained ResNet-18 weights (download separately)
├── templates/ # HTML templates for UI
├── model/ # Model architecture files
├── requirements.txt # Dependencies
├── README.md # Project documentation
└── training_plots.png # Training/validation trends
git clone https://github.com/your-username/osteoporosis-detection.git
cd osteoporosis-detectionpython -m venv venv
source venv/bin/activate # Linux / macOS
venv\Scripts�ctivate # WindowsDependencies are listed in requirements.txt (includes PyTorch with CUDA 12.1, Flask, OpenCV, ReportLab).
pip install -r requirements.txt📌 If you don’t have CUDA 12.1, install CPU-only PyTorch:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpuPlace the trained weights model.pth in the project root.
(Link to be provided — e.g., Google Drive, HuggingFace, or GitHub Releases.)
python app.pyThen open in browser:
👉 http://127.0.0.1:5000/
- Enter patient details (name, age, gender, etc.)
- Upload a knee X-ray
- Click Submit
- The system will:
- Predict Normal / Osteoporosis
- Show a Grad-CAM++ heatmap
- Generate a downloadable PDF report containing:
- Patient details
- Original X-ray
- Grad-CAM++ visualization
- Model result
- Dataset: 8,175 knee X-ray images (augmented from Kaggle)
- Architecture: Fine-tuned ResNet-18
- Performance:
- Accuracy: 93%
- Precision (Osteoporosis): 0.96
- Recall (Normal): 0.96
- Balanced F1-score across classes
✅ The model generalizes well with minimal overfitting and provides interpretable predictions.
- Deep Learning: PyTorch, TorchVision
- Visualization: Grad-CAM++
- Image Processing: OpenCV, Pillow, Matplotlib
- Backend: Flask
- PDF Reports: ReportLab
- Multi-class classification for different osteoporosis stages
- Early-stage detection by combining X-ray + DEXA scans
- Non-knee image rejection module
- Mobile / cloud deployment (AWS, GCP, HuggingFace Spaces)
- Training on larger, more diverse datasets
This project is for academic and research purposes only.
It is not a medical diagnostic tool and should not be used as a substitute for professional medical advice.