python - 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)
解决方案
这可能与您的设置有关verbose
。
我看到的也是一样的。我相信这是因为我verbose=1
接到了电话fit()
- 即打印进度条和当前统计信息是一项耗时太长的批处理任务。这个假设得到了证据的支持,即如果我设置verbose=2
了仅在纪元结束时打印或verbose=0
根本不打印的警告停止。如果我增加批量大小,警告也会停止。
推荐阅读
- angular - 角度自定义管道返回表数据错误
- java - Java - 每次循环迭代后累加器变量不递增
- stylesheet - Drupal 8 样式表更改每次都必须重建缓存。有没有更好的办法?
- sql - 如何在 SQL Server 中创建数据集并处理每条记录?
- neo4j - 将 tsv 文件中的选定行导入 neo4j
- node.js - NodeJS - 从 Promise.all 函数返回值时获取“未定义”
- sql - 使用 SQL 从表列解析 XML
- java - 在 Oreo 及更高版本中使用 WorkManager 时是否应该显示持续通知?
- r - 如何将以下数据集合并为独立行?
- scala - Scala,使用 play 2.5 将 joda.LocalDateTime 转换为 json