ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.

Tensorboard原本是Google TensorFlow的可视化工具,可以用于记录训练数据、评估数据、网络结构、图像等,并且可以在web上展示,对于观察神经网络的过程非常有帮助。

项目场景:

突然报如下错误,我以为是环境坏掉了,重装环境搞了半天,猜猜最后是什么原因?

ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed.


问题描述

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      1 try:
----> 2     from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
      3 except ImportError:

ModuleNotFoundError: No module named 'tensorboard.summary'; 'tensorboard' is not a package

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
c:\Users\matt\Documents\code\playground\tensorboard.py in 
----> 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')

C:\ProgramData\Anaconda3\envs\fastai_v1\lib\site-packages\torch\utils\tensorboard\__init__.py in 
      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.


原因分析:

tensorboard的版本太低了
使用下面的版本安装新版本的tensorboard


解决方案:

如果还报有没有No module named ‘tensorboard’ 的错,则说明是由于没有安装tensorboard引起的,类似一下这种报错

Traceback (most recent call last):
  File "/home/../anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/tensorboard/__init__.py", line 2, in 
    from tensorboard.summary.writer.record_writer import RecordWriter  # noqa F401
ModuleNotFoundError: No module named 'tensorboard'

所以解决办法是安装tensorboard即可

 如果确认安装了tensorboard 依然报错,应该和版本有关

安装新版本的tensorboard

conda install -c conda-forge tensorboard

可能存在的问题:

报错:TypeError: __init__() got an unexpected keyword argument 'serialized_options'

# 很可能是protobuf的版本不对导致的
# 可以先卸载掉protobuf,再重新安装

pip install -U protobuf

 

你可能感兴趣的:(#,Pytorch编写中遇到的问题,python,开发语言,深度学习,pytorch,机器学习)