【问题标题】:Model with BatchNormalization: stagnant test loss具有 BatchNormalization 的模型:停滞的测试损失
【发布时间】:2017-04-27 09:57:10
【问题描述】:

我使用 Keras 编写了一个神经网络。它包含 BatchNormalization 层。

当我用model.fit 训练它时,一切都很好。当用 tensorflow as explained here 训练它时,训练很好,但是验证步骤总是给出很差的性能,并且很快就饱和(准确度达到 5%、10%、40%、40%、40% ......;损失也停滞不前)。

我需要使用 tensorflow,因为它在训练的监控部分提供了更大的灵活性。

我强烈怀疑这与 BN 层或/和我计算测试性能的方式有关(见下文)

feed_dict = {x: X_valid,
            batch_size_placeholder: X_valid.shape[0],
            K.learning_phase(): 0,
            beta: self.warm_up_schedule(global_step)
            }
if self.weights is not None:
    feed_dict[weights] = self.weights
acc = accuracy.eval(feed_dict=feed_dict)

在计算包含 Keras BatchNormalizatin 层的模型的验证准确性时,有什么特别的事情要做吗?

提前谢谢你!

【问题讨论】:

    标签: tensorflow keras keras-layer


    【解决方案1】:

    其实我发现了__call__ method of the BatchNormalization layertraining参数

    所以在实例化层时你可以做的只是:

    x = Input((dim1, dim2))
    h = Dense(dim3)(x)
    h = BatchNormalization()(h, training=K.learning_phase())
    

    并且在评估验证集的性能时:

    feed_dict = {x: X_valid,
                 batch_size_placeholder: X_valid.shape[0],
                 K.learning_phase(): 0,
                 beta: self.warm_up_schedule(global_step)
                 }
    acc = accuracy.eval(feed_dict=feed_dict)
    summary_ = merged.eval(feed_dict=feed_dict)
    test_writer.add_summary(summary_, global_step)
    

    【讨论】:

    • 其实我错了,它不起作用,但我不明白为什么
    • 我刚刚遇到了类似的问题,发现在BatchNormalization__call__ 中设置training=1 似乎有效。就批量标准化而言,将K.learning_phase() 设置为 0 或 1 似乎对输出没有影响,并且只要您不运行训练操作,批量规范参数就不应更改。
    • 所以你会建议使用不同的占位符而不是 K.learning_phase() ?
    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 2019-10-24
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2020-09-05
    相关资源
    最近更新 更多