Keras training only specific outputs

后端 未结 2 497
盖世英雄少女心
盖世英雄少女心 2020-12-09 06:40

I am using Kears with tensorflow and I have a model with 3 output out of which I only want to train 2.

model = Model(input=input, output=[out1,out2,out3])
mo         


        
2条回答
  •  醉梦人生
    2020-12-09 07:06

    You have to create 2 different models like this

    model1 = Model(input=input, output=[out1,out2])
    model2 = Model(input=input, output=[out1,out2,out3])
    

    You compile both but only fit the first. They will share the layers so model2, even if it wasn't trained, will have the weights learned from model1. But if there is a layer in out3 which is trainable but not in the flow between input and out1 and out2 of the graph, that layer wont be trained so will stay wirh its inital values.

    Does that help? :-)

提交回复
热议问题