且构网

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

Keras 只训练特定的输出

更新时间:2023-12-02 14:57:16

你必须像这样创建 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])

你编译了两个,但只适合第一个.它们将共享层,因此即使没有经过训练,模型 2 也会从模型 1 学习权重.但是,如果 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.

这有帮助吗?:-)