Logging images#
You can log either a single image or a series of images.
Supported data formats include:
- Image file formats, such as PNG, JPEG, JPG, GIF, BMP and WebP
- Matplotlib, Seaborn, and PIL figures
- NumPy arrays
- TensorFlow and PyTorch tensors
Logging a single image#
Use the upload()
method to log an image file from disk:
Logging a series of images#
append()
replaces log()
As of neptune-client 0.16.14
, append()
and extend()
are the preferred methods for logging series of values.
You can upgrade your installation with pip install -U neptune-client
or continue using log()
.
To log a series of images, use the append()
method.
Each append()
call appends an image to the series, so you want to use it inside a loop.
In the app, you can display and navigate the logged images in a gallery view.
Related
Passing a path to an image file#
If you supply a file path as a string, use the File
constructor.
from neptune.types import File
for name in misclassified_images_names:
y_pred = ...
y_true = ...
run["misclassified_imgs"].append(
File(f"{name}.png"),
desc=f"Prediction: {y_pred}\nActual: {y_true}",
)
Logging Matplotlib, Seaborn, and PIL figures#
You can log Matplotlib, Seaborn, and PIL figures as regular images.
When you log a figure object directly (instead of a path to a file), you don't need the File
constructor.
To upload a Matplotlib figure (matplotlib.figure.Figure
) as an image:
# Import matplotlib
import matplotlib.pyplot as plt
# Generate figure
fig = plt.figure(figsize=(7, 9))
...
# Log figure to run
run["matplotlib-fig"].upload(fig)
To log a series of Matplotlib images, use append()
inside a loop:
To upload a Searborn figure, access its .figure
property:
# Import Seaborn
import seaborn as sns
# Generate chart
seaborn_fig = ...
# Convert Seaborn object to Matplotlib format (matplotlib.Figure)
figure = seaborn_fig.figure
# Log figure to run
run["seaborn-img"].upload(figure)
To log a series of Seaborn figures, use append()
inside a loop:
Logging the step, epoch or additional metadata#
You can set a custom index with the step
argument:
You can also log a name and description for the image:
# Log data sample
for plt_image, class_name in data_sample:
run["data/sample"].append(plt_image, name=class_name)
# Log predictions with class probabilities
for image, y_pred in zip(x_test_sample, y_test_sample_pred):
description = "\n".join(
[f"class {i}: {pred}" for i, pred in enumerate(y_pred)]
)
run["train/predictions"].append(image, description=description)