TensorBoard integration guide#
With the Neptune-TensorBoard integration, you can track metrics and log metadata to both TensorBoard and Neptune at the same time. You can also use the CLI utility to export existing TensorBoard logs to Neptune.
See example in Neptune  Code examples 
Before you start#
- Sign up at neptune.ai/register.
- Create a project for storing your metadata.
- Have TensorFlow installed.
Installing the integration#
To use your preinstalled version of Neptune together with the integration:
To install both Neptune and the integration:
How do I save my credentials as environment variables?
Set your Neptune API token and full project name to the NEPTUNE_API_TOKEN
and NEPTUNE_PROJECT
environment variables, respectively.
You can also navigate to Settings → Edit the system environment variables and add the variables there.
To find your credentials:
- API token: In the bottom-left corner of the Neptune app, expand your user menu and select Get your API token. If you need the token of a service account, go to the workspace or project settings and enter the Service accounts settings.
- Project name: Your full project name has the form
workspace-name/project-name
. You can copy it from the project menu ( → Details & privacy).
If you're working in Google Colab, you can set your credentials with the os and getpass libraries:
If you'd rather follow the guide without any setup, you can run the example in Colab .
Basic logging example#
In this guide, we'll show you how to use the enable_tensorboard_logging()
function to log metadata to both TensorBoard and Neptune at the same time.
-
Create a Neptune run:
-
If you haven't set up your credentials, you can log anonymously:
For more run customization options, see
neptune.init_run()
. -
-
Import the logging function:
-
Call the integration function, passing the Neptune run object as the argument.
This will log the metadata to both the
tensorboard
directory and the Neptune run.Tip
The function also works with:
SummaryWriter
from PyTorch and tensorboardXTensorBoard
callback for Keras
-
Proceed with your model training script. For a full example, see the TensorBoard code samples on GitHub .
-
To stop the connection to Neptune and sync all data, call the
stop()
method: -
Run your script as you normally would.
To open the run, click the Neptune link that appears in the console output.
Sample output
[neptune] [info ] Neptune initialized. Open in the app:
https://app.neptune.ai/workspace/project/e/RUN-1
If Neptune can't find your project name or API token
As a best practice, you should save your Neptune API token and project name as environment variables:
Alternatively, you can pass the information when using a function that takes
api_token
andproject
as arguments:run = neptune.init_run( api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)! project="ml-team/classification", # (2)! )
- In the bottom-left corner, expand the user menu and select Get my API token.
- You can copy the path from the project details ( → Details & privacy).
If you haven't registered, you can log anonymously to a public project:
Make sure not to publish sensitive data through your code!
Analyzing the results#
You'll find the logged metadata in All metadata → tensorboard.
You can also see the metadata visualized in the other tabs, as well as create custom dashboards. See the Neptune example for inspiration.
Exporting TensorBoard logs to Neptune#
You can export TensorBoard logs from the logs
directory to Neptune with the neptune tensorboard
CLI command:
If you haven't set your credentials as environment variables, you can also pass them as arguments:
How do I save my credentials as environment variables?
Set your Neptune API token and full project name to the NEPTUNE_API_TOKEN
and NEPTUNE_PROJECT
environment variables, respectively.
You can also navigate to Settings → Edit the system environment variables and add the variables there.
To find your credentials:
- API token: In the bottom-left corner of the Neptune app, expand your user menu and select Get your API token. If you need the token of a service account, go to the workspace or project settings and enter the Service accounts settings.
- Project name: Your full project name has the form
workspace-name/project-name
. You can copy it from the project menu ( → Details & privacy).
If you're working in Google Colab, you can set your credentials with the os and getpass libraries:
neptune-notebooks incompatibility
The command doesn't work together with the Neptune-Jupyter extension (neptune-notebooks).
To use the command, you must uninstall neptune-notebooks first.
Related
- What you can log and display
- Neptune-TensorBoard API reference
- neptune-tensorboard repo on GitHub
- TensorBoard repo on GitHub