我如何在 pytorch 中使用 tensorboard?

How do I use tensorboard with pytorch?

我正在关注 pytorch tensorboard 教程:https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html

但是由于以下错误我什至无法开始:

from torch.utils.tensorboard import SummaryWriter
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~/apps/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/tensorboard/__init__.py in <module>
      1 try:
----> 2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:

ModuleNotFoundError: No module named 'tensorboard'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-4-c8ffdef1cfab> in <module>
----> 1 from torch.utils.tensorboard import SummaryWriter
      2 
      3 # default `log_dir` is "runs" - we'll be more specific here
      4 writer = SummaryWriter('runs/fashion_mnist_experiment_1')

~/apps/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/tensorboard/__init__.py in <module>
      2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:
----> 4     raise ImportError('TensorBoard logging requires TensorBoard with Python summary writer installed. '
      5                       'This should be available in 1.14 or above.')
      6 from .writer import FileWriter, SummaryWriter  # noqa F401

ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.

我通过 conda 安装了 pytorch 1.14。我应该安装其他东西吗?

该教程可能会让您知道您需要安装 tensorboard。看一下 pytorch tensorboard docs 说明你需要先安装 tensorboard。

基本上你可以使用

安装 tensorboard
pip install tensorboard

然后按运行

启动tensorboard服务器
tensorboard --logdir=runs

runs 目录是您的摘要编写者将写入的位置,也是张量板服务器从中读取以了解要可视化的内容的位置。