agent-management
Create, manage, and orchestrate AI agents using the AI Maestro CLI. Use when the user asks to "create agent", "list agents",…
Vision-language pre-training framework bridging frozen image encoders and LLMs. Use when you need image captioning, visual question answering, image-text retrieval, or multimodal chat with state-of-the-art zero-shot performance.
Claude Code
$ npx -y skills add davila7/claude-code-templates --skill multimodal-blip-2 --agent claude-code
Codex
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a codex -y
Cursor
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a cursor -y
Gemini CLI
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a gemini-cli -y
GitHub Copilot
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a github-copilot -y
OpenCode
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a opencode -y
Windsurf
$ npx skills add davila7/claude-code-templates --skill multimodal-blip-2 -a windsurf -y
name: multimodal-blip-2 description: Vision-language pre-training framework bridging frozen image encoders and LLMs. Use when you need image captioning, visual question answering, image-text retrieval, or multimodal chat with state-of-the-art zero-shot performance. license: MIT metadata: version: 1.0.0 author: Orchestra Research tags: [Multimodal, Vision-Language, Image Captioning, VQA, Zero-Shot] dependencies: [transformers>=4.30.0, torch>=1.10.0, Pillow]
Comprehensive guide to using Salesforce's BLIP-2 for vision-language tasks with frozen image encoders and large language models.
**Use BLIP-2 when:**
**Key features:**
**Use alternatives instead:**
# HuggingFace Transformers (recommended) pip install transformers accelerate torch Pillow # Or LAVIS library (Salesforce official) pip install salesforce-lavis
import torch
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
# Load model and processor
processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained(
"Salesforce/blip2-opt-2.7b",
torch_dtype=torch.float16,
device_map="auto"
)
# Load image
image = Image.open("photo.jpg").convert("RGB")
# Generate caption
inputs = processor(images=image, return_tensors="pt").to("cuda", torch.float16)
generated_ids = model.generate(**inputs, max_new_tokens=50)
caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(caption)# Ask a question about the image
question = "What color is the car in this image?"
inputs = processor(images=image, text=question, return_tensors="pt").to("cuda", torch.float16)
generated_ids = model.generate(**inputs, max_new_tokens=50)
answer = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(answer)import torch
from lavis.models import load_model_and_preprocess
from PIL import Image
# Load model
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model, vis_processors, txt_processors = load_model_and_preprocess(
name="blip2_opt",
model_type="pretrain_opt2.7b",
is_eval=True,
device=device
)
# Process image
image = Image.open("photo.jpg").convert("RGB")
image = vis_processors["eval"](image).unsqueeze(0).to(device)
# Caption
caption = model.generate({"image": image})
print(caption)
# VQA
question = txt_processors["eval"]("What is in this image?")
answer = model.generate({"image": image, "prompt": question})
print(answer)BLIP-2 Architecture:
┌─────────────────────────────────────────────────────────────┐
│ Q-Former │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Learned Queries (32 queries × 768 dim) │ │
│ └────────────────────────┬────────────────────────────┘ │
│ │ │
│ ┌────────────────────────▼────────────────────────────┐ │
│ │ Cross-Attention with Image Features │ │
│ └────────────────────────┬────────────────────────────┘ │
│ │ │
│ ┌────────────────────────▼────────────────────────────┐ │
│ │ Self-Attention Layers (Transformer) │ │
│ └────────────────────────┬────────────────────────────┘ │
└───────────────────────────┼─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│ Frozen Vision Encoder │ Frozen LLM │
│ (ViT-G/14 from EVA-CLIP) │ (OPT or FlanT5) │
└─────────────────────────────────────────────────────────────┘| Model | LLM Backend | Size | Use Case | |-------|-------------|------|----------| | `blip2-opt-2.7b` | OPT-2.7B | ~4GB | General captioning, VQA | | `blip2-opt-6.7b` | OPT-6.7B | ~8GB | Better reasoning | | `blip2-flan-t5-xl` | FlanT5-XL | ~5GB | Instruction following | | `blip2-flan-t5-xxl` | FlanT5-XXL | ~13GB | Best quality |
| Component | Description | Parameters | |-----------|-------------|------------| | Learned queries | Fixed set of learnable embeddings | 32 × 768 | | Image transformer | Cross-attention to vision features | ~108M | | Text transformer | Self-attention for text | ~108M | | Linear projection | Maps to LLM dimension | Varies |
from PIL import Image
import torch
# Load multiple images
images = [Image.open(f"image_{i}.jpg").convert("RGB") for i in range(4)]
questions = [
"What isOpen-source registry and CLI for Claude Code components: agents, commands, skills, hooks, MCPs, settings and mods
Create, manage, and orchestrate AI agents using the AI Maestro CLI. Use when the user asks to "create agent", "list agents",…
Send and receive cryptographically signed messages between AI agents using the Agent Messaging Protocol (AMP). Use when the user…
Search auto-generated codebase documentation for function signatures, API docs, class definitions, and code comments. Use when…
Query the code graph database to understand component relationships, dependencies, and change impact. Use when the user asks to…
Search conversation history and semantic memory to recall previous discussions, decisions, and context. Use when the user asks to…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.