I tried to use Tensorboard with Pytorch, installed it, wrote the code and executed it, and I encountered an error, so I will write a workaround for it.
Since I am using anaconda, I installed it with the following command.
conda install tensorboard
Import to draw a graph in SummaryWriter.
tensorboard.py
from torch.utils.tensorboard import SummaryWriter
I got the following Import Error.
ImportError: cannot import name 'SummaryWriter' from 'torch.utils.tensorboard'
During handling of the above exception, another exception occurred:
ImportError: TensorBoard logging requires TensorBoard with Python summary writer installed. This should be available in 1.14 or above.
I wondered if I couldn't install it properly, so I uninstalled it and installed it again. I got the same error. I got lost here and installed it with pip. (The confusion between pip and conda is not very good) In the end, I got the same error.
Since Tensorboard can be officially used from v1.2.0 on Pytorch, I checked the version of Pytorch for the time being.
python
import torch
print(torch.__version__)
It was *** 1.5.1 ***. It doesn't seem to be a Pytorch issue.
The error statement says that the Tensorboard version is 1.14 or higher, so check it.
conda list
It was *** 2.2.1 ***. It doesn't seem to be a Tensorboard issue either.
I checked the versions of Pytorch and Tensorboard and it was okay so I don't have to do it anymore. I don't know what is causing the error.
Looking at the file name, it says *** tensorboard.py ***. Is it because the file name and module collide and cannot be imported? I thought.
Renamed the file to *** tb.py ***. And when I ran it, I didn't get an error! !! !! !!
I tried to use Tensorboard with Pytorch and installed it, but I got an ImportError with the same file name as module. Keep the file name and module separate. Also, avoid confusing conda with pip.
Recommended Posts