[英]Training multiple models in series in Keras for hyperparameter optimization
[英]keras training 2 models simultaneously
我有 2 個模型:model1 和 model2。
我需要獲取模型 1 的輸出並手動操作 myData 並將其設置(操作的 myData)作為模型 2 的輸入。
model2 的輸出是 myData 響應的分類(對 model1 輸出操作),相對於預定義的分類(即監督)。
我強調:連接不能解決問題。
請參考附圖
一般草圖如下:
# 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(...)
這樣既model1
和model2
將能夠同時鍛煉,你也可以獨立使用它們(如使用model1.predict()
或model2.predict()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.