SAGEA LogoDocs & API
CookbooksCursus Cookbooks

Log Images During Training

Log images alongside scalar metrics to visually inspect model predictions during training.

  • Log images from file paths, raw bytes, PIL Images, or numpy arrays
  • Images appear on the run's Charts tab with a step scrubber
  • Re-logging the same (key, step) overwrites the previous image

Time to complete: ~5 minutes

Prerequisites

  • pip install sagea-cursus
  • CURSUS_API_KEY and CURSUS_BASE_URL set in your environment
  • (Optional) pip install Pillow for PIL/numpy image support

Step 1: Log images from file paths

# log_images.py
import sagea_cursus as cursus
 
run = cursus.init(
    project="image-experiment",
    config={"lr": 1e-3, "epochs": 10},
    name="visual-check",
)
 
try:
    for step in range(10):
        loss = 1.0 / (step + 1)
        cursus.log({"train/loss": loss}, step=step)
 
        # log a saved prediction image
        cursus.log_image(
            "val/predictions",
            f"preds_step_{step:03d}.png",
            step=step,
        )
 
    cursus.finish()
except Exception:
    cursus.finish("crashed")
    raise

Step 2: Log from bytes or numpy

You can also pass raw bytes, PIL Images, or numpy arrays:

# raw bytes (PNG/JPEG/WEBP — sniffed by magic bytes)
cursus.log_image("val/predictions", open("pred.png", "rb").read(), step=step)
 
# PIL Image
from PIL import Image
cursus.log_image("val/predictions", Image.open("pred.png"), step=step)
 
# numpy array (needs Pillow installed)
import numpy as np
cursus.log_image("val/predictions", np.zeros((64, 64, 3), "uint8"), step=step)

Step 3: View on the dashboard

Open the run's Charts tab. Each image key gets its own chart with a step scrubber — slide through steps to see predictions evolve over training.

Limits: 5 MB per image, 500 images per run. Re-logging the same (key, step) overwrites the previous bytes.

What's next

On this page