严厉警告 on_batch_begin

Keras Warning on_batch_begin

使用下面的回调 ResetStatesCallback 训练 rnn 模型时,我收到以下警告消息:

/var/venv/DSTL/lib/python3.4/site-packages/keras/callbacks.py:97: UserWarning: Method on_batch_begin() is slow compared to the batch update (0.791834). Check your callbacks. % delta_t_median)

from keras.callbacks import Callback
#Reset count every RESET_STATES_LENGTH
#RESET_STATES_LENGTH=8
class ResetStatesCallback(Callback):
    def __init__(self):
        self.counter = 0

    def on_batch_begin(self, batch, logs={}):
        if self.counter % RESET_STATES_LENGTH == 0:
            self.model.reset_states()
        self.counter += 1

为什么我会收到这条消息?我应该尝试修复它吗?它真的会减慢我的训练速度吗?

有关说明,请参阅 https://github.com/fchollet/keras/issues/5008。那里说

You are running something like saving the model or rendering images after each batch and it is taking longer than the batches themselves.

因此,Keras 似乎在运行时确定您的回调比批处理本身慢。