Media tag

From damionrashford/media-os · View interactive version

Media tag is an AI agent skill from the GitHub repository damionrashford/media-os. AI image and video tagging, captioning, zero-shot classification, and semantic search with open-source + commercial-safe vision-language models: CLIP (MIT, OpenAI, zero-shot classification + text-image similarity, ViT-B/32 to ViT-L/14), SigLIP (Apache 2.0, Google, sigmoid loss, outperforms CLIP on m

How to use this skill

Skill file

Media Tag

Context: $ARGUMENTS

Four open-source vision-language families, four different jobs:

All commercial-safe.

Quick start

When to use

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:

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

Reference docs

Gotchas

Examples

Example 1 — Alt text for an image

uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py caption \
  --model blip2 --in hero.jpg \
  --prompt "Describe this image in one short sentence for alt text."

Example 2 — Classify photo against custom labels

uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py classify \
  --model siglip --in street.jpg \
  --labels "a photo of a pedestrian,a photo of a cyclist,a photo of a car,a photo of a bus,a photo of a truck" \
  --top-k 3

Example 3 — Semantic search the last-year's camera roll

uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py search \
  --model clip --index ~/Pictures/2025/ --index-out 2025.npz

uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py search \
  --index 2025.npz --query "sunset at the beach" --top-k 20

Example 4 — Bulk-tag a folder with a controlled vocabulary

tags.txt:

a photo of a person
a photo of food
a photo of a landscape
a photo of architecture
a photo of an animal
a photo of a vehicle
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py tag-batch \
  --model clip --in-dir photos/ --tags-file tags.txt \
  --out-csv photos_tags.csv --top-k 2 --threshold 0.20

Example 5 — Describe a video clip scene-by-scene

# optional: first find scene boundaries via media-scenedetect
scenedetect -i clip.mp4 detect-adaptive list-scenes

# then describe each scene's mid-frame
uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py video-describe \
  --model llava --in clip.mp4 --sample-fps 0.5 \
  --prompt "Describe this scene in 1-2 sentences." \
  --out scenes.jsonl

Example 6 — Detailed visual QA

uv run ${CLAUDE_SKILL_DIR}/scripts/tag.py describe \
  --model llava --in kitchen.jpg \
  --prompt "List all appliances you can see and estimate their color."

Troubleshooting

`OSError: google/siglip-base-patch16-384 is not a local folder`

Cause: No network on first run, or HF Hub outage.

Solution: Pre-download with tag.py install siglip when online; weights cache to ~/.cache/huggingface/hub/.

Search returns nonsense for perfectly reasonable queries

Cause: Embeddings not L2-normalized before cosine similarity.

Solution: The script normalizes by default. If building your own index, features /= features.norm(dim=-1, keepdim=True) before any dot-product or FAISS index insert.

LLaVA OOM on a 24 GB GPU

Cause: Default torch.float16 + full attention is still tight for 7 B on large inputs.

Solution: Use --device cpu (slow but works), or pick a smaller variant (llava-1.5-7b is smaller than -13b), or enable 4-bit via bitsandbytes (see references/models.md).

CLIP classification scores all look the same

Cause: Label prompts are too similar (cosine similarity saturates) or too dissimilar from ImageNet training distribution.

Solution: Rewrite prompts as "a photo of X" / "an image showing X". For domain-specific labels, an ensemble of 5-10 prompt templates per class averaged is the standard trick.

Video-describe runs for hours

Cause: --sample-fps 1 is one LLaVA inference per second. For a 30-min video that's 1 800 inferences.

Solution: Reduce to --sample-fps 0.2 (one per 5 s), or pre-segment with media-scenedetect and run once per scene midpoint.

BLIP-2 captions are boring / repetitive

Cause: Default greedy decoding.

Solution: The script uses num_beams=5 by default. Crank to 10 or enable do_sample=True with temperature 0.7 via --beams 10 --temperature 0.7 (if wired in). Or switch to LLaVA for more varied language.

SigLIP scores don't sum to 1

Cause: SigLIP uses sigmoid, not softmax. Each label probability is independent.

Solution: Treat as independent yes/no probabilities. Sum > 1 or < 1 is expected.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.