Skip to content

Image–text models on video frames: CLIP4Clip and X-CLIP

An image–text model on sampled frames, with embeddings pooled, is a hard baseline for video search (CLIP4Clip). X-CLIP lets frames talk and adapts prompts to each video. Pooling forgets order.

Advanced ~13 min9 steps

What runs in CodeSplash

You will be able to

  • Build a video embedding from frame embeddings and say what mean pooling loses
  • Explain cross-frame communication and video-conditioned prompts in X-CLIP
  • Keep a zero-shot protocol free of label-specific fitting
  • Try the frame-level idea in CodeSplash on frames saved as images

Read first

01

Frames through CLIP

Read

CLIPCLIPA pair of networks trained on web image–caption pairs so that an image and a text about it land close together in one vector space. already maps images and text into one space. The simplest video model: sample some frames, embed each with CLIP's image tower, combine them into one video vector, and compare with a text query by cosine similarityCosine similarityThe cosine of the angle between two vectors: 1 for the same direction, 0 for unrelated, −1 for opposite.:

v=norm(T({fCLIP(xt)}t)),s(v,q)=v⊤norm(gCLIP(q)).v = \mathrm{norm}\big(T(\{f_{\text{CLIP}}(x_t)\}_t)\big), \qquad s(v, q) = v^\top \mathrm{norm}\big(g_{\text{CLIP}}(q)\big).

How TT combines frames is the main design choice.

02

CLIP4Clip: pool, or learn to combine

Read
Reference · VID044 · Needs a data type CodeSplash doesn't load yetCLIP4ClipAdapts pretrained CLIP image-text representations to video retrieval by comparing temporal aggregation and similarity strategies.

CLIP4Clip compares ways to combine frames: plain averaging, temporal poolingTemporal pooling of frame embeddingsAverage the embeddings of a video's frames into one vector. Simple and strong, but it forgets frame order., a small sequence model over the frame embeddings, or a cross-attention module between text and frames. Averaging is a strong baseline, but it ignores order.

The reference's toy shows it: three frame embeddings averaged forward and backward give the same vector, and its similarity with a text query is 0.707 either way.

03

Opening or closing?

Predict

Predict first

You search "a door opening" over two clips: one of a door opening, the same clip reversed (closing). The system averages CLIP frame embeddings. Which scores higher?

The opening clip scores higherBoth score the same with mean poolingThe closing clip scores higher
Reveal

Both score the same. Averaging forgets order, so a clip and its reverse pool to the same vector. High retrieval scores can come from scene and object overlap without any understanding of events. Order-reversal and hard-caption tests expose this.

04

X-CLIP: frames talk, prompts adapt

Read
Reference · VID045 · Explained hereX-CLIPExpands language-image pretraining for video recognition through cross-frame communication and video-conditioned language prompting.

X-CLIP adds two things for video recognition. Cross-frame attention lets frames exchange information before pooling, so the video embedding can carry temporal evidence. And class prompts are adjusted using the video itself, so "a video of {running}" is nudged toward what this clip looks like before comparison.

In the reference's toy, a small video-dependent shift to two class-text vectors gives similarities 0.796 and 0.137. Prompts tuned to training classes may not help truly new labels, and wording changes predictions: zero-shot results must use fixed templates and no fitting on the target labels.

05

Try it on frames in CodeSplash

Read

CodeSplash doesn't open video, but frames saved as image files can be added to a project as an image collection; join a small table giving each frame's source video and timestamp. Then:

  1. Image–text search and zero-shot labels scores each frame against your label prompts or text queries with CLIP or SigLIP.
  2. Average the scores per video in Prepare or SQL: that is CLIP4Clip's mean pooling, with the same blindness to order.
Method guide · discover.image_textImage–text search and zero-shot labels (CLIP, SigLIP)Which of my words fit each image, which images match a text, and which images look alike?

Treat it as a notebook-sized experiment: no learned temporal model is involved.

06

Controls that matter

Read
  • Reversed and shuffled clips: if scores don't change, the model isn't using order (a shuffled-frame controlShuffled-frame controlScore the model again on clips with their frames in random order. If accuracy barely drops, it isn't using motion.).
  • Hard captions that differ in one event ("pours milk" against "pours water").
  • Same data when comparing pooling against learned temporal modules.
  • Exact templates and splits for zero-shot numbers.
07

What runs here

Read
EntryIn CodeSplash
VID044 · CLIP4ClipNeeds a data type CodeSplash doesn't load yet (video)
VID045 · X-CLIPExplained here
08

Check: CLIP on video

Checkpoint

Check yourself

What does mean pooling of frame embeddings lose?

Show the answer

Answer: b

Averaging is order-blind. That's fine for scenes, not for events defined by direction.

Check yourself

Why is CLIP4Clip's mean-pooling variant worth running before a complex video–text model?

Show the answer

Answer: a

If a learned temporal module barely beats averaging on the same data, motion isn't doing much.

Check yourself

Which test shows whether a video retrieval model uses event order?

Show the answer

Answer: b

Order-sensitive queries against reversed clips separate scene matching from event understanding.

Check yourself

What are X-CLIP's video-conditioned prompts?

Show the answer

Answer: b

The text side adapts to each clip; the vision side gets cross-frame attention.

Check yourself

You report X-CLIP's zero-shot accuracy on a new action set. What keeps it honest?

Show the answer

Answer: a

Template choice changes predictions. Choosing templates on the test labels is fitting to them.

Check yourself

In CodeSplash you score extracted frames with an image–text model and average per video. Which video model have you reproduced in spirit?

Show the answer

Answer: b

Per-frame CLIP scores averaged per video is mean pooling; no temporal module is involved.

09

Recap

Recap
  • Image–text models on sampled frames plus pooling make a strong video search baseline.
  • Mean pooling forgets order: a clip and its reverse score the same.
  • X-CLIP adds cross-frame attention and video-conditioned prompts; keep zero-shot protocols fixed.
  • In CodeSplash, frames saved as images can be scored with CLIP or SigLIP and pooled per video.

Concepts in this lesson