首页 > 解决方案 > 将预测概率转换为二进制输出和 ResourceExhaustedError

问题描述

我定义了以下损失函数:

def dice_coef(y_true, y_pred):
    y_pred = K.gather(y_pred, tf.where(y_pred>0.5))
    y_true_f = K.flatten(y_true)
    y_pred_f = K.flatten(y_pred)
    intersect = K.sum(y_pred_f * y_true_f)
    denominator = K.sum(y_pred_f) + K.sum(y_true_f)
    dice_score = K.constant(2.) * intersect / (denominator + K.constant(.01))
    return dice_score

由于我只希望 y_pred 为 0 和 1,因此我遵循了 stackoverflow 上的一个线程,该线程建议使用y_pred = K.gather(y_pred, tf.where(y_pred>0.5)). 但是,我收到错误消息:

ResourceExhaustedError:分配具有形状的张量时出现 OOM [662885,4,144,144,1]

解决这个问题有什么办法吗?

标签: pythontensorflowkerasloss-function

解决方案


推荐阅读