Media Tag
Context: $ARGUMENTS
Four open-source vision-language families, four different jobs:
- CLIP / SigLIP — "is this image closer to prompt A or prompt B?" Zero-shot classification, similarity scoring, semantic search index.
- BLIP-2 — pure image captioning. One image in, one sentence out.
- LLaVA — full vision-language model. Captioning, VQA, dense description, video-frame narration.
All commercial-safe.
Quick start
- Caption a single image (sentence): → Step 3 (
tag.py caption --model blip2) - Describe in detail or ask a question (VLM): → Step 4 (
tag.py describe --model llava) - Zero-shot classify against your own label list: → Step 5 (
tag.py classify --model clip) - Build and query a CLIP search index over a folder: → Step 6 (
tag.py search) - Bulk-tag a folder to CSV: → Step 7 (
tag.py tag-batch) - Per-scene description of a video: → Step 8 (
tag.py video-describe) - Pre-download weights: → Step 2 (
tag.py install <model>)
When to use
- Auto-alt-text for a photo library or CMS.
- Content moderation / safety (classify against a forbidden-label list).
- Semantic search over a local image folder ("find the red car in the rain").
- Cataloguing / DAM metadata enrichment (auto-tag with a controlled vocabulary).
- Quick video content summary — one description per second or per scene cut.
- Caption → search index → retrieval pipelines for RAG over images.
- Do NOT use for facial recognition of named individuals (these models weren't trained for that; accuracy and ethics both terrible).
- Do NOT use for OCR — use
media-ocr-ai. Do NOT use for object-detection bboxes — usecv-opencv(YOLO) orcv-mediapipe.
Step 1 — Pick a model
| Family | License | Strength | VRAM (base) | When to pick |
|-----------|---------------|---------------------------------------------------------|-------------|--------------------------------------------|
| CLIP | MIT | Zero-shot classification + embedding-based search | 1–4 GB | "Does this match this label?" |
| SigLIP| Apache 2.0 | Drop-in CLIP replacement; higher zero-shot accuracy | 1–4 GB | Same as CLIP, prefer when quality matters |
| BLIP-2| BSD-3-Clause | Clean image captions, compact output | 6–12 GB | One-line alt text / captions |
| LLaVA | Apache 2.0 | Free-form dense description, VQA, video-frame narration | 8–24 GB | "Describe this video scene in detail" |
Full per-model matrix (benchmark accuracy, caption quality, context length, speed) in references/models.md.
Step 2 — Install / pre-download
PEP 723 header in scripts/tag.py declares all dependencies. uv run manages an ephemeral venv.
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py install clip
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py install siglip
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py install blip2
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py install llava
Per-model notes:
- CLIP — via
open_clip(preferred for variety) ortransformers(openai/clip-vit-large-patch14).open_clipexposes a huge zoo (ViT-B-32,ViT-L-14,ViT-H-14,ViT-bigG-14, with OpenAI / LAION / DataComp pretrain tags). - SigLIP —
google/siglip-base-patch16-384,-large-patch16-384,-so400m-patch14-384. All Apache 2.0. Usetransformers. - BLIP-2 —
Salesforce/blip2-opt-2.7b(BSD-3),-opt-6.7b,-flan-t5-xl. Usetransformers. - LLaVA —
llava-hf/llava-1.5-7b-hf,llava-hf/llava-v1.6-mistral-7b-hf(LLaVA-NeXT),llava-hf/llava-onevision-qwen2-7b-ov-hf(includes video support, recommended). All Apache 2.0 as repackaged byllava-hf. Usetransformers.
Step 3 — Single-image caption (BLIP-2 or LLaVA)
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py caption \
--model blip2 --in photo.jpg --out-text caption.txt
Output: one sentence, WCAG-alt-text-style. Good for cataloguing.
For richer captions:
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py caption \
--model llava --in photo.jpg --out-text caption.txt
LLaVA tends to produce 2–4 sentences describing scene, subject, mood. Pass --prompt to steer:
--prompt "Describe this image in one short sentence suitable for alt text."
Step 4 — VLM description + VQA (LLaVA)
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py describe \
--model llava --in photo.jpg \
--prompt "What objects are in this image and what is their color?" \
--out answer.txt
Arbitrary VQA via --prompt. Useful prompts are cached in references/prompts.md — read it when drafting prompts for object detection, scene analysis, or video narration.
Step 5 — Zero-shot classification (CLIP or SigLIP)
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py classify \
--model clip --in photo.jpg \
--labels "a photo of a cat,a photo of a dog,a photo of a car,a photo of a bicycle" \
--top-k 2
Output (JSON on stdout):
{"top": [
{"label": "a photo of a cat", "score": 0.87},
{"label": "a photo of a dog", "score": 0.09}
]}
Pro tip — use full-sentence prompts ("a photo of X"), not bare words ("X"). CLIP / SigLIP are heavily biased by phrasing; "a photo of a cat" outperforms "cat" by 5–10 points on ImageNet-class prompts.
For SigLIP:
--model siglip
Same interface; different pretrain + sigmoid head. Higher-quality scores without softmax competition between labels — each score is independent probability.
Step 6 — CLIP semantic search index
# 1. build embedding index of a folder
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py search \
--model clip --index photos/ --index-out photos_clip.npz
# 2. query
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py search \
--model clip --index photos_clip.npz \
--query "a red car in the rain" --top-k 10
Index is a .npz with files (list of paths) + embeddings (float32 L2-normalized array). Query is a text embedding dot-producted against the index.
For scale beyond ~50 k images, swap the brute-force dot-product for FAISS or Qdrant — the reference doc references/models.md has a short recipe, or integrate into your own pipeline.
Step 7 — Bulk-tag a folder to CSV
# tags.txt contains one candidate label per line
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py tag-batch \
--model clip --in-dir photos/ --tags-file tags.txt \
--out-csv tags.csv --threshold 0.25 --top-k 5
Writes filename,label,score rows for every image × top-k labels above threshold. Good for automated catalog metadata.
Step 8 — Video scene description
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py video-describe \
--model llava --in clip.mp4 \
--sample-fps 1 --prompt "Describe this frame in one sentence." \
--out clip_scenes.jsonl
Samples the video at N fps, runs LLaVA on each frame, writes one JSONL row per sample: {"t": 3.0, "text": "..."}. Downstream, merge adjacent identical descriptions for scene-level summary, or pair with media-scenedetect for true scene-boundary sampling.
Gotcha: per-frame LLaVA is expensive. For a 5-minute video at --sample-fps 1 on a 3090 that's ~5 minutes of inference. Use --sample-fps 0.2 (one frame per 5s) or pre-segment with media-scenedetect and run once per scene.
Available scripts
scripts/tag.py— subcommands:caption,classify,describe,search,tag-batch,video-describe,install. Each supports--dry-run,--verbose,--device {auto,cpu,cuda,mps}.