用打印的方式来调试tensorflow实在是太麻烦了,幸运的是,tensorflow 推出了tfdbg,他需要改动的代码行数更少,而且提供的调试体验交互性更强,可以加快开发和调试的速度。
所以我按着网上的教程,先copy了一份示例代码:
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)
for _ in range(10):
sess.run(train_op, feed_dict={x: xs, y: 42 * xs})
执行起来却出了问题:
1.no module named 'tensorflow.python.debug.lib'
找了一通毛病,发现是自己tensorflow的版本低了,windows下的要升级到
最新版本(1.1.0rc1)
2.Error while finding spec for 'XX.py' (<class 'ValueError'>: Exhausted all fallback ui_types.)
根据官方教程,需要安装pyreadline
pip install pyreadline
未完待续
网友评论