How to train the network only on one output when there are multiple outputs?

前端 未结 2 1453
清歌不尽
清歌不尽 2020-12-24 03:44

I am using a multiple output model in Keras

model1 = Model(input=x, output=[y2, y3])

model1.compile((optimizer=\'sgd\', loss=cutom_loss_function)

2条回答
  •  独厮守ぢ
    2020-12-24 04:15

    I only want to train the network on output y2.

    Based on Keras functional API guide you can achieve that with

    model1 = Model(input=x, output=[y2,y3])   
    model1.compile(optimizer='sgd', loss=custom_loss_function,
                      loss_weights=[1., 0.0])
    

    What is the shape/structure of the y_pred and y_true argument in loss function when multiple outputs are used? Can I access them as above? Is it y_pred[0] or y_pred[:,0]

    In keras multi-output models loss function is applied for each output separately. In pseudo-code:

    loss = sum( [ loss_function( output_true, output_pred ) for ( output_true, output_pred ) in zip( outputs_data, outputs_model ) ] )
    

    The functionality to do loss function on multiple outputs seems unavailable to me. One probably could achieve that by incorporating the loss function as a layer of the network.

提交回复
热议问题