Experiments/Visualizations

Images

Visualize your images

mlop supports logging many different image types to the platform, you can currently log images that are of the format of:

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,
)
mlop.log({"image/file/0-0": img})
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.

Supported Formats

mlop uses pillow as its backend for image logging, with the following supported formats.

Examples

Logging from PIL Images

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)})

Logging from File Paths

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

Logging from NumPy Arrays

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

Logging from Matplotlib Figures

 
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)})

This provides you with the nice visualization

line

On this page