ImportError: TensorBoard logging requires TensorBoard version 1.15 or above

ImportError: TensorBoard logging requires TensorBoard version 1.15 or above

我遵循 pytorch.org 中的教程 出现错误:TensorBoard logging requires TensorBoard version 1.15 or above,但我已经安装了TensorBoard。 这是代码:

#from torch.utils.tensorboard import SummaryWriter
from tensorboardX import SummaryWriter
writer = SummaryWriter('runs/fashion_mnist_experiment_1')
#get some random training images
dataiter = iter(trainloader)
images , labels = dataiter.next()
#create grid of images
img_grid = torchvision.utils.make_grid(images)
matplotlib_imshow(img_grid,one_channel=True)
writer.add_image('four_fashion_images',img_grid)
writer.add_graph(net, images)
writer.close()

错误:

ImportError                               Traceback (most recent call last)
<ipython-input-12-d38808675cb4> in <module>
----> 1 writer.add_graph(net, images)
      2 writer.close()

~\anaconda3\envs\torch2\lib\site-packages\tensorboardX\writer.py in add_graph(self, model, input_to_model, verbose)
    791 
    792         """
--> 793         from torch.utils.tensorboard._pytorch_graph import graph
    794         self._get_file_writer().add_graph(graph(model, input_to_model, verbose))
    795 

~\anaconda3\envs\torch2\lib\site-packages\torch\utils\tensorboard\__init__.py in <module>
      2 from distutils.version import LooseVersion
      3 if not hasattr(tensorboard, '__version__') or LooseVersion(tensorboard.__version__) < LooseVersion('1.15'):
----> 4     raise ImportError('TensorBoard logging requires TensorBoard version 1.15 or above')
      5 del LooseVersion
      6 del tensorboard

ImportError: TensorBoard logging requires TensorBoard version 1.15 or above

环境:

tensorboard               2.3.0                    pypi_0    pypi
tensorboard-plugin-wit    1.7.0                    pypi_0    pypi
tensorboardx              2.1                      pypi_0    pypi
tensorflow                1.2.1                    py36_0    defaults
pytorch                   1.6.0           py3.6_cuda102_cudnn7_0    pytorch
torchvision               0.7.0                py36_cu102    pytorch
future                    0.18.2                   py36_1    defaults
protobuf                  3.12.3           py36h33f27b4_0    defaults

我一开始用的是from torch.utils.tensorboard import SummaryWriter,但是出现了和above.Then一样的错误,我用的是from tensorboardX import SummaryWriter

卸载 tensorflowtensorboardtensorboardxtensorboard-plugin-wit

只安装tensorboard,然后安装conda

如果这不起作用,请仅使用 tensorboard 重新创建 conda 环境。如果需要 tensorflow 也请提前安装。

编辑:

tensorboard-plugin-wittensorboard 的依赖项,在安装 tensorboard 本身时应根据其 pypi 描述自动安装。

我的问题是我工作的目录被命名为 tensorboard,所以它试图从当前目录导入而不是从已安装的包导入。 所以我建议尝试重命名目录,看看是否有帮助。

conda uninstall tensorflow
conda uninstall tensorboard
conda uninstall tensorboardx
conda uninstall tensorboard-plugin-wit
conda uninstall cloud-tpu-client
pip uninstall tensorflow
pip uninstall tensorboard
pip uninstall tensorboardx
pip uninstall tensorboard-plugin-wit
pip uninstall cloud-tpu-client

然后

conda install tensorboard

conda installpip install我都试过了,但是在ipynb文件中使用from torch.utils.tensorboard import SummaryWriter还是出现这个错误。我检查了 not hasattr(tensorboard, '__version__') or LooseVersion(tensorboard.__version__) < LooseVersion('1.15'),它们都是 False,这意味着它不会引发错误。

最后,我关闭了这个ipynb文件并重新启动它,它成功了。你应该试试这个,而不需要为重新安装你的 conda 环境而苦苦挣扎。

就我而言,遇到错误时我只有 Tensorboard 而没有 Tensorflow,所以我不得不:

conda uninstall tensorboard - 这也删除了 PyTorch Lightning
conda install tensorboard
conda install -c conda-forge pytorch-lightning