tensorflow - Is it possible to override the progress bar of TensorFlow's keras?
问题描述
In the last days, I have been observing a weird behavior in the printed loss in the progress bar. It turned out that the weird behaviour was due to the fact that the default progress bar of keras displays a moving average of the losses (rather than the actual losses at every epoch).
So, is it possible to override the progress bar of TensorFlow's keras? I don't think so.
There's the class tf.keras.utils.Progbar
that contains the parameter stateful_metrics
, which is probably what I need, but fit
doesn't seem to provide an option to override the progress bar or to change the behaviour from moving average to actual loss of the epoch/step. What alternative do you suggest? Feel free to write an answer below with some reproducible code.
解决方案
听起来你想要的应该通过tf.keras.callbacks.ProgbarLogger
. 从理论上讲,它应该按照以下示例中概述的方式工作,但是,当前存在tf.keras.callbacks.ProgbarLogger
.
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Flatten
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train, x_test = x_train / 255, x_test / 255
model = tf.keras.Sequential([
Flatten(),
Dense(128, activation='relu'),
Dense(10)
])
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer='adam', loss=loss_fn, metrics=['accuracy'])
progbar_callback = tf.keras.callbacks.ProgbarLogger(stateful_metrics="accuracy")
model.fit(x_train, y_train, callbacks=[progbar_callback])
推荐阅读
- php - Google Drive API 代码身份验证返回 500 错误
- bash - Curl:如何从文件中传递特定键的值
- c# - DLL 版本不匹配:找到的程序集的清单定义与程序集引用不匹配
- python - pyspark用正则表达式读取csv文件
- jboss - 如何使用 jBPM 7.7 配置我的 MySQL 5.7?
- apache-spark - 如何确定 PySpark 数据帧分区的“首选位置”?
- angular - 如何将 composeAsync 添加到 Angular 5 验证器
- angular - Angular 4中的Rest API调用得到CORS错误
- javascript - 用于验证没有时间的日期的 Moment js 格式
- java - 如何通过单击按钮将图像从 URL 设置为墙纸?