python - 如何在Tensorflow中的tf.estimator上使用tensorflow调试工具tfdbg?

标签 python debugging tensorflow tensorflow-estimator

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

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

tf.contrib.learn Estimators 有一种方法可以做到这一点,但我找不到一种方法来使其适应(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

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

最佳答案

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

尝试:

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

代替:

hooks = [tf_debug.LocalCLIDebugHook()]      

如果你使用 Pycharm,添加到配置参数 --debug

关于python - 如何在Tensorflow中的tf.estimator上使用tensorflow调试工具tfdbg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47833697/

相关文章:

python - 从 DM.de 抓取客户评论

c - 调试子进程不适用于 set detach-on-fork off

python - 如何选择张量中的一组项目

android - Tensorflow 中的 'Const Op' 是什么?

python - 我如何在 django 中运行特定的迁移部门

python - 错误 pd.pivot "MultiIndex.name must be a hashable type"

python - 错误的注释 : class_id = 1. 但是 class_id 应该是 [from 0 to 0], file : data/obj/20210221_112744. txt

javascript - Chrome : Breakpoint when location. href 已设置

javascript - 检测大型 JS 程序中的任何变量何时设置为 NaN

python - 循环的可变长度 - tensorflow