TensorBoard可视化
导航栏中的选项卡
- Scalars 显示损失和指标在每个时期如何变化。 您还可以使用它来跟踪训练速度,学习率和其他标量值。
- Graphs 可帮助您可视化模型。 在这种情况下,将显示层的Keras图,这可以帮助您确保正确构建。
- Distributions 和 Histograms 显示张量随时间的分布。 这对于可视化权重和偏差并验证它们是否以预期的方式变化很有用。
当您记录其他类型的数据时,会自动启用其他 TensorBoard 插件。 例如,使用 Keras TensorBoard 回调还可以记录图像和嵌入。 您可以通过单击右上角的“inactive”下拉列表来查看 TensorBoard 中还有哪些其他插件。
可视化
第一步:收集auc/loss
tf.summary.scalar('auc', auc)
需要在代码中有auc/loss计算的地方,使用上面那句话,收集auc/loss。经常放在模型定义的文件中。
再介绍几个函数:
TensorBoard通过summary对数据进行汇总。常用操作如下:
tf.summary.FileWriter——用于将汇总数据写入磁盘
tf.summary.scalar——对标量数据汇总和记录
tf.summary.histogram——记录数据的直方图
tf.summary.image——将图像写入summary
tf.summary.merge——对各类的汇总进行一次合并
tf.summary.merge_all——合并默认图像中的所有汇总
第二步:启动tensorBoard
tf.summary.scalar()收集的数据放在下面这种选中的文件中,eval时候收集的数据放在了eval那个文件夹中
打开终端,进入到model这个目录下,运行:
(tf) localhost:model wang$ ll
total 0
drwxr-xr-x 5 wang staff 160 Aug 24 18:07 ./
drwxr-xr-x 25 wang staff 800 Aug 24 18:35 ../
drwxr-xr-x 32 wang staff 1024 Aug 24 15:54 20210815/
drwxr-xr-x 21 wang staff 672 Aug 24 17:02 20210816/
drwxr-xr-x 21 wang staff 672 Aug 24 21:18 20210817/
(tf) localhost:model wang$ pwd
/Users/wang/big/feedrec/offline/model
(tf) localhost:model wang$ tensorboard --logdir 20210817/
/Users/wang/anaconda3/envs/tf/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
W0824 18:15:19.534792 123145575596032 plugin_event_accumulator.py:294] Found more than one graph event per run, or there was a metagraph containing a graph_def, as well as one or more graph events. Overwriting the graph with the newest event.
W0824 18:15:19.539469 123145575596032 plugin_event_accumulator.py:302] Found more than one metagraph event per run. Overwriting the metagraph with the newest event.
TensorBoard 1.14.0 at http://localhost:6011/ (Press CTRL+C to quit)
W0824 18:43:12.207637 123145575596032 plugin_event_accumulator.py:294] Found more than one graph event per run, or there was a metagraph containing a graph_def, as well as one or more graph events. Overwriting the graph with the newest event.
重点:
1.进入到events.out.tfevents.1629799638.localhost所在的上级目录。再运行 tensorboard --logdir 20210817/ 否则会报出乱七八糟的错误。
一个可信任的model该有的auc走势:
遇到的问题
完全按照上面执行,就不会遇见下面问题,可以结束本次浏览 。
一 、tensorboard: error: invalid choice: '–logdir=eval' (choose from 'serve', 'dev')
原因:logdir没写对
二、No dashboards are active for the current data set.
原因:logdir没写对
三、ValueError: GetLogdirSubdirectories: path exists and is not a directory
原因:tensorboard --logdir events.out.tfevents.1637840530.algogossip 将--logdir 的参数写到了文件级别,应该写到文件夹级别。
参考:
1.官方文档:https://www.tensorflow.org/tensorboard/get_started
2.深度学习编码的一个例子:https://dl.apachecn.org/#/docs/hands-on-ml-2e-zh/13