有多个输出的CNN损失? [英] CNN loss with multiple outputs?

查看:45
本文介绍了有多个输出的CNN损失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下型号

  def get_model():时代= 100learning_rate = 0.1衰减率=学习率/历元inp = keras.Input(shape =(64,101,1),name ="inputs")x =layers.Conv2D(128,kernel_size =(3,3),步幅=(3,3),padding =相同")(inp).x =层数.Conv2D(256,kernel_size =(3,3),步幅=(3,3),padding =相同")(x)x =层数Flatten()(x)x =层数(150)(x)x =层数(150)(x)out1 =层数.Dense(40000,name ="sf_vec")(x)out2 =层数.Dense(128,name ="ls_weights")(x)模型= keras.Model(inp,[out1,out2],name ="2_out_model")model.compile(optimizer = tf.keras.optimizers.Adam(learning_rate = decay_rate),#in caso rimettere 0.001损失="mean_squared_error")keras.utils.plot_model(model,to_file ='model.png',show_shapes = True,show_layer_names = True)model.summary()退货模式 

即,我想基于混合"算法训练我的神经网络.第一输出的损失和第二输出的损失的关系.我以这种方式训练我的神经网络:

  model.fit(x_train,[sf_train,ls_filters_train],时期= 10) 

,例如,在训练期间,显示如下:时代10/10->损失:0.0702-sf_vec_loss:0.0666-ls_weights_loss:0.0035

我想知道损失"是否属于这种情况?几乎是sf_vec_loss和ls_weights_loss之间的总和,或者如果keras实际上是以此方式进行推理的.而且,是否正在针对网络上的损失"训练网络?只要?预先谢谢你:)

解决方案

遵循Tensorflow 解决方案

following the Tensorflow Documentation...

from the loss argument:

If the model has multiple outputs, you can use a different loss on each output by passing a dictionary or a list of losses. The loss value that will be minimized by the model will then be the sum of all individual losses

remember also that you can also weight the loss contributions of different model outputs

from the loss_weights argument:

The loss value that will be minimized by the model will then be the weighted sum of all individual losses, weighted by the loss_weights coefficients

这篇关于有多个输出的CNN损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