简体   繁体   中英

How to add Dropout in Keras functional model?

Let's say I have an LSTM layer in Keras like this:

x = Input(shape=(input_shape), dtype='int32')

x = LSTM(128,return_sequences=True)(x)

Now I am trying to add Dropout to this layer using:

X = Dropout(0.5)

but this gives error, which I am assuming the above line is redefining X instead of adding Dropout to it. How to fix this?

Just add x = Dropout(0.5)(x) like this:

x = Input(shape=(input_shape), dtype='int32')
x = LSTM(128,return_sequences=True)(x)
x = Dropout(0.5)(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM