Skip to content

API reference: TensorBoard integration#

The Neptune-TensorBoard integration has the following components:

  • The enable_tensorboard_logging() function, for logging metadata to TensorBoard and Neptune simultaneously.
  • The neptune tensorboard CLI command, for exporting existing TensorBoard logs to Neptune.

enable_tensorboard_logging()#

Logs the tracked metadata to both the tensorboard directory and the Neptune run.

Parameters

Name      Type Default     Description
run Run - (required) An existing run reference, as returned by neptune.init_run().
base_namespace str, optional "tensorboard" Namespace under which all metadata logged by the integration will be stored.

Examples

import neptune
from neptune_tensorboard import enable_tensorboard_logging

run = neptune.init_run()
enable_tensorboard_logging(run)
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:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

Alternatively, you can pass the information when using a function that takes api_token and project as arguments:

run = neptune.init_run(
    api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)!
    project="ml-team/classification", # (2)!
)
  1. In the bottom-left corner, expand the user menu and select Get my API token.
  2. You can copy the path from the project details ( Details & privacy).

If you haven't registered, you can log anonymously to a public project:

api_token=neptune.ANONYMOUS_API_TOKEN
project="common/quickstarts"

Make sure not to publish sensitive data through your code!

You can also customize the Neptune run with more options at initialization:

run = neptune.init_run(
    name="My TensorBoard run",
    tags=["test", "tensorboard", "fail_on_exception"],
    dependencies="infer",
    fail_on_exception=True,
)

For more, see neptune.init_run().


neptune tensorboard#

Exports TensorBoard logs from the logs directory to Neptune.

Where to enter the command
  • Linux: Command line
  • macOS: Terminal app
  • Windows: PowerShell or Command Prompt
  • Jupyter Notebook: In a cell, prefixed with an exclamation mark: ! your-command-here

Command syntax: neptune tensorboard [--api_token] [--project] logs

Options    Description
--api_token Neptune API token. Copy it from your user menu in the bottom-left corner of the Neptune app.
--project Neptune project name. You can copy it from the project settings: Details & privacy.

Examples

If you've set your Neptune credentials as environment variables, you can use the following command:

neptune tensorboard logs
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.

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
setx NEPTUNE_API_TOKEN "h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
setx NEPTUNE_PROJECT "ml-team/classification"

You can also navigate to SettingsEdit the system environment variables and add the variables there.

%env NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
%env NEPTUNE_PROJECT="ml-team/classification"

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:

import os
from getpass import getpass
os.environ["NEPTUNE_API_TOKEN"] = getpass("Enter your Neptune API token: ")
os.environ["NEPTUNE_PROJECT"] = "workspace-name/project-name"

Otherwise, you can pass the credentials as options:

neptune tensorboard --api_token I2YzgMz1...MifQ== --project ml-team/llm-project logs

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.


See also

neptune-tensorboard repo on GitHub