Skip to content

dpavansekhar/Osteoporosis-Detection-using-Machine-Learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Osteoporosis Classification using Deep Learning


Project Overview

This project focuses on classifying bone conditions using deep learning models trained on X-ray images. The models used include VGG16, VGG19, InceptionV3, ResNet50, Xception, AlexNet, MobileNetV2 and a Custom CNN. The goal is to accurately classify images into three categories:

  • Osteopenia
  • Osteoporosis
  • Normal

Dataset

The dataset consists of X-ray images of bones, divided into three classes. The images were preprocessed by resizing, normalizing, and augmenting to enhance the model's performance.

X-ray Images Classification
Normal Normal Normal Normal Normal
Osteopenia Osteopenia Osteopenia Osteopenia Osteopenia
Osteoporosis Osteoporosis Osteoporosis Osteoporosis Osteoporosis

Model Architecture

Model Architecture of Osteoporosis Prediction

Models Used

We have trained and evaluated the following deep learning models:

  1. VGG16
  2. VGG19
  3. InceptionV3
  4. ResNet50
  5. Xception
  6. AlexNet
  7. Custom CNN
  8. Late Fusion
  9. Dense Net 121
  10. VGG 16 + VGG 19
  11. InceptionV3 + XceptionNet
  12. ResNet 50 + DenseNet 121

Each model was trained with the same dataset and evaluated using precision, recall, f1-score, accuracy, and confusion matrices.

Performance Metrics

Below is a summary of the classification performance for each model:

Model Accuracy Precision Recall F1-Score Confusion Matrix Graphs
VGG16 70% 0.74 0.70 0.70 image image
VGG19 75% 0.77 0.75 0.75 image image
InceptionV3 88% 0.89 0.88 0.88 image image
ResNet50 66% 0.74 0.66 0.65 image image
Xception 87% 0.88 0.87 0.87 image image
AlexNet 85% 0.86 0.85 0.85 image image
Late Fusion 86% 0.86 0.86 0.86 image image
DenseNet 121 83% 0.83 0.83 0.83 image image
MobileNetV2 84% 0.82 0.84 0.82 image image
Custom CNN 89% 0.89 0.89 0.89 image image
Ensemble Learning
VGG 16 + VGG 19 80% 0.81 0.80 0.80 image
InceptionV3 + Xception 84% 0.84 0.84 0.84 image
ResNet50 + DenseNet121 82% 0.82 0.82 0.82 image
AlexNet + MobileNetV2 88% 0.89 0.88 0.88 image
InceptionV3 + DenseNet121 85% 0.86 0.85 0.85 image
Xception + DenseNet121 85% 0.85 0.85 0.85 image
MobileNetV2 + Xception 84% 0.85 0.84 0.84 image
InceptionV3 + MobileNetV2 84% 0.85 0.84 0.84 image
Custom CNN + DenseNet121 85% 0.85 0.85 0.85 image

Classification Reports

VGG16

              precision    recall  f1-score   support

  Osteopenia       0.82      0.55      0.66        75
Osteoporosis       0.60      0.86      0.71       159
      Normal       0.83      0.60      0.70       156

    accuracy                           0.70       390
   macro avg       0.75      0.67      0.69       390
weighted avg       0.74      0.70      0.70       390

VGG19

              precision    recall  f1-score   support

  Osteopenia       0.81      0.73      0.77        75
Osteoporosis       0.68      0.88      0.77       159
      Normal       0.85      0.63      0.73       156

    accuracy                           0.75       390
   macro avg       0.78      0.75      0.75       390
weighted avg       0.77      0.75      0.75       390

InceptionV3

              precision    recall  f1-score   support

  Osteopenia       0.85      0.88      0.86        75
Osteoporosis       0.88      0.91      0.89       159
      Normal       0.91      0.87      0.89       156

    accuracy                           0.88       390
   macro avg       0.88      0.88      0.88       390
weighted avg       0.89      0.88      0.88       390

ResNet50

              precision    recall  f1-score   support

  Osteopenia       0.87      0.35      0.50        75
Osteoporosis       0.57      0.92      0.70       159
      Normal       0.86      0.55      0.67       156

    accuracy                           0.66       390
   macro avg       0.76      0.61      0.62       390
weighted avg       0.74      0.66      0.65       390

