tensorboard colab tensorflow._api.v1.io.gfile' 没有属性 'get_filesystem

jus*_*dev 5 tensorboard pytorch

我正在尝试在 colab 上使用张量板。我设法使它工作,但不适用于所有命令。add_graph 和 add_scalar 有效,但是当我尝试运行 add_embedding 时,出现以下错误:

AttributeError: module 'tensorflow._api.v1.io.gfile' has no attribute 'get_filesystem'
Run Code Online (Sandbox Code Playgroud)

这是相关的代码(我认为);

import os
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter(log_dir ="logs" )

images, labels = select_n_random(trainset.data, trainset.targets)
images = torch.from_numpy(images)
labels = torch.from_numpy(np.array(labels))
class_labels = [classes[lab] for lab in labels]

# log embeddings
features = images.reshape((-1,32*32*3))
writer.add_embedding(features,metadata=class_labels) #, label_img=images.unsqueeze(1))
Run Code Online (Sandbox Code Playgroud)

完整的错误是:

/tensorflow-1.15.0/python3.6/tensorflow_core/python/util/module_wrapper.py in __getattr__(self, name)
    191   def __getattr__(self, name):
    192     try:
--> 193       attr = getattr(self._tfmw_wrapped_module, name)
    194     except AttributeError:
    195       if not self._tfmw_public_apis:

AttributeError: module 'tensorflow._api.v1.io.gfile' has no attribute 'get_filesystem'
Run Code Online (Sandbox Code Playgroud)

使用

  • tensorflow-1.15.0(尝试安装 2.0 但有不同的问题)
  • 蟒蛇 3.6.9
  • 火炬 1.4.0
  • tensorboard 2.1.1(也尝试过 1.15.0 但同样的问题)

我也尝试使用“魔法”命令:

%load_ext tensorboard
%tensorboard --logdir logs
Run Code Online (Sandbox Code Playgroud)

但我无法让它以这种方式工作(其他问题)。

任何建议如何使它工作?

Jja*_*ang 13

对我来说,这解决了问题:

import tensorflow as tf
import tensorboard as tb
tf.io.gfile = tb.compat.tensorflow_stub.io.gfile
Run Code Online (Sandbox Code Playgroud)


小智 2

卸载张量流。不要将tensorflow与torch安装在同一环境中。如果你安装了tensorflow,tensorboard可能会首先尝试使用tensorflow的api。

那么你可能会遇到这个问题:'LocalFileSystem' object has no attribute 'makedirs'
有一个解决方案 - https://github.com/pytorch/pytorch/issues/34028

  • 卸载的张量流
  • 重新安装Tensorboard
    PS:重新启动内核和tensorboard。

tensorboard 2.2.0 和 torch 1.14.0 对我有用。