我想做一个修正的二元交叉熵损失函数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)
这些评论在某种程度上概括了问题的状况
非常感谢您的帮助。谢谢
目前没有回答
相关问题 更多 >
编程相关推荐