简体   繁体   English

keras 同时训练 2 个模型

[英]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 输出操作),相对于预定义的分类(即监督)。

  1. I need to improve model1 output and improve model2 classification simultaneously.我需要同时改进模型 1 的输出和改进模型 2 的分类。 However in testing I will work with each model separately.但是在测试中,我将分别使用每个模型。
  2. To my opinion I need to use model 2 cost function as model 1 cost function - how can it be done?在我看来,我需要使用模型 2 成本函数作为模型 1 成本函数 - 怎么做?
  3. Any other idea how can it be done?任何其他想法如何做到?

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() ).这样既model1model2将能够同时锻炼,你也可以独立使用它们(如使用model1.predict()model2.predict()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Keras 中串联训练多个模型以进行超参数优化 - Training multiple models in series in Keras for hyperparameter optimization 在keras与顺序中训练并行模型 - training Parallel models in keras vs sequentially 在 Apache Spark 中并行训练 Keras 模型 - Training Keras models in parallel in Apache Spark 同时在不同的 GPU 上训练多个 keras/tensorflow 模型 - Train multiple keras/tensorflow models on different GPUs simultaneously 在 keras 中同时训练神经网络并让它们在训练时共同分享损失? - Training neural nets simultaneously in keras and have them share losses jointly while training? 预训练 Keras Xception 和 InceptionV3 模型 - Pre-training Keras Xception and InceptionV3 models 使用部分共享权重串联训练两个 Keras 模型 - Training two Keras models in tandem with partially shared weights 一段时间后,Keras 模型训练会占用更多时间 - Keras models training taking up more time after some time 在 CPU 和 GPU 上的两个单独的 juypter 笔记本中训练 Keras 模型 - Training Keras models in two seperate juypter notebooks on CPU and GPU 当两个模型同时训练不同的数据时,如何将一层从一个模型传递到另一个模型? - How to pass a layer from one model to another when two models are training on different data simultaneously?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM