【问题标题】:How do we compile a multiple output keras model我们如何编译多输出 keras 模型
【发布时间】:2018-01-13 17:43:31
【问题描述】:

正如标题所说,我们如何编译具有多个输出的 keras 函数模型?

# Multiple Outputs
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers.recurrent import LSTM
from keras.layers.wrappers import TimeDistributed

# input layer
visible = Input(shape=(4,2))
# feature extraction
extract = LSTM(10, return_sequences=True)(visible)
# classification output
class11 = LSTM(10)(extract)
class12 = Dense(8, activation='relu')(class11)
class13 = Dense(8, activation='relu')(class12)

output1 = Dense(9, activation='softmax')(class13)

# sequence output
output2 = TimeDistributed(Dense(1, activation='tanh'))(extract)
# output

model = Model(inputs=visible, outputs=[output1, output2])

# summarize layers
print(model.summary())

有两个输出分支,具有两种不同类型的输出值。第一个输出是一个带有 softmax 激活函数的密集层,另一个输出是一个带有 tanh 激活函数的时间分布层。

我们应该如何编译这个模型。我试过这种方式

model.compile(optimizer=['rmsprop','adam'],
              loss=['categorical_crossentropy','mse'],
              metrics=['accuracy'])

但它给出了这个错误

ValueError: ('无法解释优化器标识符:', ['rmsprop', 'adam'])

【问题讨论】:

  • 如果您不介意,我将不胜感激。
  • 我已经给了一份,也接受了你的回答
  • 非常感谢 :)

标签: python-2.7 keras keras-layer


【解决方案1】:

问题在于您想设置两个单独的优化器,这在keras 中是不合理的。您需要选择rmspropadam 作为主要优化器。

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    相关资源
    最近更新 更多