Update app.py
Browse files
app.py
CHANGED
@@ -26,8 +26,8 @@ model_file = "./seg_unet_model.h5"
|
|
26 |
#Custom objects for model
|
27 |
|
28 |
def Combo_loss(y_true, y_pred, eps=1e-9, smooth=1):
|
29 |
-
targets =
|
30 |
-
inputs =
|
31 |
intersection = K.sum(targets * inputs)
|
32 |
dice = (2. * intersection + smooth) / (K.sum(targets) + K.sum(inputs) + smooth)
|
33 |
inputs = K.clip(inputs, eps, 1.0 - eps)
|
@@ -37,15 +37,15 @@ def Combo_loss(y_true, y_pred, eps=1e-9, smooth=1):
|
|
37 |
return combo
|
38 |
|
39 |
def dice_coef(y_true, y_pred, smooth=1):
|
40 |
-
y_pred =
|
41 |
-
y_true =
|
42 |
intersection = K.sum(y_true * y_pred, axis=[1,2,3])
|
43 |
union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3])
|
44 |
return K.mean((2 * intersection + smooth) / (union + smooth), axis=0)
|
45 |
|
46 |
def focal_loss_fixed(y_true, y_pred, gamma=2.0, alpha=0.25):
|
47 |
-
pt_1 =
|
48 |
-
pt_0 =
|
49 |
focal_loss_fixed = -K.mean(alpha * K.pow(1. - pt_1, gamma) * K.log(pt_1+K.epsilon())) - K.mean((1 - alpha) * K.pow(pt_0, gamma) * K.log(1. - pt_0 + K.epsilon()))
|
50 |
return focal_loss_fixed
|
51 |
|
|
|
26 |
#Custom objects for model
|
27 |
|
28 |
def Combo_loss(y_true, y_pred, eps=1e-9, smooth=1):
|
29 |
+
targets = keras.ops.cast(K.flatten(y_true), dtype="float32")
|
30 |
+
inputs = keras.ops.cast(K.flatten(y_pred), dtype="float32")
|
31 |
intersection = K.sum(targets * inputs)
|
32 |
dice = (2. * intersection + smooth) / (K.sum(targets) + K.sum(inputs) + smooth)
|
33 |
inputs = K.clip(inputs, eps, 1.0 - eps)
|
|
|
37 |
return combo
|
38 |
|
39 |
def dice_coef(y_true, y_pred, smooth=1):
|
40 |
+
y_pred = keras.ops.cast(y_pred, dtype="int32")
|
41 |
+
y_true = keras.ops.cast(y_true, tdtype="int32")
|
42 |
intersection = K.sum(y_true * y_pred, axis=[1,2,3])
|
43 |
union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3])
|
44 |
return K.mean((2 * intersection + smooth) / (union + smooth), axis=0)
|
45 |
|
46 |
def focal_loss_fixed(y_true, y_pred, gamma=2.0, alpha=0.25):
|
47 |
+
pt_1 = keras.ops.where(keras.ops.equal(y_true, 1), y_pred, keras.ops.ones_like(y_pred))
|
48 |
+
pt_0 = keras.ops.where(keras.ops.equal(y_true, 0), y_pred, keras.ops.ones_like(y_pred))
|
49 |
focal_loss_fixed = -K.mean(alpha * K.pow(1. - pt_1, gamma) * K.log(pt_1+K.epsilon())) - K.mean((1 - alpha) * K.pow(pt_0, gamma) * K.log(1. - pt_0 + K.epsilon()))
|
50 |
return focal_loss_fixed
|
51 |
|