#1205·open_clip

Documentation proposal: stress-test OpenCLIP similarity under JPEG compression and downscaling

Author: ternausCreated Aug 29, 2026Updated Sep 8, 2026

OpenCLIP users often deploy image embeddings and retrieval on inputs that have been re-encoded or resized by upload, CDN, or mobile pipelines. The current examples use clean inputs, so users do not have a compact recipe for measuring whether an image remains close to its original embedding and matched caption after these delivery artifacts.

Would you be open to a focused tutorial that uses AlbumentationsX to generate controlled JPEG-compression and resolution-loss variants, then uses a pretrained OpenCLIP model to measure the effect?

Proposed scope

The tutorial would:

  • load one pretrained OpenCLIP model and retain its returned validation preprocessing;
  • use a small fixed collection of image-caption pairs;
  • generate fixed JPEG-quality and downscale severity ladders with AlbumentationsX;
  • encode the clean and degraded images with the same model;
  • report clean-to-degraded image-embedding cosine similarity and any change in the matched caption's rank;
  • show a compact image grid alongside the measurements.

The integration boundary would remain small:

python
import cv2
import numpy as np
from PIL import Image

import albumentations as A


def apply_ax(image: Image.Image, transform: A.Compose) -> Image.Image:
    transformed = transform(
        image=np.asarray(image.convert("RGB")),
    )["image"]
    return Image.fromarray(transformed)


jpeg_40 = A.Compose(
    [
        A.ImageCompression(
            compression_type="jpeg",
            quality_range=(40, 40),
            p=1.0,
        ),
    ],
)

downscale_50 = A.Compose(
    [
        A.Downscale(
            scale_range=(0.5, 0.5),
            interpolation_pair={
                "downscale": cv2.INTER_AREA,
                "upscale": cv2.INTER_CUBIC,
            },
            p=1.0,
        ),
    ],
)

image_tensor = preprocess(apply_ax(image, jpeg_40))

AlbumentationsX would stop at the RGB image. OpenCLIP's returned preprocess callable would remain the sole source of model-specific resizing, normalization, and tensor conversion.

This would be an evaluation tutorial rather than a replacement for OpenCLIP's torchvision/timm training augmentation path or the ongoing work in #1181. It would not change --aug-cfg, WebDataset, model code, or OpenCLIP's default dependencies. Earlier #474 asked about domain-specific transforms, while discussion #1126 noted that stronger image augmentation may matter for smaller datasets; this tutorial would isolate the measurement step before introducing any training-policy recommendation.

The example would measure behavior rather than promise that a particular model or augmentation improves robustness.

Dependency note: AlbumentationsX is AGPL-3.0-only and requires Python 3.10+. Users select the appropriate PyTorch CPU, CUDA, or MPS runtime for their environment. It would remain an optional tutorial dependency.

If this scope would be useful, would you prefer a standalone notebook under tutorials/ or a section in docs/Interacting_with_open_clip.ipynb? I would be happy to prepare the contribution after confirming the preferred scope and placement.