llava
它能做什么
这项技能介绍 LLaVA,这是一个开源助手,能够看懂图片并与你讨论图片内容。适合构建图片聊天机器人或图片分析工具的开发者。
适用场景
- ✓当你想要一个能在多条消息中回答关于某张图片问题的聊天机器人时。
- ✓当你需要一个免费、开源的视觉聊天 API 替代方案时。
- ✓当你想让模型描述或分析包含图片的文档时。
技能链接
https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/18-multimodal/llava/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我做一个聊天工具:我上传一张图表,然后可以就它继续提问。”
每周 5 个新技能,1 分钟读完。
工作原理
LLaVA 把 CLIP 图像编码器与 Vicuna 或 LLaMA 语言模型组合在一起。你加载预训练的检查点,传入图片和消息,模型就会以对话方式回复。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
LLaVA - Large Language and Vision Assistant
Open-source vision-language model for conversational image understanding.
When to use LLaVA
Use when:
- Building vision-language chatbots
- Visual question answering (VQA)
- Image description and captioning
- Multi-turn image conversations
- Visual instruction following
- Document understanding with images
Metrics:
- 23,000+ GitHub stars
- GPT-4V level capabilities (targeted)
- Apache 2.0 License
- Multiple model sizes (7B-34B params)
Use alternatives instead:
- GPT-4V: Highest quality, API-based
- CLIP: Simple zero-shot classification
- BLIP-2: Better for captioning only
- Flamingo: Research, not open-source
Quick start
Installation
# Clone repository
git clone https://github.com/haotian-liu/LLaVA
cd LLaVA
# Install
pip install -e .
Basic usage
from llava.model.builder import load_pretrained_model
from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
from llava.conversation import conv_templates
from PIL import Image
import torch
# Load model
model_path = "liuhaotian/llava-v1.5-7b"
tokenizer, model, image_processor, context_len = load_pretrained_model(
model_path=model_path,
model_base=None,
model_name=get_model_name_from_path(model_path)
)
# Load image
image = Image.open("image.jpg")
image_tensor = process_images([image], image_processor, model.config)
image_tensor = image_tensor.to(model.device, dtype=torch.float16)
# Create conversation
conv = conv_templates["llava_v1"].copy()
conv.append_message(conv.roles[0], DEFAULT_IMAGE_TOKEN + "\nWhat is in this image?")
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()
# Generate response
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(model.device)
with torch.inference_mode():
output_ids = model.generate(
input_ids,
images=image_tensor,
do_sample=True,
temperature=0.2,
max_new_tokens=512
)
response = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()
print(response)
Available models
| Model | Parameters | VRAM | Quality |
|---|---|---|---|
| LLaVA-v1.5-7B | 7B | ~14 GB | Good |
| LLaVA-v1.5-13B | 13B | ~28 GB | Better |
| LLaVA-v1.6-34B | 34B | ~70 GB | Best |
# Load different models
model_7b = "liuhaotian/llava-v1.5-7b"
model_13b = "liuhaotian/llava-v1.5-13b"
model_34b = "liuhaotian/llava-v1.6-34b"
# 4-bit quantization for lower VRAM
load_4bit = True # Reduces VRAM by ~4×
CLI usage
# Single image query
python -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file image.jpg \
--query "What is in this image?"
# Multi-turn conversation
python -m llava.serve.cli \
--model-path liuhaotian/llava-v1.5-7b \
--image-file image.jpg
# Then type questions interactively
Web UI (Gradio)
# Launch Gradio interface
python -m llava.serve.gradio_web_server \
--model-path liuhaotian/llava-v1.5-7b \
--load-4bit # Optional: reduce VRAM
# Access at http://localhost:7860
Multi-turn conversations
# Initialize conversation
conv = conv_templates["llava_v1"].copy()
# Turn 1
conv.append_message(conv.roles[0], DEFAULT_IMAGE_TOKEN + "\nWhat is in this image?")
conv.append_message(conv.roles[1], None)
response1 = generate(conv, model, image) # "A dog playing in a park"
# Turn 2
conv.messages[-1][1] = response1 # Add previous response
conv.append_message(conv.roles[0], "What breed is the dog?")
conv.append_message(conv.roles[1], None)
response2 = generate(conv, model, image) # "Golden Retriever"
# Turn 3
conv.messages[-1][1] = response2
conv.append_message(conv.roles[0], "What time of day is it?")
conv.append_message(conv.roles[1], None)
response3 = generate(conv, model, image)
Common tasks
Image captioning
question = "Describe this image in detail."
response = ask(model, image, question)
Visual question answering
question = "How many people are in the image?"
response = ask(model, image, question)
Object detection (textual)
question = "List all the objects you can see in this image."
response = ask(model, image, question)
Scene understanding
question = "What is happening in this scene?"
r
常见问题
有哪些规格可以选?
技能说明模型规模从约 70 亿到 340 亿参数不等。
它使用什么许可证?
技能列出的是 Apache 2.0 许可证。
简单分类应该用哪个工具?
技能建议简单的零样本分类使用 CLIP。
详情
作者的原始描述
Large Language and Vision Assistant. Enables visual instruction tuning and image-based conversations. Combines CLIP vision encoder with Vicuna/LLaMA language models. Supports multi-turn image chat, visual question answering, and instruction following. Use for vision-language chatbots or image understanding tasks. Best for conversational image analysis.
热度
- GitHub 星标
- 14k
- 排名
- #11235
- 许可证
- MIT
- 更新时间
- 2026/10/10
评论
- …
同一仓库的更多技能
autoresearch
14k引导你的智能体完成一个完整的 AI 研究项目,从文献综述到实验和写作,并通过反复的测试与审查循环推进。
prompt-guard
14k让你的智能体在文本进入你的 AI 应用之前,使用 Meta 的小型分类器检查其中是否含有提示注入和越狱尝试。
pytorch-fsdp2
14k向你的智能体展示如何在训练脚本中加入 PyTorch FSDP2,使大型模型能被拆分到多张 GPU 上并正确保存。
ml-training-recipes
14k为你的智能体提供经过验证的神经网络训练方案,涵盖模型选择、优化器、学习率以及处理损失骤升的方法。