tensorflow debug vs tensorflow eager

1. tensorflow debugger

因为tensorflow是先建立静态图计算,最后再给喂数据,所以插入断点等debug方式难以适用, 程序中一些数据处理的错误难以发现。
tensorflow自己开发了一个专用调试器 tensorflow debugger

/# 使用范例
from tensorflow.python import debug as tfdbg
sess = tf.Session()
sess = tfdbg.LocalCLIDebugWrapperSession(sess)
#每次在run的时候会自动打开debug终端
# 打开终端之后
>run //运行
>lt // 列出所有tensor, 此时可以点击tensor名查看tensor值,pycharm页面内无法点击查看只能命令行查看
>pt tensor_name // 查看tensor值,与鼠标点击tensor等价
>run // 继续执行
  • 官方说明文档网址:https://www.tensorflow.org/guide/debugger#other_features_of_the_tfdbg_cli

注意:tensorflow debugger在pycharm上面运行如果报_curses.error: setupterm: could not find terminal错误时,打开edit configuration, 勾选Emulate terminal in output console选项。
如果问题还没有解决或在其他平台上出现_curses.error: setupterm: could not find terminal类错误,可能是因为没有设置环境变量,运行如下代码设置环境变量:

export TERM=linux
export TERMINFO=/etc/terminfo

如果系统没有/etc/terminfo目录则创建目录, 并拷贝terminfo database。对于 "linux"和"pcansi" 终端, 可以在如下网址下载database:

  • http://forum.xda-developers.com/attachment.php?attachmentid=2134052&d=1374459598
  • http://forum.xda-developers.com/showthread.php?t=552287&page=4

更多有关terminal not found的问题,详见https://stackoverflow.com/questions/9485699/setupterm-could-not-find-terminal-in-python-program-using-curses

2. tensorflow eager

第二个有力debugger helper是eager,eager从tensorflow 1.4开始包含在tensorflow安装包中不需要额外安装
eger建立动态图,使tensorflow立刻运算并返回具体值。

  1. 安装
    如果安装了TensorFlow1.4可以直接使用eager, 否则可以安装简洁版框架
pip install tf-nightly # (for CPU-only TensorFlow)
pip install tf-nightly-gpu # (for GPU-enabled TensorFlow)
  1. 使用
import tensorflow.contrib.eager as tfe

tfe.enable_eager_execution()
a = tf.constant([[1,2],[3,4]])
print(a)
# 可以直接打印tensor

3. 其他debug教学材料

https://wookayin.github.io/tensorflow-talk-debugging/#1

你可能感兴趣的:(tensorflow debug vs tensorflow eager)