<p>当我遇到同样的问题时,您可以使用这几行灵感来自<code>tensorboard\main.py</code>:</p>
<pre><code>from tensorboard import default
from tensorboard import program
tb = program.TensorBoard(default.PLUGIN_LOADERS, default.get_assets_zip_provider())
tb.configure(argv=['--logdir', my_directory])
tb.main()
</code></pre>
<p>以<code>my_directory</code>作为要检查的文件夹。如果要避免在<code>tb.main()</code>之后被阻塞,请不要忘记创建单独的线程。
致意</p>
<p>编辑Tensorboard V1.10:</p>
<p>出于个人原因,我用另一种方式来写:</em></p>
<pre><code>class TensorBoardTool:
def __init__(self, dir_path):
self.dir_path = dir_path
def run(self):
# Remove http messages
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
# Start tensorboard server
tb = program.TensorBoard(default.PLUGIN_LOADERS, default.get_assets_zip_provider())
tb.configure(argv=['--logdir', self.dir_path])
url = tb.launch()
sys.stdout.write('TensorBoard at %s \n' % url)
</code></pre>
<p>编辑Tensorboard V1.12:</p>
<p><em>根据Elad Weiss和tsbertalan对tensorboard 1.12版的描述。</em></p>
<pre><code> def run(self):
# Remove http messages
log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
# Start tensorboard server
tb = program.TensorBoard(default.get_plugins(), default.get_assets_zip_provider())
tb.configure(argv=[None, '--logdir', self.dir_path])
url = tb.launch()
sys.stdout.write('TensorBoard at %s \n' % url)
</code></pre>
<p>然后运行它只要:</p>
<pre><code># Tensorboard tool launch
tb_tool = TensorBoardTool(work_dir)
tb_tool.run()
</code></pre>
<p>这将允许您在主进程的同时运行Tensorboard服务器,而不会干扰http请求!</p>