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 what type of field the metadata is stored in and how you can interact with it.

Metadata type Example Logging method    Sample code
Single value Parameters, final scores, text = run["f1_score"] = 0.86
Single file Image, plot file, data sample upload() model_version["binaries"].upload("model.pkl")
Series of values Metrics, series of text entries log() (inside for loop) run["train/loss"].log(loss)
Series of files Image series log() (inside for loop) run["misclassified_images"].log(File("misclassified_image.png"))
Set of files Large number of files upload_files() model["preprocessing_scripts"].upload_files("./preprocessing/*.py")
Tags Text tags to annotate objects add() run.add(["RNN", "finetune"])
Artifact, externally stored file Dataset, model file track_files() model["data/val"].track_files("validation.csv")


For the full list of field types and their methods, see Field types reference.

Simple value assignment#

Single value#

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

run["max_epochs"] = 5
run["optimizer"] = "Adam"

You 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 equals 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())

Creating a series: log()#

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

for iteration in range(100):

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

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

Series of images or figures: log()#

You can also use the log() 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):

Passing a file path

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

from import File

for iteration in range(100):

Tracking artifact metadata: track_files()#

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:


Uploading files or objects: upload()#

To log a single file or object, like a sample of data or confusion matrix figure, use the upload() method:


For how to upload files from binary or text content, see also from_content() and from_stream().

Displaying arrays or tensors: upload() + as_image()#

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

from import File


Interactive HTML: as_html()#

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

from import File


Python object: as_pickle()#

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

from import File