MJimitater
MJimitater

Reputation: 939

How to run tensorboard in vscode?

Whenever I try to run tensorboard in a jupyter notebook within visual studio code with this command tensorbard --logdir=runs, I get the message Launching TensorBoard.... However, Tensorboard never launches. Sometimes I also get an error message.

Any ideas on how to launch tensorboard within vscode?

EDIT:

I also tried running slightly optimized commands

%load_ext tensorboard
%tensorboard --logdir runs

but this only shows the message Launching Tensorboard... eternally.

Same result with

%reload_ext tensorboard
%tensorboard --logdir runs --host localhost --port 8888

Is there any tensorboard extension that embeds tensorboard into a cell output?

Upvotes: 24

Views: 64327

Answers (6)

alelom
alelom

Reputation: 3008

In October 2023 the VSCode integration still didn't work for me out of the box, when attempting to use it via SSH on a remote machine with Conda. I either got a prompt for Tensorboard not installed or a timeout after 60 seconds. If I selected "Yes" when I got Tensorboard not installed, I got an installation process started, at the end of which I got the message All requested packages are already installed. I followed all the VSCode GitHub bug issues on this issue, and they all end up pointing out to this PR: github.com/microsoft/vscode-python/pull/19592 which actually didn't fix the issue for me.

tl;dr: what I did to run Tensorboard via SSH on my Ubuntu VM was:

  1. Check if you can start tensorboard manually running tensorboard --logdir= . from terminal without getting a command not found or similar error.

    1.1 If not, check if you tensorboard installation has a main.py file, as per this SO post:

    • check the location of Tensorflow: pip show tensorflow
    • cd to the location printed on screen.
    • cd tensorboard to go in the main code folder
    • ls and verify if there is a main.py file.

    1.2 If no main.py is present, probably the installation got corrupted. Make sure you don't have the deprecated tensorflow-tensorboard installed:

    • run pip uninstall tensorflow-tensorboard,
    • uninstall and reinstall tensorboard: pip uninstall tensorboard
    • reinstall: pip install tensorboard
  2. Here I got an error stating that it couldn't find GLIBCXX_3.4.29. I followed this SO answer to get it installed.

After 2, I finally could run Tensorboard, even via the VSCode integration.

Upvotes: 1

Dan
Dan

Reputation: 773

Although the answer provided by @Jeffrey is correct, it lacks an important detail. Since I am not able to edit the post from @Jeffrey, I am rewriting my answer here.

You have to select python interpreter from Command Palette -> Python Select Interpreter as mentioned here BEFORE using the 3 steps mentioned in the Jeffrey's post.

Additionally, VS Code might ask you to install tensorboard and torch-tb-profiler before third step mentioned in Jeffrey's post. You could install it by clicking on the prompt or manually.

Hence, the comprehensive steps will be as follows:

  1. Select appropriate python interpreter: Command Palette -> Python Select Interpreter
  2. Start Tensorboard: command palette -> Python: Launch TensorBoard
  3. (For first time) Install Tensorboard and torch-tb-profiler: You can do it by just clicking on vs code prompt or manually inside the select python interpreter.
  4. Folder selection: Select the folder where your TensorBoard log files are stored. By default, the current directory opened in vs code file will be used.

References:
1: https://code.visualstudio.com/docs/python/environments#_work-with-python-interpreters
2: https://pypi.org/project/tensorflow-tensorboard/

Upvotes: 8

AMI
AMI

Reputation: 61

Try the following: tensorboard --logdir=runs

Upvotes: 0

Jeffrey
Jeffrey

Reputation: 316

VS Code and the Python extension now has TensorBoard integrated in it in its latest release!

https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2021-release/

To start a TensorBoard session from VSC:

  1. Open the command palette (Ctrl/Cmd + Shift + P)
  2. Search for the command “Python: Launch TensorBoard” and press enter.
  3. You will be able to select the folder where your TensorBoard log files are located. By default, the current working directory will be used.

VSCode will then open a new tab with TensorBoard and its lifecycle will be managed by VS Code as well. This means that to kill the TensorBoard process all you have to do is close the TensorBoard tab.

Upvotes: 30

Josmar Suarez
Josmar Suarez

Reputation: 21

I had the same issue, I was able to visualize tensorboard by entering http://localhost:6006 in the browser.

Screenshot of Tensorboard

Upvotes: 2

Elona Shatri
Elona Shatri

Reputation: 101

You can use this

tensorboard --logdir=data/ --host localhost --port 8888

Upvotes: 8

Related Questions