def weightedLoss(y_true, y_pred):
# compute weights
# a = cv2.blur(y_true, (11,11))
# ind = (a > 0.01) * (a < 0.99)
# ind = ind.astype(np.float32)
# weights = np.ones(a.shape)
a = K.pool2d(y_true, (11,11), strides=(1, 1), padding='same', data_format=None, pool_mode='avg')
ind = K.cast(K.greater(a, 0.01), dtype='float32') * K.cast(K.less(a, 0.99), dtype='float32')
weights = K.cast(K.greater_equal(a, 0), dtype='float32')
w0 = K.sum(weights)
# w0 = weights.sum()
weights = weights + ind * 2
w1 = K.sum(weights)
# w1 = weights.sum()
weights = weights / w1 * w0
return weightedBCELoss2d(y_true, y_pred, weights) + weightedSoftDiceLoss(y_true, y_pred, weights)
评论列表
文章目录