确定自定义损失度量keras中预测的相关组件

2024-06-16 09:41:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个修正的二元交叉熵损失函数Keras,在预测输出中惩罚大量孤岛的模型。输出为128x128x128。我有一个函数,它使用measure.label()计算输入numpy数组中的孤岛数量,它工作得非常好。问题是,当我从loss函数内部调用这个函数时,loss函数接收到的输入总是一个None值,我不知道是什么导致了这种情况

我的损失是:

eps = 2
def custom_binary_crossentropy(y_true,y_pred):
        bc = K.binary_crossentropy(y_true, y_pred)

        ytyp_x = K.shape(y_true)[0]

        yt = K.reshape(y_true, (ytyp_x,128,128))
        yp = K.reshape(y_pred, (ytyp_x,128,128))
// after this operation i KNOW that the yp and yt values are 3d like they should be, 
//but when I pass them into the num_islands function they are interpreted as None values. 
//I know this because I filter out the None values in the num_islands function
//and return something different if the input is None

        islands = num_islands(yp,0)
        islands = tf.dtypes.cast(islands,dtype=tf.float32)


        loss = bc*(K.log(islands + eps))
        return(loss)

这些评论在某种程度上概括了问题的状况

非常感谢您的帮助。谢谢


Tags: the函数nonetrueepsnumvaluesbinary