我的问题是当我尝试运行此代码时
if log_to_tensorboard: from torch.utils.tensorboard import SummaryWriter
if log_to_tensorboard: writer = SummaryWriter()
我收到此错误:
(导入 SummaryWriter 工作没有任何问题,但后来我尝试运行"writer = SummaryWriter((",但它不起作用(
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-d77d9d09e62b> in <module>
----> 1 writer = SummaryWriter()
/anaconda3/lib/python3.6/site-packages/torch/utils/tensorboard/writer.py in __init__(self, log_dir, comment, purge_step, max_queue, flush_secs, filename_suffix)
223 # and recreated later as needed.
224 self.file_writer = self.all_writers = None
--> 225 self._get_file_writer()
226
227 # Create default bins for histograms, see generate_testdata.py in tensorflow/tensorboard
/anaconda3/lib/python3.6/site-packages/torch/utils/tensorboard/writer.py in _get_file_writer(self)
254 if self.all_writers is None or self.file_writer is None:
255 self.file_writer = FileWriter(self.log_dir, self.max_queue,
--> 256 self.flush_secs, self.filename_suffix)
257 self.all_writers = {self.file_writer.get_logdir(): self.file_writer}
258 if self.purge_step is not None:
/anaconda3/lib/python3.6/site-packages/torch/utils/tensorboard/writer.py in __init__(self, log_dir, max_queue, flush_secs, filename_suffix)
64 log_dir = str(log_dir)
65 self.event_writer = EventFileWriter(
---> 66 log_dir, max_queue, flush_secs, filename_suffix)
67
68 def get_logdir(self):
/anaconda3/lib/python3.6/site-packages/tensorboard/summary/writer/event_file_writer.py in __init__(self, logdir, max_queue_size, flush_secs, filename_suffix)
71 """
72 self._logdir = logdir
---> 73 if not tf.io.gfile.exists(logdir):
74 tf.io.gfile.makedirs(logdir)
75 self._file_name = os.path.join(logdir, "events.out.tfevents.%010d.%s.%s.%s" %
/anaconda3/lib/python3.6/site-packages/tensorboard/lazy.py in __getattr__(self, attr_name)
63 class LazyModule(types.ModuleType):
64 def __getattr__(self, attr_name):
---> 65 return getattr(load_once(self), attr_name)
66
67 def __dir__(self):
AttributeError: module 'tensorflow' has no attribute 'io'
如何解决? 我卸载并安装了 tensorflow,升级了张量板和火炬 - 这对我没有帮助
我遇到了同样的问题。我的解决方案如下:
- 检查是否存在
tensorflow-tensorboard
。
pip uninstall tensorflow-tensorboard
- >install tensorboard==1.14
因为发生了错误:TensorBoard 日志记录需要安装了 Python 摘要编写器的 TensorBoard。这应该在 1.14 或更高版本中可用。
参考: https://github.com/pytorch/pytorch/issues/20140
pip install tensorboard==1.14.0
我能够使用此处推荐的解决方案来解决此问题,该解决方案建议:
pip install tensorflow-io
升级我的 pytorch 和张量板版本后,我遇到了同样的错误。这里的提议都不适合我。我将 tensorflow 升级到最新版本,安装了其他人建议的其他 tensorflow-* 包。什么都没用。最终,我发现强制加载tensorflow_stub是这里的解决方案。所以对我来说,简单的解决方案是卸载 tensorflow(和其他 tensorflow-*(版本。换句话说,
pip uninstall tensorflow
为了好起见,我还在卸载后重新启动了机器,错误消失了
可以升级张量板的版本