helpers.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:head-segmentation 作者: szywind 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号