繁体   English   中英

在keras中实现Custom Cost功能,这需要输出整个批次的大小

[英]Implement Custom Cost function in keras which requires output of whole batch-size

关于该数据集的简要信息:-它是一个人的Re-ID问题(无论2张图像是否相同),我必须为其实现编写自己的损失/成本函数(二项式偏差)。 对于128的批量大小,我将具有256张图像,因此3256 * 256 /批处理矩阵,我的疑问是如何使用keras获取批处理大小的输出,以便实现成本函数

我添加了二项式偏差成本函数公式的屏幕截图。 在此处输入图片说明

使用其他batch_size参数定义您的自定义损失:

def my_loss_template(y_true, y_pred, batch_size):
    # compute the loss

要使用它,

batch_size = 20
my_loss = lambda x, y: my_loss_template(x, y, batch_size)
model.compile(optimizer='adam', loss=my_loss)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM