6 months ago

TensorFlow有一个亮点就是,我们能看到自己写的程序,这个功能就是Tensorboard
下面介绍开启Tensorboard的步骤
1.数据序列化-events文件 --- jupyter或ipython中执行,通常在Session会话中运行

import tensorflow as tf
# 返回filewriter,写入事件文件到指定目录(最好用绝对路径),以提供给tensorboard使用
tf.summary.FileWriter('/tmp/tensorflow/summary/test/', graph=sess.graph)

这将在指定目录中生成一个 event 文件,其名称格式 events.out.tfevents.{timestamp}.{hostname}
2.启动TensorBoard ---- 命令行中执行

tensorboard  --logdir="/tmp/tensorflow/summary/test/"

第一次会报一个错误

Traceback (most recent call last):
  File "c:\users\hp\appdata\local\programs\python\python35\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\hp\appdata\local\programs\python\python35\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\HP\Envs\data_process\Scripts\tensorboard.exe\__main__.py", line 5, in <module>
  File "c:\users\hp\envs\data_process\lib\site-packages\tensorboard\main.py", line 28, in <module>
    import tensorflow as tf
  File "c:\users\hp\envs\data_process\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "c:\users\hp\envs\data_process\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "c:\users\hp\envs\data_process\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "c:\users\hp\envs\data_process\lib\site-packages\tensorflow\python\platform\self_check.py", line 55, in preload_check
    % build_info.msvcp_dll_name)
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587

主要原因是:TensorFlow是基于VC++2015开发的,所以需要下载安装VisualC++ Redistributable for Visual Studio 2015 来获取MSVCP140.DLL的支持。
解决方案系统已经有提示:到指定网址去下载软件Visual C++ 2015 Redistributable

3.再次启动TensorBoard
系统提示运行成功

2018-11-23 19:23:29.644801: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
W1123 19:23:29.673004 Reloader tf_logging.py:121] 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.
W1123 19:23:29.681026 Reloader tf_logging.py:121] Found more than one metagraph event per run. Overwriting the metagraph with the newest event.
TensorBoard 1.8.0 at http://小李子爱生活:6006 (Press CTRL+C to quit)

将出现在最后一行的urlhttp://小李子爱生活:6006复制到浏览器打开即可

参考资料:
运行tensorboard --logdir=log遇到的错误之can't assign to operator
Windows下安装TensorFlow快速教程

← 【机器学习】numpy与python中的随机数模块 【深度学习】动态人脸识别haarcascade分类器下载 →