Neptune-TensorBoard Integration

Note

Neptune integrates with both TensorFlow / Keras directly and via TensorBoard. If you are already using TensorBoard you may want to see the TensorFlow / Keras integration page

What will you get with this integration?

TensorBoard is a visualization toolkit for TensorFlow. neptune-tensorboard is an open source project curated by the Neptune team that integrates TensorBoard with Neptune to let you enjoy the best of both worlds.

Neptune supports two major use cases:

  1. With neptune tensorboard /path/to/tensorboard/logs bash command you can have your TensorBoard visualizations hosted in Neptune. See Convert TensorBoard logs to Neptune experiments.

  2. You can use the integrate_with_tensorflow() method to instantly log major metrics (epoch and batch related) to Neptune. See Log new runs to Neptune via TensorBoard

Neptune currently logs and displays the following TensorBoard objects:

  • Scalars (as metrics)

  • Images (as images)

  • String Tensors (as text)

  • path to the TensorBoard run (as property ‘tf/run/path’)

You can also extend what you are currently logging via TensorBoard to objects like model checkpoints, interactive charts, video and more. To learn about that see the More options section.

Note

This integration is tested with tensorflow==2.3.1, tensorboard==2.4.0, neptune-client==0.4.132, and neptune-tensorboard==0.5.1.

Where to start?

If you have already tracked some experiments with TensorBoard and you want to convert the TensorBoard logs directory into Neptune experiments see the Convert TensorBoard logs to Neptune experiments section.

If you want to log new experiments to Neptune via TensorBoard you should read the Log new runs to Neptune via TensorBoard section.

To extend what you are already logging to TensorBoard with native Neptune logging read More options section.

If you want to try things out and focus only on the code you can either:

Convert TensorBoard logs to Neptune experiments

Before you start

  1. Ensure that you have Python 3.x and following libraries installed:

    • neptune-tensorboard

    • tensorboard.

pip install tensorboard==2.4.0 neptune-tensorboard==0.5.1
  1. You also need minimal familiarity with TensorBoard. Have a look at the TensorBoard get started guide.

Step 1: Set your NEPTUNE_API_TOKEN

Linux/iOS:

export NEPTUNE_API_TOKEN='YOUR_API_TOKEN'

Windows:

set NEPTUNE_API_TOKEN="YOUR_API_TOKEN"

Tip

Read more about how to securely set the Neptune API token.

Step 2: Convert your TensorBoard logs directory with Neptune

Navigate to your TensorBoard logs directory and run:

neptune tensorboard --project USER_NAME/PROJECT_NAME

Alternatively, you can point Neptune to your TensorBoard logs directory:

neptune tensorboard /PATH/TO/TensorBoard_logdir --project USER_NAME/PROJECT_NAME

Tip

You can also set the project qualified name in the NEPTUNE_PROJECT environment variable and skip the --project argument

Linux/macOS:

export NEPTUNE_PROJECT='USER_NAME/PROJECT_NAME'

Windows:

set NEPTUNE_PROJECT="USER_NAME/PROJECT_NAME"

Browse and collaborate on your TensorBoard runs in Neptune

You can now click on one of the links from the console and go to Neptune to see your experiments.

Dashboard

Organize TensorBoard experiments in Neptune

Comparison

Compare TensorBoard experiments in Neptune

Remember that you can try it out with zero setup:

Log new runs to Neptune via TensorBoard

Before you start

  1. Ensure that you have Python 3.x and following libraries installed:

pip install tensorflow==2.3.1 tensorboard==2.4.0 neptune-tensorboard==0.5.1
  1. You also need minimal familiarity with TensorBoard. Have a look at the TensorBoard get started guide to get started.

Step 1: Initialize Neptune

Add the following snippet at the top of your script.

import neptune

neptune.init(api_token='ANONYMOUS', project_qualified_name='shared/tensorboard-integration')

Tip

You can also use your personal API token. Read more about how to securely set the Neptune API token.

Step 2: Create an experiment

Run the code below to create a Neptune experiment:

neptune.create_experiment('tensorboard-logging')

This also creates a link to the experiment. Open the link in a new tab. The charts will currently be empty, but keep the window open. You will be able to see live metrics once logging starts.

When you create an experiment Neptune will look for the .git directory in your project and get the last commit information saved.

Note

If you are using .py scripts for training Neptune will also log your training script automatically.

Step 3: Add neptune_tensorboard.integrate_with_tensorflow() to your script

Import and add integrate_with_tensorflow() function from the neptune-tensorboard package at the top of your script.

import neptune_tensorboard
neptune_tensorboard.integrate_with_tensorflow()

Step 4: Run your training script

Run your script as you normally would:

python train.py

Step 5: Monitor your TensorBoard training in Neptune

Now you can switch to the Neptune tab which you had opened previously to watch the training live!

Charts

TensorBoard learning curve charts

Charts

TensorBoard learning curve charts

Code

TensorBoard code saved

More options

You can log many other experiment metadata like interactive charts, video, audio and more. See the full list of objects you can log and display in Neptune.

Two common use cases, logging model checkpoints and interactive charts to Neptune are show below.

Log model weights to Neptune

You can log model weights to Neptune both during and after training.

To do that just use a log_artifact() method on the saved model file.

model.save('my_model')

# log model
neptune.log_artifact('my_model')
TensorBoard checkpoints logging

Log interactive charts

You can log interactive charts to Neptune.

For example, let’s log an interactive ROC AUC curve.

  1. Install dependencies including neptune-contrib library

pip install neptune-contrib scikit-plot matplotlib==3.2.0 plotly==4.12.0

Warning

Automatic conversion between matplotlib figures and plotly charts works only with matplotlib==3.2.0 and plotly==4.12.0.

  1. Create a ROC AUC curve

import matplotlib.pyplot as plt
from scikitplot.metrics import plot_roc

y_test_pred = model.predict(x_test)

fig, ax = plt.subplots()
plot_roc(y_test, y_test_pred, ax=ax)
  1. Log it to Neptune via log_chart() function.

from neptunecontrib.api import log_chart

log_chart(name='ROC curve', chart=fig)
TensorBoard logging interactive html charts

Remember that you can try it out with zero setup:

How to ask for help?

Please visit the Getting help page. Everything regarding support is there.