且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Keras仅训练特定的输出

更新时间:2023-12-01 22:02:46

您必须创建2个类似的模型

You have to create 2 different models like this

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

您可以同时编译两者,但只适合第一个.他们将共享各层,因此,即使没有对model2进行训练,也将具有从model1学习的权重.但是,如果out3中有一个可训练的层,但在图形的输入与out1和out2之间的流中却不是,则该层将不会被训练,因此将保留其初始值.

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.

这有帮助吗? :-)