首页 > 解决方案 > Keras:方法 on_batch_end() 很慢,但我没有回调?

问题描述

Keras 刚刚警告我:

用户警告:与批量更新 (0.988304) 相比,方法 on_batch_end() 速度较慢。检查你的回调。

我的 keras 脚本中没有回调,但我正在使用DataGenerator( keras.utils.Sequence)。这会是个问题吗?

对于DataGenerator,我已经实现了__init__()__len__()__getitem()__on_epoch_end方法。

对于on_epoch_end,我有:

def on_epoch_end(self):
    """
    This method will be called between every epoch, so we can shuffle the
    indexes here.
    """
    self.indexes = np.arange(len(self.image_names))
    if self.shuffle:
        np.random.shuffle(self.indexes)

完整的调用栈如下:

使用 TensorFlow 后端。/var/lib/condor/execute/slot1/dir_30551/anaconda/envs/cellimage/lib/python3.6/site-packages/skimage/transform/_warps.py:84:用户警告:默认模式“常量”将在 skimage 0.15 中更改为“反射”。

warn("默认模式,'constant',将在 " /var/lib/condor/execute/slot1/dir_30551/anaconda/envs/cellimage/lib/python3.6/site-packages/keras 中更改为 'reflect' /callbacks.py:120: UserWarning: 方法 on_batch_end() 与批量更新 (0.586719) 相比很慢。检查你的回调。% delta_t_median)

/var/lib/condor/execute/slot1/dir_30551/anaconda/envs/cellimage/lib/python3.6/site-packages/keras/callbacks.py:120:UserWarning:与批量更新相比,方法on_batch_end()慢(0.988304)。检查你的回调。% delta_t_median)

标签: pythonkeras

解决方案


这可能与您的设置有关verbose

我看到的也是一样的。我相信这是因为我verbose=1接到了电话fit()- 即打印进度条和当前统计信息是一项耗时太长的批处理任务。这个假设得到了证据的支持,即如果我设置verbose=2了仅在纪元结束时打印或verbose=0根本不打印的警告停止。如果我增加批量大小,警告也会停止。


推荐阅读