Views
No views yet
capsnet_4class_lung_disease_classifier⚠️ Not a medical device. Outputs are for research/education. Clinician review is required before any clinical use.
PrimaryCaps and DigitCaps; routing iterations: 3; 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]).margin_loss (capsule margin).Adam with a learning-rate scheduler (lr_scheduler).(1, 256, 256, 1); #classes: 4; batch size: 32.EarlyStopping (mode='min'), ReduceLROnPlateau, custom StopAtValAccuracy(target=0.95), and ModelCheckpoint(save_best_only=True).train_dataset and val_dataset). Long-run training used validation_split = 0.2; kernel exploration used validation_split = 0.5.disease_labels = ['COVID', 'Lung_Opacity', 'Normal', 'Viral Pneumonia']).Licenses & provenance:
capsnet_training_metrics_all_runs.csvI excluded the lung opacity class from external tests because it often co-occurs with other diseases. This makes it challenging to classify accurately. However, the reported accuracy for the remaining classes is still quite representative.
test_on_external_dataset_capsnet_lung_disease_classifier_krnl9.csv
mlruns_capsnet) and save confusion matrices.1import tensorflow as tf
2from tensorflow.keras.utils import load_img, img_to_array
3
4# here the model architecture inc. custom objects to
5from modelbuilder import capsnet_custom_objects # "margin_loss": margin_loss,
6 # "PrimaryCaps": PrimaryCaps,
7 # "DigitCaps": DigitCaps,
8 # "Length": Length
9
10# Load trained Keras model
11model = tf.keras.models.load_model("path/to/model.keras",
12 custom_objects=custom_objects)
13
14x = preprocess("example_cxr.png")
15# x.shape -> (1, 256, 256, 1)
16pred = model.predict(x)[0] # shape: (4,)
17pred_label = np.argmax(pred)
18print(pred, pred_label)