【发布时间】:2020-07-16 08:30:15
【问题描述】:
我有以下成本函数= argmin L1+L2 ,其中 L1 是均方误差,L2 是 -λ Summation( Square((y) x (z) )) 其中 y 是预测的输出图像,z 是要建模的给定输入图像。 y 和 z 的元素乘法,然后取平方。 λ 是 L1 和 L2 之间的权衡参数。我不知道如何实现,我是这样做的
def custom_loss(i):
def loss(y_true, y_pred):
y_true=K.cast(y_true, dtype='float32')
y_pred=K.cast(y_pred, dtype='float32')
input_image=K.cast(i, dtype='float32')
mul=tf.math.multiply(input_image,y_pred)
L1=K.mean(K.square(mul),axis=1)
L2=K.mean(K.square(y_pred - y_true), axis=-1)
closs=L1-L2
return closs
return loss
【问题讨论】:
-
有什么问题?
-
我想知道我的实现是否正确。
-
嗨@Shaleel,您能否尝试将输出场景的一个示例提供给您的损失函数并检查它是否是您想要的输出?如果没有,您能否包含用于测试的最低可重现代码?
标签: python python-3.x tensorflow keras deep-learning