简体   繁体   中英

How do I use tensorboard with pytorch?

I was following the pytorch tensorboard tutorial: https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html .

But I can't even start because of the following error:

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.

I installed pytorch 1.14 via conda. Am I supposed to install something else?

That tutorial should probably let you know that you need to install tensorboard. Take a look at the pytorch tensorboard docs which explains that you need to install tensorboard first.

Basically you can install tensorboard using

pip install tensorboard

and then start the tensorboard server by running

tensorboard --logdir=runs

The runs directory is where your summary writer will write to and it's where the tensorboard server reads from to know what to visualize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM