Instructions to use c2p-cmd/knee_oa_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use c2p-cmd/knee_oa_classifier with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://c2p-cmd/knee_oa_classifier") - Notebooks
- Google Colab
- Kaggle
𦴠Knee Osteoarthritis X-ray Classifier
This model classifies grayscale knee X-ray images into 5 severity classes:
- Normal
- Doubtful
- Mild
- Moderate
- Severe
π Model Details
- Model: CNN built with Keras
- Input shape: (162, 300, 1)
- Preprocessing: Grayscale conversion, resizing, internal normalization (
Rescaling(1./255)) - Data Augmentation: Flip, rotation, zoom
- Output: Softmax probability over 5 classes
π§Ύ Dataset Description
This model was trained on the Digital Knee X-ray Images dataset available on Kaggle. The dataset contains labeled grayscale knee X-ray images categorized into:
- Normal
- Doubtful
- Mild
- Moderate
- Severe
These categories represent the Kellgren and Lawrence grading system for osteoarthritis severity. The images are organized into corresponding folders and include both healthy and osteoarthritic knee conditions.
Link to dataset: Digital Knee X-ray Images (Kaggle)
π Training Summary
- Epochs: 100 with early stopping (83)
- Optimizer: Adam
- Loss: Sparse Categorical Crossentropy
- Metric: F1 Score
π Usage
from keras.models import load_model
model = load_model("knee_oa_classifier.keras")
# Preprocess and predict (image should be (162, 300, 1) when using a url to an image
response = requests.get(url)
img = Image.open(BytesIO(response.content))
img = img.convert('L').resize((162, 300))
display(img)
img_array = np.array(img)
img_array = img_array.reshape((1, 162, 300, 1)) # Add batch and channel dimensions
pred_probs = model.predict(img_array)
pred_class_index = np.argmax(pred_probs)
pred_class_label = train_ds.class_names[pred_class_index]
for pred_prob in pred_probs:
for i, class_name in enumerate(train_ds.class_names):
display(f'{class_name} -> {pred_prob[i]*100}')
display('')
πΌ Example Prediction
Image link
Class probabilities:
- 0Normal -> 0.0
- 1Doubtful -> 0.0
- 2Mild -> 100.0
- 3Moderate -> 0.0
- 4Severe -> 0.0
- Downloads last month
- 8
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://c2p-cmd/knee_oa_classifier")