我在尝试将
torch.utils.tensorboard.SummaryWriter
与 PyTorch 结合使用时遇到问题。我正在 torch 中训练 DCGAN,尽管没有在代码中直接导入或使用 TensorFlow,但我收到以下错误:
Traceback (most recent call last):
File "C:/Users/Gebruiker/PycharmProjects/BobRossGAN/train.py", line 47, in <module>
writer_real = SummaryWriter(f"logs/real")
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\utils\tensorboard\writer.py", line 247, in __init__
self._get_file_writer()
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\utils\tensorboard\writer.py", line 277, in _get_file_writer
self.file_writer = FileWriter(
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\utils\tensorboard\writer.py", line 76, in __init__
self.event_writer = EventFileWriter(
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorboard\summary\writer\event_file_writer.py", line 73, in __init__
if not tf.io.gfile.exists(logdir):
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorboard\lazy.py", line 65, in __getattr__
return getattr(load_once(self), attr_name)
AttributeError: module 'tensorflow' has no attribute 'io'
这是我的代码片段:
import torch
from torch.utils.tensorboard import SummaryWriter
# other imports and code
writer_real = SummaryWriter(f"logs/real")
我可以发布我的完整代码,但是在
SummaryWriter
初始化时抛出错误。
我不确定为什么这个错误持续存在,我尝试降级到较低版本的 pytorch、tensorflow 和 tensorboard,但没有取得太大成功。我看到类似问题的答案包括将张量板降级到 1.15,但这对我来说也不起作用。
有谁知道如何解决这个错误? 我正在使用
torch==2.2.0
和 tensorboard==2.13.0
。
我也遇到了同样的问题,请问你解决了吗?