Skip to content

Open in Colab

Quickstart#

Viewing metadata in a Neptune dashboard

This quickstart guide shows how to install Neptune and use some basic logging functions. We use mocked metrics, the MNIST dataset, and a sample image.

We recommend using your own Neptune project and API token, but you can also run the quickstart without registering.

Create a project#

  1. Sign up for a Neptune account: neptune.ai/register
  2. In your Neptune workspace, navigate to All projects New project.

    For help, see Create a project.

Install Neptune#

pip install neptune
conda install -c conda-forge neptune
Installing through Anaconda Navigator

To find neptune, you may need to update your channels and index.

  1. In the Navigator, select Environments.
  2. In the package view, click Channels.
  3. Click Add..., enter conda-forge, and click Update channels.
  4. In the package view, click Update index... and wait until the update is complete. This can take several minutes.
  5. You should now be able to search for neptune.

Note: The displayed version may be outdated. The latest version of the package will be installed.

Note: On Bioconda, there is a "neptune" package available which is not the neptune.ai client library. Make sure to specify the "conda-forge" channel when installing neptune.ai.

Prepare the sample data#

To access the MNIST dataset, install TensorFlow:

pip install tensorflow

To have a file to upload to Neptune, download the sample image:

curl -O https://neptune.ai/wp-content/uploads/2023/06/Lenna_test_image.png

Create a run#

  1. Create a script called hello_neptune.py.
  2. Copy and paste the below code into the script file:
hello_neptune.py
import neptune

# Create a Neptune run
run = neptune.init_run(
    project="your-workspace-name/your-project-name", # (1)!
    api_token="YourNeptuneApiToken", # (2)!
    name="sincere-oxpecker", # (3)!
    tags=["quickstart", "script"], # (4)!
    dependencies="infer", # (5)!
)

# Log a single value
# Specify a field name ("seed") inside the run and assign a value to it
run["seed"] = 0.42

# Log a series of values
from random import random

epochs = 10
offset = random() / 5

for epoch in range(epochs):
    acc = 1 - 2**-epoch - random() / (epoch + 1) - offset
    loss = 2**-epoch + random() / (epoch + 1) + offset

    run["accuracy"].append(acc)
    run["loss"].append(loss)

# Upload an image
run["single_image"].upload("Lenna_test_image.png")

# Load the MNIST dataset
from tensorflow.keras.datasets import mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

# Upload a series of images
from neptune.types import File

for i in range(10):
    run["image_series"].append(
        File.as_image(
            x_train[i]
        ),  # You can upload arrays as images using Neptune's File.as_image() method
        name=f"{y_train[i]}",
    )

# Stop the connection and synchronize the data with the Neptune servers
run.stop()
  1. The full project name. For example, "ml-team/classification".

    To find the required string in the Neptune app, click How to create a new run. You can copy the project argument from the modal that opens.

  2. In the bottom-left corner of the Neptune app, expand the user menu and select Get your API token.

    When you're done testing, save your API token as an environment variable instead of putting it here in the code!

  3. Sets a custom name, which you can use as a human-friendly ID.

    To display it in the app, add sys/name as a column.

    You can also edit the name in the run information view ( menu → Show run information).

  4. Tags help organize and compare runs. You can also manage tags in the Neptune web app.

  5. You can also pass the path to your dependencies file or omit this parameter.

hello_neptune.py
import neptune

# Create a Neptune run
run = neptune.init_run(
    project="common/quickstarts", # (1)!
    api_token=neptune.ANONYMOUS_API_TOKEN, # (2)!
    name="sincere-oxpecker", # (3)!
    tags=["quickstart", "script"], # (4)!
    dependencies="infer", # (5)!
)

# Log a single value
# Specify a field name ("seed") inside the run and assign a value to it
run["seed"] = 0.42

# Log a series of values
from random import random

epochs = 10
offset = random() / 5

for epoch in range(epochs):
    acc = 1 - 2**-epoch - random() / (epoch + 1) - offset
    loss = 2**-epoch + random() / (epoch + 1) + offset

    run["accuracy"].append(acc)
    run["loss"].append(loss)

# Upload an image
run["single_image"].upload("Lenna_test_image.png")

# Load the MNIST dataset
from tensorflow.keras.datasets import mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

# Upload a series of images
from neptune.types import File

for i in range(10):
    run["image_series"].append(
        File.as_image(
            x_train[i]
        ),  # You can upload arrays as images using Neptune's File.as_image() method
        name=f"{y_train[i]}",
    )

# Stop the connection and synchronize the data with the Neptune servers
run.stop()
  1. Projects in the common workspace are public and can be used for testing.

    To log to your own workspace, pass the full name of your Neptune project: workspace-name/project-name. For example, project="ml-team/classification".

    You can copy the name from the project details. Click the menu in the top-right corner and select Edit project details.

  2. The api_token argument is included to enable anonymous logging.

    Once you register, you should leave the token out of your script and instead save it as an environment variable.

  3. Sets a custom name, which you can use as a human-friendly ID.

    To display it in the app, add sys/name as a column.

    You can also edit the name in the run information view ( menu → Show run information).

  4. Tags help organize and compare runs. You can also manage tags in the Neptune web app.

  5. You can also pass the path to your dependencies file or omit this parameter.

Now that you have your Hello Neptune script ready, execute it from your terminal, Jupyter Lab, or other environments:

python hello_neptune.py

Click the link in the console output to open the run in Neptune.

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( # (1)!
    api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8",  # your token here
    project="ml-team/classification",  # your full project name here
)
  1. Also works for init_model(), init_model_version(), init_project(), and integrations that create Neptune runs underneath the hood, such as NeptuneLogger or NeptuneCallback.

  2. API token: In the bottom-left corner, expand the user menu and select Get my API token.

  3. Project name: You can copy the path from the project details ( Edit project details).

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!

Explore the results#

In the Run details view, you can browse your data in the following tabs:

  • All metadata – all of the logged metadata, in a folder-like structure.

    Show example

    Viewing all metadata of a run in the Neptune web app

  • Charts – metrics visualized as graphs.

  • Images – previews and interactive galleries.
  • Monitoring – hardware consumption during the run execution.
  • Source code – code snapshots, Git information, and dependencies.

Browse example runs in Neptune  See code on GitHub 

Next steps#

  • Rerun the script with different values to track a few more runs, then select the Compare runs tab to compare and visualize them.
  • Before moving on, take a moment to save your API token as an environment variable. This helps keep your API token secure, as you can omit the api_token parameter from your code.
  • To get the most out of Neptune, take the Neptune tutorial. It walks you through all of the above plus the central Neptune features.