Search and group similar images
1from lynx import LYNX2 3model = LYNX("lynx-basic")4 5# Single image → (D,) ndarray6embedding = model.encode("frame.jpg", layer="pooled")7 8# Directory → ((N, D) ndarray, list of paths)9embeddings, paths = model.encode("frames_dir/")Embeddings decouple "what the model sees" from "what you do with it". Once you have a (N, D) array, you can build a similarity search, cluster a dataset, deduplicate near-identical frames, or train your own downstream classifier without retraining the backbone — all on the same model that's running detection in production.
The most common use: similarity search. Encode a reference image, encode your corpus, rank by cosine similarity. For a small corpus (<10K), numpy is fine; for larger, swap in FAISS or Annoy with the same vectors. Encode a directory once, cache the resulting array on disk, query it for years.
Not every model exports encoder outputs. If encode() raises, the error lists the available layer names — pick one. layer="pooled" is the standard choice (a single vector per image); deeper layers give higher-dim, more spatially-localized features at the cost of size and speed.