Views
No views yet
[0,1][-1000, 1500]128 × 128 pixelslearning rate = 1e-4)| Metric | Non-Augmented Model | Augmented Model |
|---|---|---|
| Dice Coefficient | 0.8502 | 0.8658 |
| IoU (Mean) | 0.7445 | 0.8316 |
| ASSD (Symmetric Distance) | 0.3907 | 0.3888 |
| Hausdorff Distance | 8.4853 | 9.8995 |
| ROC AUC Score | 0.91 | 1.00 |
1import os
2from huggingface_hub import hf_hub_download
3from tensorflow.keras.models import load_model
4from keras.saving import register_keras_serializable
5import tensorflow.keras.backend as K
6
7# Set Keras backend (optional)
8os.environ["KERAS_BACKEND"] = "jax"
9
10# Register and define missing functions
11@register_keras_serializable()
12def dice_coef(y_true, y_pred, smooth=1e-6):
13 y_true_f = K.flatten(y_true)
14 y_pred_f = K.flatten(y_pred)
15 intersection = K.sum(y_true_f * y_pred_f)
16 return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
17
18@register_keras_serializable()
19def gl_sl(*args, **kwargs):
20 pass # Placeholder function (update if needed)
21
22# Download the model from Hugging Face
23model_path = hf_hub_download(repo_id="amal90888/unet-segmentation-model", filename="unet_model.keras")
24
25# Load the model with registered custom objects
26unet = load_model(model_path, custom_objects={"dice_coef": dice_coef, "gl_sl": gl_sl}, compile=False)
27
28# Recompile with fresh optimizer and correct loss function
29from tensorflow.keras.optimizers import Adam
30unet.compile(optimizer=Adam(learning_rate=1e-4), loss="binary_crossentropy", metrics=["accuracy", dice_coef])
31
32print(" Model loaded and recompiled successfully!")