我想制作一个修正的二进制交叉熵损失函数Keras,该函数会对预测输出中的大量孤岛造成不利影响。输出为128x128x128。我有一个函数,可以使用measure.label()计算输入的numpy数组中的孤岛数量,它可以完美地工作。问题是当我从损失函数内部调用此函数时,损失函数收到的输入始终为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)
这些评论总结了问题的状态。
我们非常感谢您的帮助。谢谢!