Skip to content

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 single image#

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

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

Logging series of images#

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

If you supply a path to a file, use a File constructor.

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

from neptune.new.types import File

for name in misclassified_images_names:
    y_pred = ...
    y_true = ...
    run["misclassified_imgs"].log(File("misclassified_image.png"))

In the app, you can display and navigate the logged images in a gallery view.

Viewing a series of images in Neptune

Logging Matplotlib, Seaborn, and PIL figures#

You can log Matplotlib, Seaborn, and PIL images 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 log() inside a loop:

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

See example in Neptune ≫

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 log() inside a loop:

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

See example in Neptune ≫

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 = Image.open("path_to_image")
    run["train/distribution"].log(pil_image)

See example in Neptune ≫