benedictpepper
Clean deployment
dead8f4
|
Raw History Blame Contribute Delete
3.05 kB

Model Weights

Trained model weights are not tracked in this repository due to file size.

Download from the GitHub Releases page and place files here in models/.


Available Formats

File Size Format Notes
fixed_size_model.weights.h5 ~76 MB Weights-only HDF5 βœ… Recommended for most users
progressive_model.weights.h5 ~76 MB Weights-only HDF5 βœ… Recommended for most users
fixed_size_model.keras ~317 MB Full Keras SavedModel For research / retraining only
progressive_model.keras ~317 MB Full Keras SavedModel For research / retraining only

Loading .weights.h5 (Recommended)

Requires rebuilding the architecture first, then loading weights:

import tensorflow as tf

def build_model(img_size=384):
    """Concat Pooling EfficientNetB4 head β€” matches training architecture."""
    tf.keras.mixed_precision.set_global_policy('float32')
    inputs  = tf.keras.Input(shape=(img_size, img_size, 3))
    backbone = tf.keras.applications.EfficientNetB4(
        include_top=False, weights=None, input_tensor=inputs
    )
    x   = backbone.output
    gap = tf.keras.layers.GlobalAveragePooling2D()(x)
    gmp = tf.keras.layers.GlobalMaxPooling2D()(x)
    x   = tf.keras.layers.Concatenate()([gap, gmp])
    x   = tf.keras.layers.Dense(512, activation='swish')(x)
    x   = tf.keras.layers.BatchNormalization()(x)
    x   = tf.keras.layers.Dropout(0.5)(x)
    out = tf.keras.layers.Dense(2, activation='softmax')(x)
    return tf.keras.Model(inputs, out)

model = build_model(img_size=384)
model.load_weights("models/fixed_size_model.weights.h5")

# Inference β€” preprocess: pixel / 255.0 (NOT preprocess_input)
import numpy as np
from PIL import Image
img = np.array(Image.open("xray.jpg").resize((384, 384))) / 255.0
pred = model(img[np.newaxis].astype(np.float32), training=False).numpy()[0]
print(f"Bacterial: {pred[0]:.3f}  Viral: {pred[1]:.3f}")

Loading .keras (Full Model)

import tensorflow as tf
model = tf.keras.models.load_model("models/fixed_size_model.keras", compile=False)

Requires TensorFlow 2.19+. Mixed precision is embedded in the model config.


Performance

Model Test Accuracy Test AUC FNR Viral
Fixed Size (384Γ—384) 86.92% 0.9198 32.4%
Progressive Resizing (224β†’256β†’384) 78.46% 0.8011 47.3%

Evaluated on 390-image Kermany test set (242 bacterial, 148 viral) with 2-pass TTA.


Architecture

  • Backbone: EfficientNetB4 (ImageNet pretrained, include_top=False)
  • Head: Concat Pooling β€” GlobalAveragePooling2D + GlobalMaxPooling2D β†’ Concatenate(3,584-dim) β†’ Dense(512, Swish) β†’ BatchNorm β†’ Dropout(0.5) β†’ Dense(2, Softmax)
  • Preprocessing: pixel Γ· 255.0 β€” not preprocess_input
  • Loss: CategoricalFocalCrossentropy (Ξ³=2.0, Ξ±=0.25, label_smoothing=0.1)