定义指标损失会影响模型培训吗?
我想为我的模型添加多个损失值,但是当我将它们添加到损失参数中时,它们不会显示(仅显示为损失,而不是每个损失价值):
dice_loss = sm.losses.DiceLoss()
focal_loss = sm.losses.BinaryFocalLoss()
total_loss = dice_loss + (1 * focal_loss)
optim = tf.keras.optimizers.Adam(LR)
loss = [total_loss, sm.losses.BinaryFocalLoss(), sm.losses.DiceLoss(), sm.losses.JaccardLoss()]
metrics = [sm.metrics.IOUScore(threshold=0.5), sm.metrics.FScore()]
model.compile(optimizer = optim, loss=loss, metrics=metrics)
为了显示每个损失,我添加了损失对于这样的指标方面:
dice_loss = sm.losses.DiceLoss()
focal_loss = sm.losses.BinaryFocalLoss()
total_loss = dice_loss + (1 * focal_loss)
optim = tf.keras.optimizers.Adam(LR)
loss = [total_loss]
metrics = [sm.metrics.IOUScore(threshold=0.5), sm.metrics.FScore(), sm.losses.BinaryFocalLoss(), sm.losses.DiceLoss(), sm.losses.JaccardLoss()]
model.compile(optimizer = optim, loss=loss, metrics=metrics)
我可以将损失函数添加到指标方面吗?还是会影响培训过程?如果它会影响培训过程,那么我是否可以在不影响培训过程的情况下显示每个损失价值?
I want to add multiple loss values to my model, but when I add them to the loss parameter, they don't show up (it just shows as loss, not each loss value):
dice_loss = sm.losses.DiceLoss()
focal_loss = sm.losses.BinaryFocalLoss()
total_loss = dice_loss + (1 * focal_loss)
optim = tf.keras.optimizers.Adam(LR)
loss = [total_loss, sm.losses.BinaryFocalLoss(), sm.losses.DiceLoss(), sm.losses.JaccardLoss()]
metrics = [sm.metrics.IOUScore(threshold=0.5), sm.metrics.FScore()]
model.compile(optimizer = optim, loss=loss, metrics=metrics)
So to show each loss, I add the loss to the metrics side like this:
dice_loss = sm.losses.DiceLoss()
focal_loss = sm.losses.BinaryFocalLoss()
total_loss = dice_loss + (1 * focal_loss)
optim = tf.keras.optimizers.Adam(LR)
loss = [total_loss]
metrics = [sm.metrics.IOUScore(threshold=0.5), sm.metrics.FScore(), sm.losses.BinaryFocalLoss(), sm.losses.DiceLoss(), sm.losses.JaccardLoss()]
model.compile(optimizer = optim, loss=loss, metrics=metrics)
Is it okay for me to add the loss function to the metrics side? or it will be affect the training process? If it will affect the training process, is there anyway for me to show each loss value without affecting the training process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这很好,它不会改变训练过程,指标仅用于监视,而不是用于计算训练模型的梯度。
Yes this is fine, it will not change the training process, metrics are only used for monitoring and not for computing gradients that will train the model.