Tens的Spyder调试器

2024-10-06 12:07:45 发布

您现在位置:Python中文网/ 问答频道 /正文

Spyder提供了一个功能强大的调试器,可用于在执行期间暂停代码并检查变量。在

另一方面,Tensorflow变量不容易检查。有没有办法在spyder的python控制台中查看它们?在

更新: 当我试图回答anatoly techtonik的评论时,我决定编写一个虚拟程序来向case展示情况:

import tensorflow as tf

class foo(object):

    def __init__(self, a, b):
        self.a = tf.constant(a)
        self.b = tf.constant(b)
        init = tf.initialize_all_variables()
        self.c = self._foo_add()
        # Launch the session
        self.sess = tf.InteractiveSession()
        self.sess.run(init)

    def _foo_add(self):
        m = tf.add(self.a,self.b)
        return tf.add(m, tf.constant(1))

    def print_foo(self):
        return self.sess.run(self.c)

f = foo(2,3)
print f.print_foo()

如果在函数_foo_add的return语句上设置一个检查点,按debug按钮并在控制台中键入m.eval(),则可以访问其值,在本例中为5。 我想这回答了我的问题。谢谢anatoly techtonik。在


Tags: runselfaddreturnfooinittfdef
1条回答
网友
1楼 · 发布于 2024-10-06 12:07:45

你考虑过使用tensorflow调试器吗

https://www.tensorflow.org/api_guides/python/tfdbg

带着MNIST教程来

在www.tensorflow.org/programmers_guide/debugger在

另一种选择:Jupyter笔记本似乎也有类似的扩展 (认为该项目似乎已停止)

https://github.com/ericjang/tdb

相关问题 更多 >