Skip to content

Essential logging methods#

Depending on your type of metadata, there are a few different logging methods to choose from.

The method determines the resulting type of field, which affects how the metadata is stored, displayed, and interacted with.

What you're logging Neptune method    Example
Parameters, scores, any single values = run["f1_score"] = 0.86
File upload() run["binaries"].upload("model.pkl")
Metrics, text logs append() (inside a loop) run["train/loss"].append(loss)
Predictions, images (as series) append() (inside a loop) run["misclassified_images"].append(img_object)
Set of files upload_files() run["preprocessing_scripts"].upload_files("./preprocessing/*.py")
Externally stored artifacts track_files() run["data/val"].track_files("s3://data/train")

Value assignment: =#

Single value#

Text field in run metadata view

To log single-valued metadata, like a hyperparameter or evaluation metric, assign the value with an equality sign (=):

import neptune

run = neptune.init_run()

run["max_epochs"] = 5
run["activation"] = "ReLU"

You can query a single value from a Neptune object with the fetch() method:

>>> print(run["max_epochs"].fetch())

Dictionary of values#

To log metadata from a Python dictionary, like a training configuration, assign the value with an equality sign (=). Your Python dictionary will be parsed into a Neptune namespace automatically.

run["parameters"] = {
    "batch_size": 64,
    "dropout": 0.2,
    "optim": {"learning_rate": 0.001, "optimizer": "Adam"},

When fetching, the namespace structure would look like this:

>>> print(run["parameters/optim/optimizer"].fetch())

Series of values: append()#

Chart showing several graphs

Use the append() method to create a series of metrics or other values, like loss during training or text logs after every iteration. Each append() call adds a new value to the series.

run = neptune.init_run()

for iteration in range(100):

To append a collection of values at once, you can use the extend() method.

You query entries from a series of values with the fetch_last() method:

>>> run["train/loss"].fetch_last()

Series of images#

View a series of images in Neptune

You can also use the append() method to log a series of figures, like image predictions after every epoch.

You can pass PIL, Matplotlib, or Seaborn figure objects as the argument:

for iteration in range(100):
    pil_image = ...
Passing a file path as the argument

If you supply a file path, use the File constructor:

from neptune.types import File

for i in range(100):

Artifact version tracking: track_files()#

Artifact metadata in Neptune

To track and version a dataset, model, or any other artifact stored in a file, folder, or S3-compatible storage, use the track_files() method:

run = neptune.init_run()

This only stores metadata about the artifacts on Neptune servers, not the artifacts themselves.


Track artifacts

File upload: = or upload()#

Matplotlib figures

To log a single file or object, like a sample of data or confusion matrix figure, simply assign the object to a field name of your choice.

import matplotlib.pyplot as plt

run = neptune.init_run()
fig = plt.figure(figsize=(7, 9))

# Log figure to run
run["my-figure"] = fig

When passing a file path as the argument, use the upload() method:



Set of files: upload_files()#

Preview of set of images in Neptune app

If you don't need advanced display options for individual files, you can upload a set of files to a single field with the upload_files() method.


Arrays and tensors: as_image()#

Display your arrays or tensors as a series of images with the as_image() method:

from neptune.types import File


Interactive HTML: as_html()#

Plotly figure in Neptune

You can convert, for example, dataframe objects to interactive HTML with the as_html() method:

from neptune.types import File


By default, Neptune logs Matplotlib figures as static images. You can use as_html() to log the figure as an interactive visualization instead:

from neptune.types import File

fig = ...

Python object: as_pickle()#

Log Python objects as pickles with the as_pickle() method:

from neptune.types import File