如何在Tensorflow中使用tfdbg调试工具来调试tf.estimator?

10

我正在使用Tensorflow 1.4版本,并想要调试我的train()函数。

在这个链接中https://www.tensorflow.org/programmers_guide/debugger#debugging_tf-learn_estimators_and_experiments

有一种方法可以用于tf.contrib.learn Estimators,但我找不到一种适应(Tensorflow 1.4中新出现的)tf.estimator的方法。

这是我尝试过的:

from tensorflow.python import debug as tf_debug

# Create an estimator
my_estimator = tf.estimator.Estimator(model_fn=model_fn, 
                                      params=model_params,
                                      model_dir='/tb_dir',
                                      config=config_estimator)

# Create a LocalCLIDebugHook and use it as a hook when calling train().
hooks = [tf_debug.LocalCLIDebugHook()]

# Train
my_estimator.train(input_fn=train_input_fn, steps=10,hooks=hooks)

但我遇到了这个错误:

> --------------------------------------------------------------------------- error 
Traceback (most recent call
> last) <ipython-input-14-71325f3c8f14> in <module>()
>       7 
>       8 # Train
> ----> 9 my_estimator.train(input_fn=train_input_fn, steps=10,hooks=hooks)
> 
[...]
> 
> /root/anaconda3/lib/python3.6/site-packages/tensorflow/python/debug/cli/curses_ui.py
> in _screen_launch(self, enable_mouse_on_start)
>     443 
>     444     curses.noecho()
> --> 445     curses.cbreak()
>     446     self._stdscr.keypad(1)
>     447 
> 
> error: cbreak() returned ERR

有人能指点我正确的方向吗?

1个回答

5

默认设置适用于在命令行中工作,如果您使用像Pycharm这样的IDE,则最简单的解决方案是更改UI类型。

尝试:

hooks = [tf_debug.LocalCLIDebugHook(ui_type="readline")]

替换为:

hooks = [tf_debug.LocalCLIDebugHook()]      

如果您使用Pycharm,请将--debug添加到配置参数中。

我正在使用Jupyter笔记本工作,是的,它正在与您的解决方案一起工作。谢谢。 - Benjamin Larrousse

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接