【问题标题】:Running time increasing from ~10 seconds per epoch to ~120 seconds per epoch after adding Dropout?添加 Dropout 后,运行时间从每 epoch 约 10 秒增加到每 epoch 约 120 秒?
【发布时间】:2020-08-29 17:13:22
【问题描述】:

我正在训练一个简单的神经网络,如下所示;

model = Sequential()
model.add(layers.GRU(32,
                     input_shape=(None, 13)))
model.add(layers.Dense(1))

model.compile(optimizer=RMSprop(), loss='mae')
history = model.fit_generator(train_gen,
                              steps_per_epoch=500,
                              epochs=40,
                              validation_data=val_gen)

一切正常并按预期运行。然而,它存在过度拟合的问题。因此,我在 GRU 层中添加了 dropout 正则化:

model.add(layers.GRU(32,
                     dropout=0.2,
                     recurrent_dropout=0.2,
                     input_shape=(None, 13)))

这将我的 epoch 的运行时间从 +- 10 秒增加到 +- 120 秒。有没有人解释为什么会这样?有没有办法对抗它,因为高出 12 倍的运行时间对我来说似乎有点不同寻常?

【问题讨论】:

    标签: python tensorflow keras recurrent-neural-network dropout


    【解决方案1】:

    我从以下论文中找到了这段摘录,其中强调了为什么 dropout 会增加每个 epoch 所花费的时间,上述情况通常是使用 dropouts 的一个缺点。

    One of the drawbacks of dropout is that it increases training time. A dropout network
    typically takes 2-3 times longer to train than a standard neural network of the same architecture. A major cause of this increase is that the parameter updates are very noisy.
    Each training case effectively tries to train a different random architecture. Therefore, the
    gradients that are being computed are not gradients of the final architecture that will be
    used at test time. Therefore, it is not surprising that training takes a long time
    

    有关更多详细信息,您可以参考这篇关于 dropouts 的论文: http://jmlr.org/papers/v15/srivastava14a.html

    此外, 这个答案https://stats.stackexchange.com/a/377126/197455 给出了一个好主意。

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      相关资源
      最近更新 更多