Update README.md
Browse files
README.md
CHANGED
|
@@ -10,7 +10,8 @@ metrics:
|
|
| 10 |
**Date:** 2025-09-17
|
| 11 |
|
| 12 |
## Overview
|
| 13 |
-
A Capsule Network (CapsNet) implemented in TensorFlow/Keras to classify **four lung-disease categories** from masked chest X-ray images.
|
|
|
|
| 14 |
|
| 15 |
> ⚠️ **Not a medical device.** Outputs are for research/education. Clinician review is required before any clinical use.
|
| 16 |
|
|
@@ -20,7 +21,12 @@ A Capsule Network (CapsNet) implemented in TensorFlow/Keras to classify **four l
|
|
| 20 |
- **Out-of-scope:** Direct clinical decision-making; deployment on patient data without formal validation and regulatory clearance.
|
| 21 |
|
| 22 |
## Model Details
|
| 23 |
-
- **Architecture:** CapsNet with `PrimaryCaps` and `DigitCaps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
- **Loss:** `margin_loss` (capsule margin).
|
| 25 |
- **Optimizer:** `Adam` with a learning-rate scheduler (`lr_scheduler`).
|
| 26 |
- **Metrics:** accuracy.
|
|
@@ -45,15 +51,17 @@ and
|
|
| 45 |
https://www.kaggle.com/datasets/omkarmanohardalvi/lungs-disease-dataset-4-types (License: Unknown)
|
| 46 |
|
| 47 |
## Evaluation
|
| 48 |
-
- **Protocol:** train on the balanced training set, validate with a held-out split; select first-layer kernel size from [5,7,9,10,11] based on validation performance; evaluate best checkpoint on the
|
| 49 |
- **Reported metrics:** Metrics for each model being trained are in `capsnet_training_metrics_all_runs.csv`
|
| 50 |
|
| 51 |
-
## External test
|
| 52 |
-
>I excluded the lung opacity class from external tests because it often co-occurs with other diseases. This
|
| 53 |
However, the reported accuracy for the remaining classes is still quite representative.
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
-
Results CSV: `test_on_external_dataset_capsnet_lung_disease_classifier_krnl9.csv`
|
| 57 |
|
| 58 |

|
| 59 |
|
|
@@ -77,7 +85,7 @@ from tensorflow.keras.utils import load_img, img_to_array
|
|
| 77 |
import numpy as np
|
| 78 |
|
| 79 |
# Load trained Keras model
|
| 80 |
-
model = tf.keras.models.load_model("path/to/model.keras",
|
| 81 |
custom_objects={"margin_loss": margin_loss,
|
| 82 |
"PrimaryCaps": PrimaryCaps,
|
| 83 |
"DigitCaps": DigitCaps,
|
|
|
|
| 10 |
**Date:** 2025-09-17
|
| 11 |
|
| 12 |
## Overview
|
| 13 |
+
A Capsule Network (CapsNet) implemented in TensorFlow/Keras to classify **four lung-disease categories** from masked chest X-ray images.
|
| 14 |
+
The model uses routing-by-agreement and **margin loss**, and was trained with MLflow tracking. Input images are resized to **256×256×3**.
|
| 15 |
|
| 16 |
> ⚠️ **Not a medical device.** Outputs are for research/education. Clinician review is required before any clinical use.
|
| 17 |
|
|
|
|
| 21 |
- **Out-of-scope:** Direct clinical decision-making; deployment on patient data without formal validation and regulatory clearance.
|
| 22 |
|
| 23 |
## Model Details
|
| 24 |
+
- **Architecture:** CapsNet with `PrimaryCaps` and `DigitCaps`
|
| 25 |
+
- built-in augmentation(disabled by default during inference) and rescaling layers:
|
| 26 |
+
- ´layers.RandomRotation(0.1)`, 'layers.RandomTranslation(height_factor=0.1, width_factor=0.1)', 'layers.RandomZoom(0.1)'
|
| 27 |
+
- 'Rescaling(1./255)'
|
| 28 |
+
- routing iterations: 3;
|
| 29 |
+
- first Conv2D kernel size: tuned over [5, 7, 9, 10, 11] after an exploratory sweep (3-epoch runs over [3,5,7,9,10,11]).
|
| 30 |
- **Loss:** `margin_loss` (capsule margin).
|
| 31 |
- **Optimizer:** `Adam` with a learning-rate scheduler (`lr_scheduler`).
|
| 32 |
- **Metrics:** accuracy.
|
|
|
|
| 51 |
https://www.kaggle.com/datasets/omkarmanohardalvi/lungs-disease-dataset-4-types (License: Unknown)
|
| 52 |
|
| 53 |
## Evaluation
|
| 54 |
+
- **Protocol:** train on the balanced training set, validate with a held-out split; select first-layer kernel size from [5,7,9,10,11] based on validation performance; evaluate best checkpoint on the external test set.
|
| 55 |
- **Reported metrics:** Metrics for each model being trained are in `capsnet_training_metrics_all_runs.csv`
|
| 56 |
|
| 57 |
+
## External test and the winner model
|
| 58 |
+
>I excluded the lung opacity class from external tests because it often co-occurs with other diseases. This class makes it challenging to classify accurately.
|
| 59 |
However, the reported accuracy for the remaining classes is still quite representative.
|
| 60 |
+
- krnl9 (best COVID F1, balanced performance) (the one here presented)-> Results CSV: `test_on_external_dataset_capsnet_lung_disease_classifier_krnl9.csv`
|
| 61 |
+
- krnl11 (highest accuracy, strongest Viral Pneumonia detection)
|
| 62 |
+
- optionally krnl10 (solid performance, close to the leaders)
|
| 63 |
|
| 64 |
|
|
|
|
| 65 |
|
| 66 |

|
| 67 |
|
|
|
|
| 85 |
import numpy as np
|
| 86 |
|
| 87 |
# Load trained Keras model
|
| 88 |
+
model = tf.keras.models.load_model("your/path/to/model.keras",
|
| 89 |
custom_objects={"margin_loss": margin_loss,
|
| 90 |
"PrimaryCaps": PrimaryCaps,
|
| 91 |
"DigitCaps": DigitCaps,
|