【问题标题】:Applying dropout to input layer in LSTM network (Keras)将 dropout 应用于 LSTM 网络(Keras)中的输入层
【发布时间】:2019-01-04 08:15:52
【问题描述】:

是否可以在 Keras 中对 LSTM 网络的输入层应用 dropout?

如果这是我的模型:

model = Sequential()
model.add(LSTM(10, input_shape=(look_back, input_length), return_sequences=False))
model.add(Dense(1))

目标是达到以下效果:

model = Sequential()
model.add(Dropout(0.5))
model.add(LSTM(10, input_shape=(look_back, input_length), return_sequences=False))
model.add(Dense(1))

【问题讨论】:

  • 你试过了吗?有错误吗?您只需要将 input_shape 设置为 Dropout 层。

标签: machine-learning neural-network keras dropout


【解决方案1】:

您可以使用Keras Functional API,其中您的模型将写为:

inputs = Input(shape=(input_shape), dtype='int32')
x = Dropout(0.5)(inputs)
x = LSTM(10,return_sequences=False)(x)

定义你的输出层,例如:

predictions = Dense(10, activation='softmax')(x)

然后构建模型:

model = Model(inputs=inputs, outputs=predictions)

【讨论】:

    猜你喜欢
    • 2019-07-03
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2021-08-13
    相关资源
    最近更新 更多