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
| license: mit | |
| language: | |
| - en | |
| metrics: | |
| - f1 | |
| pipeline_tag: image-classification | |
| library_name: keras | |
| tags: | |
| - biology | |
| - medical | |
| # 𦴠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: | |
| 1. Normal | |
| 2. Doubtful | |
| 3. Mild | |
| 4. Moderate | |
| 5. 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)](https://www.kaggle.com/datasets/orvile/digital-knee-x-ray-images/data) | |
| ## π Training Summary | |
| - Epochs: 100 with early stopping (83) | |
| - Optimizer: Adam | |
| - Loss: Sparse Categorical Crossentropy | |
| - Metric: F1 Score | |
| ## π Usage | |
| ```python | |
| 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]("https://storage.googleapis.com/kagglesdsdata/datasets/5697473/9389485/OS%20Collected%20Data/Osteopenia/Osteopenia%2010.jpg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=gcp-kaggle-com%40kaggle-161607.iam.gserviceaccount.com%2F20250513%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250513T112322Z&X-Goog-Expires=259200&X-Goog-SignedHeaders=host&X-Goog-Signature=9e41a414c2260b2090ef9c53e4d37a543e6075779074aa5a38e756c299147309380ee57f591f224fb8d992c63ce7f797655f647fc57ff4dca602997ff7efd1bf944e2737782cb2812a2da1f8d8c5f93ed33066df3b7983701e0fdd87c5d96395c45b4ea5be14fe7fab58495c99772e814e42f83a6db24d8b8760eeac2cd58c4581fc57cccbb2fb46a2040c521ef8b332105e6b43de0f0a6c23d5324102349bc13ecefb93d1d1cd8881fadb3d29f49d8662c8f70190c8e5903672c56d9c1ad4cead65f267dbec4774d682772d2afe9d1a8f003899ac931c4698649365be9c9170d8e5336c13e29584508c1c4b1b2dc928ac64ac763b4c1579e8eee9c265a2c644") | |
| Class probabilities: | |
| - 0Normal -> 0.0 | |
| - 1Doubtful -> 0.0 | |
| - 2Mild -> 100.0 | |
| - 3Moderate -> 0.0 | |
| - 4Severe -> 0.0 |