Images

Visualize your images

mlop supports logging many different image types to the platform, you can current log imagees that are of the format of

  • NumPy arrays
  • PILLOW images
  • PyTorch tensors
  • Matplotlib plots or figures

To use image logging you first need to instantiate the mlop.Image class

img = mlop.Image(
    data: Union[str, PILImage.Image, matplotlib.figure.Figure, torch.Tensor, np.ndarray],
    caption: str | None = None,
)

ParameterTypeDescription
dataUnion[str, PILImage.Image, matplotlib.figure.Figure, torch.Tensor, np.ndarray]The image data to log. Can be a path to an image file, a PIL image, a Matplotlib figure, a PyTorch tensor, or a NumPy array.
captionstrA caption for the image.

Then log the image as standard

mlop.log({"image/file/0-0": img})

This provides you with the visualization as such

line

:::tip mlop uses PILLOW as its backend for image logging, with the following supported formats. :::

Examples

Create a PIL image

from PIL import Image
 
img = Image.new("RGB", (100, 100), color = (255,255,255))
filename = "pil_image.png"
img.save(filename)
 
mlop.log({"img": mlop.Image(img)})

File Path

path = "pil_image.png"
mlop.log({"img": mlop.Image(path)})

NumPy Array

data = np.random.randint(low=0, high=256, size=(100, 100, 3))
mlop.log({"image": mlop.Image(data)})

Matplotlib

 
noise = np.random.rand(*size)
x = np.linspace(0, 1, size[1])
y = np.linspace(0, 1, size[0])
X, Y = np.meshgrid(x, y)
gradient = X + Y
image = (noise + gradient) / 2
fig, ax = plt.subplots(figsize=(1, 1), dpi=100)
ax.imshow(image, cmap="viridis")
ax.axis("off")
 
mlop.log({"image": mlop.Image(fig)})

On this page