pycharm中使用tfdebugger及常见问题

作者:daidaihema
原文地址:https://blog.csdn.net/daidaihema/article/details/79516767








环境Windows10,Anaconda3。

错误:

curses问题

去这里下载相应的库:https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses

利用pip install 安装,见下图:

这里写图片描述

pip install安装时遇到的问题

TypeError: parse() got an unexpected keyword argument ‘transport_encoding’

解决办法

conda install -c anaconda html5lib
再次安装:
conda install pip
然后再执行:pip install 命令。

安装pyreadline

修改颜色用的,代码中设置ui_type=”readline”

conda install pyreadline


import numpy as np
import tensorflow as tf
from tensorflow.python import debug as tf_debug

xs = np.linspace(-0.5, 0.49, 100)
x = tf.placeholder(tf.float32, shape=[None], name="x")
y = tf.placeholder(tf.float32, shape=[None], name="y")
k = tf.Variable([0.0], name="k")
y_hat = tf.multiply(k, x, name="y_hat")
sse = tf.reduce_sum((y - y_hat) * (y - y_hat), name="sse")
train_op = tf.train.GradientDescentOptimizer(learning_rate=0.02).minimize(sse)

sess = tf.Session()
sess.run(tf.global_variables_initializer())

sess = tf_debug.LocalCLIDebugWrapperSession(sess,ui_type="readline")
for _ in range(10):
  sess.run(y_hat,feed_dict={x:xs,y:10*xs})
  sess.run(train_op, feed_dict={x: xs, y: 42 * xs})
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

然后执行命令:

python demo_debug.py –debug
或者
python -m demo_debug –debug

这里写图片描述

debug 界面中 带 下划线的 东西 都是可以用鼠标点一下,就会触发相应操作的

核心的几个命令是:

run :执行一次 debug_session.run() , 这次执行产生中间 tensor 的值都可以通过 debug 界面查看
exit : 退出 debug

这时可以用鼠标点击“Tensor name”,ui_type=”readline”时不可以,查看相应的 tensor 详情(等价为输入命令:pt tensor_name)。
比如我们查看上述代码中y_hat变量的情况,输入如下命令:

pt y_hat:0
 
 
  • 1
  • 1

如图所示:
这里写图片描述

Commands:

list_tensors (lt) : Show the list of dumped tensor(s).
print_tensor (pt) : Print the value of a dumped tensor.
node_info (ni) : Show information about a node
ni -t : Shows the traceback of tensor creation
list_inputs (li) : Show inputs to a node
list_outputs (lo) : Show outputs to a node
run_info (ri) : Show the information of current run
(e.g. what to fetch, what feed_dict is)
invoke_stepper (s) : Invoke the stepper!
run (r) : Move to the next run

pycharm环境下tfdbg:

这时sess = tf_debug.LocalCLIDebugWrapperSession(sess,ui_type=”readline”)中ui_type=“readline”,其它情况未测,好像通过设置也可以.
这里写图片描述

[原链接] (http://blog.csdn.net/philosophyatmath/article/details/79153347)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值