[PYTHON] I got an error when using Tensorboard with Pytorch

Introduction

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.

Install Tensorboard

Since I am using anaconda, I installed it with the following command.

conda install tensorboard

code

Import to draw a graph in SummaryWriter.

tensorboard.py


from torch.utils.tensorboard import SummaryWriter

error

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.

approach

For the time being, uninstall and reinstall

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.

Pytorch version check

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.

Check the version of Tensorboard

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.

File name change

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! !! !! !!

Summary

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

I got an error when using Tensorboard with Pytorch
I got an error when saving with OpenCV
I got a Value Error when using JUMAN ++ with PyKNP
When I get an error with PyInstaller
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
I got an error when pip install pandas on Mac, so I dealt with it
I get an error with import pandas.
I got an error when pip install tweepy on macOS Sierra, so I dealt with it
What I got into when using Tensorflow-gpu
I got an error when I ran composer global require laravel / installer
When I get an error with Pylint in Atom on Windows
I get an error when trying to install maec 4.0.1.0 with pip
I got an error when I ran meteor add accounts-password and got hooked
I got an error when trying to install Xgboost and its solution
I got an SSL related error with pip install, so I solved it
I get an error with all yum commands
I got an error when trying to run Hello World in Go language
Linux Ubuntu16.04 I got a little scary error when I ran a command using sudo
I got an error that Python couldn't read settings.ini
I get an error when I put opencv in pyautoGUI
A memorandum when an error occurs with pip install
Investigate the cause when an error is thrown when python3.8 is not found when using lambda-uploader with python3.8
I get an error when I try to raise Python to 3 series using pyenv on Catalina
When using optparse with iPython
Try an autoencoder with Pytorch
Error when playing with python
I made Word2Vec with Pytorch
Small speedup when using pytorch
When I made CaboCha usable with python3, I got stuck (Windows 10)
What to do when an error occurs with import _ssl
When I installed python on macOS and used it, I got an error when I put an https connection
[Solution] When I try to connect to CloudSQL with GAE, I get an ImportError only when using dev_appserver.
I got an error when I tried to process luigi in parallel on windows, but the solution
When coverage fails with _sqlite3 error
I got a TypeError:'int' object is not iterable when using keras
I got an AttributeError when mocking the open method in python
# Solution when pip install gives an error when using Anaconda on Windows 10
[Beanstalk] What to do when an error occurs with import uuid
I got an SSL Error when I installed Anaconda in a new environment, so I solved it (Windows10, Anaconda3-2019.10)
I implemented Attention Seq2Seq with PyTorch
I sent an SMS with Python
[Python] Error and solution memo when using venv with pyenv + anaconda
I tried implementing DeepPose with PyTorch
I want to improve efficiency with Python even in an experimental system (4) Use ser.close () when an error is thrown using try syntax
Unable to bind to interface error when using apollo federation with gqlgen
[Django] Error when using Q object (Related Field got invalid lookup)
When you want to send an object with requests using flask
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
Solution when an error occurs when hiding the console screen with PyInstaller
How to deal with OAuth2 error when using Google APIs from Python
What to do if an error occurs when importing numpy with VScode
I got an unfamiliar error in Django: TypeError: resolve () got an unexpected keyword argument'strict'
A reminder of what I got stuck when starting Atcoder with python
TypeError: concat () got an unexpected keyword argument'join_axes' when using pandas_profling (Google Colab)
[AWS] How to deal with WordPress "An error occurred when cropping an image."
I tried sending an SMS with Twilio
I tried using Amazon SQS with django-celery
I implemented Shake-Shake Regularization (ShakeNet) with PyTorch
Note when creating an environment with python
I tried using Selenium with Headless chrome