Xception

              precision    recall  f1-score   support

  Osteopenia       0.81      0.89      0.85        75
Osteoporosis       0.89      0.83      0.86       159
      Normal       0.89      0.91      0.90       156

    accuracy                           0.87       390
   macro avg       0.86      0.88      0.87       390
weighted avg       0.88      0.87      0.87       390

AlexNet

              precision    recall  f1-score   support

  Osteopenia       0.86      0.85      0.86        75
Osteoporosis       0.82      0.88      0.85       159
      Normal       0.89      0.83      0.86       156

    accuracy                           0.85       390
   macro avg       0.86      0.85      0.85       390
weighted avg       0.86      0.85      0.85       390

Late Fusion

              precision    recall  f1-score   support

  Osteopenia       0.75      0.84      0.79        75
Osteoporosis       0.85      0.85      0.85       159
      Normal       0.93      0.88      0.90       156

    accuracy                           0.86       390
   macro avg       0.84      0.86      0.85       390
weighted avg       0.86      0.86      0.86       390

DenseNet 121

              precision    recall  f1-score   support

  Osteopenia       0.82      0.87      0.84        75
Osteoporosis       0.79      0.87      0.83       159
      Normal       0.88      0.77      0.82       156

    accuracy                           0.83       390
   macro avg       0.83      0.83      0.83       390
weighted avg       0.83      0.83      0.83       390

Custom CNN

              precision    recall  f1-score   support

  Osteopenia       0.82      0.75      0.78        75
Osteoporosis       0.87      0.92      0.90       159
      Normal       0.94      0.92      0.93       156

    accuracy                           0.89       390
   macro avg       0.88      0.86      0.87       390
weighted avg       0.89      0.89      0.89       390

MobileNet V2

              precision    recall  f1-score   support

  Osteopenia       0.73      0.72      0.72        75
Osteoporosis       0.75      0.83      0.79       159
      Normal       0.86      0.78      0.82       156

    accuracy                           0.79       390
   macro avg       0.78      0.78      0.78       390
weighted avg       0.79      0.79      0.79       390

Ensemble Learning

VGG 16 + VGG 19

              precision    recall  f1-score   support

  Osteopenia       0.78      0.83      0.80        75
Osteoporosis       0.75      0.86      0.80       159
      Normal       0.89      0.73      0.80       156

    accuracy                           0.80       390
   macro avg       0.81      0.81      0.80       390
weighted avg       0.81      0.80      0.80       390

InceptionV3 + Xception

              precision    recall  f1-score   support

  Osteopenia       0.78      0.77      0.78        75
Osteoporosis       0.83      0.87      0.85       159
      Normal       0.89      0.85      0.87       156

    accuracy                           0.84       390
   macro avg       0.83      0.83      0.83       390
weighted avg       0.84      0.84      0.84       390

ResNet50 + DenseNet121

              precision    recall  f1-score   support

  Osteopenia       0.83      0.57      0.68        75
Osteoporosis       0.79      0.92      0.85       159
      Normal       0.85      0.84      0.85       156

    accuracy                           0.82       390
   macro avg       0.82      0.78      0.79       390
weighted avg       0.82      0.82      0.82       390

AlexNet + MobileNetV2

              precision    recall  f1-score   support

  Osteopenia       0.86      0.81      0.84        75
Osteoporosis       0.85      0.94      0.89       159
      Normal       0.94      0.85      0.89       156

    accuracy                           0.88       390
   macro avg       0.88      0.87      0.87       390
weighted avg       0.89      0.88      0.88       390

InceptionV3 + DenseNet121

              precision    recall  f1-score   support

  Osteopenia       0.75      0.85      0.80        75
Osteoporosis       0.84      0.86      0.85       159
      Normal       0.93      0.84      0.88       156

    accuracy                           0.85       390
   macro avg       0.84      0.85      0.84       390
weighted avg       0.86      0.85      0.85       390

Xception + DenseNet121

              precision    recall  f1-score   support

  Osteopenia       0.80      0.88      0.84        75
Osteoporosis       0.81      0.88      0.84       159
      Normal       0.93      0.79      0.86       156

    accuracy                           0.85       390
   macro avg       0.84      0.85      0.84       390
weighted avg       0.85      0.85      0.85       390

