簡體   English   中英

keras 同時訓練 2 個模型

[英]keras training 2 models simultaneously

我有 2 個模型:model1 和 model2。

我需要獲取模型 1 的輸出並手動操作 myData 並將其設置(操作的 myData)作為模型 2 的輸入。

model2 的輸出是 myData 響應的分類(對 model1 輸出操作),相對於預定義的分類(即監督)。

  1. 我需要同時改進模型 1 的輸出和改進模型 2 的分類。 但是在測試中,我將分別使用每個模型。
  2. 在我看來,我需要使用模型 2 成本函數作為模型 1 成本函數 - 怎么做?
  3. 任何其他想法如何做到?

我強調:連接不能解決問題。

請參考附圖

一般草圖如下:

# 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(...)

這樣既model1model2將能夠同時鍛煉,你也可以獨立使用它們(如使用model1.predict()model2.predict()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM