🚀 GLM-Edge-V-5B
GLM-Edge-V-5B是一款支持图像文本转换为文本的模型,适用于图像描述等场景。对于中文阅读需求,可点击这里查看相关内容。
🚀 快速开始
✨ 主要特性
- 框架支持:Pytorch
- 模型标签:glm、edge
- 推理功能:暂不支持
📦 安装指南
从源代码安装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中规定的条款。
信息表格
属性 |
详情 |
模型类型 |
image-text-to-text |
训练框架 |
Pytorch |
许可证 |
other(glm-4) |
许可证链接 |
LICENSE |