This repository was developed as part of an AI in Healthcare Hackathon.
Knee osteoarthritis is a degenerative joint disease caused by the gradual wearing of cartilage that cushions the bones in the knee. This leads to joint pain, stiffness, and loss of mobility. Diagnosis is typically based on X-ray or MRI scans, which reveal the narrowing of joint spacesβan important indicator of OA severity.
The Kellgren-Lawrence (KL) grading system is a standard method used to classify the severity of knee osteoarthritis: The severity of osteoarthritis was classified into 5 levels based on KL score, from the healthy level to the severe level, where the greater the degree of severity, the smaller the spacing of the joint.
- KL score:
- Grade 0: Healthy
- Grade 1: Doubtful
- Grade 2: Minimal
- Grade 3: Moderate
- Grade 4: Severe
The following image shows the different levels from Knee Osteoarthritis Dataset with Severity Grading.
To build an AI model that automatically classifies the severity of knee osteoarthritis from X-ray images using deep learning and provides a user-friendly prediction tool.
.
βββ README.md
βββ app
βΒ Β βββ app.py
βΒ Β βββ img
βββ assets
βββ dataset
βΒ Β βββ test
βΒ Β βββ train
βΒ Β βββ val
βββ environment.yml
βββ src
βββ 01_data_preparation.ipynb
βββ 02_ensemble_models.ipynb
βββ 02_model_inception_resnet_v2.ipynb
βββ 02_model_resnet50.ipynb
βββ 02_model_xception.ipynb
βββ 03_best_model_on_test_xception.ipynb
βββ models
Β Β βββ model_Xception_ft.hdf5How does the Web App to predict knee osteoarthritis grade using Deep Learning and Streamlit works?
https://github.com/shebin-zeo/Classification-of-Knee-Osteoarthritis-Using-Deep-Learning.git cd Knee_OST
conda env create -f environment.yml-
Activate the environment
(base) C: conda activate knee_dl_app
-
Download
model_Xception_ft.hdf5model from here to run the application. Createmodelsfolder and copy the model here.(knee_dl_app) C: mkdir src/models
-
Download the dataset from Knee Osteoarthritis Dataset with Severity Grading to train the model and test the application. Create
datasetfolder and copy the data here.(knee_dl_app) C: mkdir dataset
streamlit run app/app.pyAs soon as you run the script, a local Streamlit server will spin up, and
your app will open in a new tab in your default web browser.
Or you can navigate to `http://localhost:8501`.
The following methodology has been proposed to correctly classify the degree of osteoarthritis based on X-ray images:
- Data preparation
- Model training
- Model evaluation
- Web application development with the best model
The dataset consists of ~8000 X-ray images, split into training, validation, and test sets. Data distribution is imbalanced across the KL grades. Class balancing techniques: Weighted loss functions Data augmentation (e.g., flipping, brightness/zoom/shift changes) Preprocessing for transfer learning
See 01_data_preparation.ipynb notebook.
Three pre-trained networks were chosen: Xception, ResNet-50 e Inception Resnet v2.
The following table presents the summary of the partial results obtained in the implementation of the different pre-trained networks with fine tuning. Our metrics is Balanced Accuracy. Models were trained on Apple M1 Pro chip with 8-core CPU, 14-core GPU and 16-core Neural Engine.
| Model | Balanced Accuracy | Time Execution |
|---|---|---|
| Xception fine tuning | 67% | 68min |
| ResNet50 fine tuning | 65% | 80min |
| Inception_resnet_v2 fine tuning | 64% | 56min |
Highlighting, the highest success rate of each model by class, we have:
- Inception ResNet classified the minimal class better
- Xception classified the doubtful and severe classes better
- ResNet50 classified the healthy and moderate classes better
Three ensemble approaches were performed with the previous results:
- One calculating the average, and two calculating the weighted average of the accuracy and f1 of each class.
| Model | Balanced Accuracy | Time Execution |
|---|---|---|
| Ensemble mean | 68.63% | 16seg |
| Ensemble accuracy | 68.48% | 16seg |
| Ensemble f1 | 68.69% | 16seg |
The three models had similar results, but we selected the ensemble with f1 model.
We evaluated the best model in the test set, a balanced accuracy of 71% was obtained, and in the confusion matrix we can observe the highlight of the moderate and severe classes.
We implemented the Grad-CAM explainability technique to better understand how classes are classified. The Grad-CAM indicates the parts of the image that most impact the classification score.
We can see in the images that for the healthy, doubtful and minimal classes, the most prominent areas are located in the center of the knee, and the moderate and severe classes are most prominent on the right or left edges of the knee.
Grad-CAM results were obtained from the last convolutional layer of the Xception model.
The developed web application offers a complete interactive experience to aid clinicians and researchers in diagnosing Knee Osteoarthritis:
Upload X-ray Image Users can upload knee X-ray images through a simple UI. Predict Osteoarthritis Grade (KL Score) The app predicts one of the 5 KL grades (0β4) based on deep learning models. Display Classification Probabilities Confidence levels for each grade are shown to support decision-making. Visualize Grad-CAM Heatmaps Highlights the key regions of the X-ray influencing the model's decision using Grad-CAM.
π¨οΈ Patient Query Answering with DeepSeek R1 A built-in chatbot powered by DeepSeek R1 helps answer patient and user queries related to: Symptoms and progression of knee OA Interpretation of KL grades Recommended lifestyle modifications or treatments Information about X-ray vs MRI differences
Integrated 3D anatomical modeling allows users to: Explore the knee joint's structure Understand affected areas in each OA grade Rotate, zoom, and pan for a better spatial understanding
If the predicted result is not Grade 0 (Healthy), the app will: Display a list of nearest orthopedic/OA specialty hospitals Use location data to provide directions or contact information Prompt the user to seek medical consultation for further evaluation
- Knee Osteoarthritis Dataset with Severity Grading
- Transfer Learning-Based Smart Features Engineering for Osteoarthritis Diagnosis From Knee X-Ray Images
- Machine Learning-Based Automatic Classification of Knee Osteoarthritis Severity Using Gait Data and Radiographic Images
made with by π¨βπ» Mohamed Shebin T P










