[英]keras training 2 models simultaneously
I have 2 models: model1 and model2.我有 2 个模型:model1 和 model2。
I need to take model 1 output and manipulate myData manually and set it (manipulated myData) as input of model2.我需要获取模型 1 的输出并手动操作 myData 并将其设置(操作的 myData)作为模型 2 的输入。
model2's output is classification of the responses of myData (to model1 output manipulation), relative to predefined classification (ie supervised). model2 的输出是 myData 响应的分类(对 model1 输出操作),相对于预定义的分类(即监督)。
I emphasize: Concatenate does NOT solve the problem.我强调:连接不能解决问题。
Please refer to the attached diagram请参考附图
The general sketch would be as follows:一般草图如下:
# define model 1 architecture
...
# define model 2 architecture
...
# define manipulation logic
out1 = model1.output # get the output of model1
out1 = SomeLayer()(out1) # apply any number of layers as you wish
...
out_final = model2(out1) # feed the manipulated output to model2
# define the joint model
final_model = Model(model1.input, out_final)
# compile the model ...
final_model.compile(loss=..., optimizer=...) # loss is computed based on the output of model2
# fit the model
final_model.fit(...)
This way both model1
and model2
will be trained simultaneously and also you can use them independently (eg use model1.predict()
or model2.predict()
).这样既model1
和model2
将能够同时锻炼,你也可以独立使用它们(如使用model1.predict()
或model2.predict()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.