【问题标题】:Tensorboard Error - NameError: name 'tensorboard' is not definedTensorboard 错误 - NameError:未定义名称“tensorboard”
【发布时间】:2017-05-18 03:42:39
【问题描述】:

我现在正在学习 tensorflow,但无法让 tensorboard 工作。我尝试了下面的简单程序,但没有成功。该程序在我使用 tensorboard 代码之前可以运行,但是当我使用 tensorboard 代码时,我收到以下错误:

NameError: name 'tensorboard' is not defined

如有任何帮助,我们将不胜感激。

import tensorflow as tf


a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_a")
c = tf.multiply(a,b, name="mul_c")
d = tf.add(a,b, name="add_d")
e = tf.add(c,d, name="add_e")

sess = tf.Session()
sess.run(e)
output = sess.run(e)

writer = tf.summary.FileWriter('/tmp/newtest', graph=sess.graph)

print(sess.run(e))

tensorboard --logdir /tmp/newtest

【问题讨论】:

  • 是什么让您想到应该在 Python 程序中插入 tensorboard --logdir /tmp/newtest?那不是 Python。这是一个shell命令行。
  • user2357112,,, 非常感谢您的回复...我真的很感激...我所做的所有阅读都没有表明它是一个 shell 命令..我现在正在学习和你真的帮了我在这里..这工作!...非常感谢!!!!

标签: tensorboard


【解决方案1】:

我相信这已经“回答”了,但是,就我的所作所为,我希望它对您或其他人有所帮助。

这只是覆盖触发和显示张量板的结束开销。

import subprocess
import webbrowser
import time

logLocation = 'tflearn_logs'

print("\r\nWould you like to see the visual results (y/N)? ", end='', flush=True)
answer = input()
if answer.strip().lower() == "y":
    port = str(8018)
    print("Starting Tensorboard to visualize... ")
    process = subprocess.Popen(['tensorboard', "--logdir='" + logLocation + "'", '--port=' + port])

    # Wait for a few seconds, give the tensorboard a headstart
    time.sleep(5)

    print("Opening Tensorboard webpage... ")
    url = 'http://127.0.0.1:' + port + '/'
    # Path differs per OS (Windows, Linux, iOS)
    chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
    webbrowser.get(chrome_path).open(url) 

print("Press enter to quit... ", end='', flush=True)
answer = input()
if process is not None:
    process.kill()

【讨论】:

    猜你喜欢
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 2016-03-11
    相关资源
    最近更新 更多