Skip to content

Log 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

Note

Interactive visualizations are in HTML format and won't be displayed in the Images section. You can view such files in the All metadata section and add them to any custom dashboards you create.

Logging a single image#

Use the upload() method to log an image file from disk:

run = neptune.init_run()
run["train/bounding_boxes"].upload("bboxes.png")

Logging a series of images#

View a series of images in Neptune

To log a series of images, use the append() method.

run = neptune.init_run()
run["train/prediction_example"].append(image)

Passing a file path as the argument

If you supply a file path as a string, use the File constructor: append(File("path/to/file"))

Example:

from neptune.types import File

for name in misclassified_images_names:
    y_pred = ...
    y_true = ...
    run["misclassified_imgs"].append(
        File(f"{name}.png"),
        description=f"Prediction: {y_pred}\nActual: {y_true}",
    )

Each append() call appends an image to the series, so you want to use it inside a loop.

In the app, you can browse the logged files in the Images tab, or create a custom widget for the series field.

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.

Matplotlib#

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:

for epoch in range(params["iterations"]):
    plt_fig = get_histogram()
    run["train/distribution"].append(plt_fig)

See example in Neptune 

Seaborn#

To log a Seaborn figure as an image:

import seaborn as sns

# Generate figure
seaborn_fig = ...

# Log figure to run
run["seaborn_fig"] = seaborn_fig

To log a series of Seaborn figures, use append() inside a loop:

for epoch in range(params["iterations"]):
    seaborn_fig = ...  # Seaborn figure
    run["train/distribution"].append(seaborn_fig)
If using neptune <1.9.x

Seaborn figure support was added in version 1.9.0 of the Neptune client library.

On older versions, you need to access the .figure property of the Seaborn figure:

import seaborn as sns

seaborn_fig = ...  # Seaborn figure

# Convert Seaborn object to Matplotlib format (matplotlib.Figure)
figure = seaborn_fig.figure

# Log figure to run
run["seaborn_fig"].upload(figure)

To log a series of Seaborn figures, use append() inside a loop:

for epoch in range(params["iterations"]):
    seaborn_fig = ...
    figure = seaborn_fig.figure
    run["train/distribution"].append(figure)

See example in Neptune 

PIL#

To upload a PIL image from memory:

image1 = Image.open("representation-learning.jpg")
image2 = Image.open("RL-agents-1.jpg")

# Log image to run
run["representation_learning"].upload(image1)
run["reinforcement_learning"].upload(image2)

You can also log a series of PIL images:

for epoch in range(images_nr):
    pil_image = ...
    run["train/distribution"].append(pil_image)

Logging the step, epoch, or additional metadata#

You can set a custom index with the step argument:

run["train/distribution"].append(plt_histogram, step=epoch)

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)