🚀 GLM-Edge-V-2B
GLM-Edge-V-2B 是一款支持圖像文本到文本轉換的模型,適用於圖像描述等場景。點擊這裡查看中文閱讀內容。
🚀 快速開始
🔧 安裝指南
從源代碼安裝 transformers 庫:
pip install git+https://github.com/huggingface/transformers.git
💻 使用示例
基礎用法
import torch
from PIL import Image
from transformers import (
AutoTokenizer,
AutoImageProcessor,
AutoModelForCausalLM,
)
url = "img.png"
messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "describe this image"}]}]
image = Image.open(url)
model_dir = "THUDM/glm-edge-v-5b"
processor = AutoImageProcessor.from_pretrained(model_dir, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_dir,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_dict=True, tokenize=True, return_tensors="pt"
).to(next(model.parameters()).device)
generate_kwargs = {
**inputs,
"pixel_values": torch.tensor(processor(image).pixel_values).to(next(model.parameters()).device),
}
output = model.generate(**generate_kwargs, max_new_tokens=100)
print(tokenizer.decode(output[0][len(inputs["input_ids"][0]):], skip_special_tokens=True))
📄 許可證
本模型權重的使用需遵循 LICENSE 中規定的條款。
📋 模型信息
屬性 |
詳情 |
框架 |
Pytorch |
許可證類型 |
glm-4 |
管道標籤 |
image-text-to-text |
標籤 |
glm、edge |
推理支持 |
否 |