【发布时间】:2021-06-07 02:32:22
【问题描述】:
我在为时间序列样本中的所有时间步应用相同的 dropout 掩码时遇到一个棘手的问题,以便 LSTM 层在一次前向传递中看到相同的输入。我阅读了多篇文章,但没有找到解决方案。以下implementation 支持吗?或者这会在每个时间步随机丢弃不同的特征图?
dim = (420,48,48,1) # grayscale images of size 48x48
inputShape = (dim)
Input_words = Input(shape=inputShape, name='input_vid')
x = TimeDistributed(Conv2D(filters=50, kernel_size=(8,8), padding='same', activation='relu'))(Input_words)
x = TimeDistributed(MaxPooling2D(pool_size=(2,2)))(x)
x = TimeDistributed(SpatialDropout2D(0.2))(x)
x = TimeDistributed(BatchNormalization())(x)
x = TimeDistributed(Flatten())(x)
x = LSTM(200, dropout=0.2, recurrent_dropout=0.2)(x)
out = Dense(5,activation='softmax')(x)
model = Model(inputs=Input_words, outputs=[out])
opt = Adam(lr=1e-3, decay=1e-3 / 200)
model.compile(loss = 'categorical_crossentropy', optimizer=opt,metrics = ['accuracy'])
如果不是,那么在 keras 上会有什么好的解决方案?我可以使用Dropout with noise_shape 来解决我的问题吗?
【问题讨论】:
标签: tensorflow keras conv-neural-network lstm dropout