MobileNetV2 + Xception

              precision    recall  f1-score   support

  Osteopenia       0.76      0.85      0.81        75
Osteoporosis       0.79      0.88      0.83       159
      Normal       0.95      0.78      0.86       156

    accuracy                           0.84       390
   macro avg       0.83      0.84      0.83       390
weighted avg       0.85      0.84      0.84       390

InceptionV3 + MobileNetV2

              precision    recall  f1-score   support

  Osteopenia       0.72      0.80      0.76        75
Osteoporosis       0.82      0.86      0.84       159
      Normal       0.94      0.85      0.89       156

    accuracy                           0.84       390
   macro avg       0.83      0.83      0.83       390
weighted avg       0.85      0.84      0.84       390

Custom CNN + DenseNet121

              precision    recall  f1-score   support

  Osteopenia       0.83      0.76      0.79        75
Osteoporosis       0.82      0.91      0.86       159
      Normal       0.90      0.83      0.87       156

    accuracy                           0.85       390
   macro avg       0.85      0.84      0.84       390
weighted avg       0.85      0.85      0.85       390

Confusion Matrices & Graphs

Each model has an associated confusion matrix and performance graphs showcasing:

  • Training & Validation Accuracy
  • Training & Validation Loss
  • Comparative Model Performance


πŸ” Grad-CAM Heatmap Explanation

Grad-CAM (Gradient-weighted Class Activation Mapping) is a powerful visualization technique used to understand which regions of an input image a Convolutional Neural Network (CNN) focuses on when making predictions.

πŸ“Œ What is Grad-CAM?

Grad-CAM uses the gradients of any target class flowing into the final convolutional layer to generate a heatmap that highlights the important regions in the image for prediction. It helps in making deep learning models more interpretable, especially in tasks like image classification.

🌈 Heatmap Color Interpretation

The heatmap is overlaid on the original image using a colormap (usually Jet), where each color indicates a different level of importance:

Color Importance Level Description
πŸ”΅ Blue Low Regions the model considers less important.
🟒 Green Medium-Low Moderately important areas, not critical.
🟑 Yellow Medium-High Areas contributing more to the prediction.
πŸ”΄ Red High Most influential regions driving the prediction.
πŸ”Έ Purple Very Low Negligible impact; mostly ignored by the model.
🟠 Orange / Pink Medium Contributing regions, not the most critical but relevant.

πŸ”₯ Red and Yellow regions show where the model is "looking" the most while making its decision.

πŸ“ˆ Why Use Grad-CAM?

  • βœ… Helps validate model behavior
  • βœ… Identifies biased or incorrect attention
  • βœ… Useful for debugging and model improvement
  • βœ… Enhances explainability for sensitive applications (e.g., medical imaging)

πŸ–ΌοΈ Example Use Cases

  • Image classification (e.g., "Is this a cough or not?")
  • Object detection
  • Medical diagnosis interpretation (e.g., X-ray analysis)
Grad-CAM Heatmaps
image image image
VGG 16 VGG 19 InceptionV3
image image image
XceptionNet ResNet50 DenseNet121
image image
Late Fusion Custom CNN

Conclusion

Among all models, Custom CNN performed the best with 89% accuracy, followed by InceptionV3 at 88%. The VGG and ResNet architectures showed moderate performance. The confusion matrices and graphs provide further insights into model performance.


πŸš€ How to Run The Streamlit Application

This project uses Streamlit to create a web interface for osteoporosis detection.

πŸ“¦ Step 1: Clone the Repository

Open terminal in your system and clone the repository.

git clone https://github.com/dpavansekhar/Osteoporosis-Detection-using-Machine-Learning.git
cd Osteoporosis-Detection-using-Machine-Learning

πŸ§ͺ Step 2: Install Dependencies

pip install -r requirements.txt

▢️ Step 3: Run the App

Open the command prompt in the same folder i.e, where the project is present.

streamlit run interface/app.py

This will launch the app in your default browser at https://localhost:8501.

Authors

Dogga Pavan Sekhar - AI/ML Researcher


This project was developed as part of an ongoing research initiative in medical image classification using deep learning.

About

This project uses deep learning to classify knee X-ray images into Normal, Osteopenia, and Osteoporosis. It supports early diagnosis and improves osteoporosis detection through AI-based medical imaging.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors