🚀 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 |
推理支持 |
否 |