-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathloss.py
More file actions
34 lines (20 loc) · 737 Bytes
/
Copy pathloss.py
File metadata and controls
34 lines (20 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import tensorflow as tf
import tensorflow.keras.backend as K
def dice_coef(y_true, y_pred):
# explicit cast
y_true = tf.cast(y_true, tf.float32)
y_true = K.flatten(y_true)
y_pred = K.flatten(y_pred)
intersection = K.sum(y_true * y_pred)
return 2.0 * intersection / (K.sum(y_true) + K.sum(y_pred) + 1.)
def dice_coef_loss(y_true, y_pred):
# explicit cast
y_true = tf.cast(y_true, tf.float32)
return 1.0 - dice_coef(y_true, y_pred)
def bce_dice_loss(y_true, y_pred):
# explicit cast
y_true = tf.cast(y_true, tf.float32)
a = 0.5
b = 1-a
loss = a * K.binary_crossentropy(y_true, y_pred) + b * dice_coef_loss(y_true, y_pred)
return loss