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.
run["metrics/acc"].append(0.98) # "metrics/acc" is a FloatSeries field
run["metrics/acc"].append(0.99) # You can keep appending float values
run["metrics/acc"] = "High accuracy!" # Error: You can't suddenly assign a string
acc = run["metrics/acc"].fetch_values() # Series fields support fetching all values
acc = run["metrics/acc"].fetch_last() # ... or just the last value
run["metrics/acc"].download() # Error: download() is for file fields
The below table outlines which method to use, depending on the type of metadata you're logging:
What you're logging | Neptune method | Example |
---|---|---|
Parameters, scores, any single values | = or assign() |
run["f1_score"] = 0.86 |
Metrics, text logs | append() |
(inside a loop) run["train/loss"].append(loss) |
Predictions, sequence of images | append() |
(inside a loop) run["misclassified_images"].append(img_object) |
Externally stored artifacts | track_files() |
run["data/val"].track_files("s3://data/train") |
Set of files | upload_files() |
run["preprocessing_scripts"].upload_files("./preprocessing/*.py") |
File | upload() |
run["binaries"].upload("model.pkl") |
Value assignment: =
#
Single value#
To log single-valued metadata, like a hyperparameter or evaluation metric, assign the value with an equality sign (=
):
You can query a single value from a Neptune object with the fetch()
method:
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:
Series of values: append()
#
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):
run["train/loss"].append(loss)
run["logs"].append(iteration_config)
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:
Related
Series of images#
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:
Passing a file path as the argument
If you supply a file path, use the File
constructor:
Related
Artifact version tracking: 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:
This only stores metadata about the artifacts on Neptune servers, not the artifacts themselves.
Related
File upload: =
or upload()
#
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:
Related
- For how to upload files from binary or text content, see also
from_content()
andfrom_stream()
. - Upload files
Set of files: upload_files()
#
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:
Related
Interactive HTML: as_html()
#
You can convert, for example, dataframe objects to interactive HTML with the as_html()
method:
By default, Neptune logs Matplotlib figures as static images. You can use as_html()
to log the figure as an interactive visualization instead:
Python object: as_pickle()
#
Log Python objects as pickles with the as_pickle()
method: