🚀 Qwen2.5-VL-7B-Captioner-Relaxed
Qwen2.5-VL-7B-Captioner-Relaxed 是一個經過指令微調的版本,基於先進的多模態大語言模型 Qwen/Qwen2.5-VL-7B-Instruct。這是 Ertugrul/Qwen2-VL-7B-Captioner-Relaxed 的更新版本,使用 Qwen2.5 基礎模型進行了重新訓練。 這個微調版本基於為文本到圖像模型精心策劃的數據集,能為給定圖像提供更詳細的描述。它構建於改進後的 Qwen2.5 架構之上。
🚀 快速開始
環境要求
如果你遇到 KeyError: 'qwen2_vl'
或 ImportError: cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers'
等錯誤,請嘗試從源代碼安裝最新版本的 transformers 庫:
pip install git+https://github.com/huggingface/transformers accelerate
代碼示例
import torch
from PIL import Image
from transformers import (
AutoModelForImageTextToText,
AutoProcessor
)
model_id = "Ertugrul/Qwen2.5-VL-7B-Captioner-Relaxed"
image_path = "path/to/your/image.jpg"
model = AutoModelForImageTextToText.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
attn_implementation="flash_attention_2",
)
min_pixels = 256*28*28
max_pixels = 1280*28*28
processor = AutoProcessor.from_pretrained(model_id, max_pixels=max_pixels, min_pixels=min_pixels)
system_message = "You are an expert image describer."
def generate_description(path, model, processor):
image_inputs = Image.open(path).convert("RGB")
messages = [
{
"role": "system",
"content": [{"type": "text", "text": system_message}],
},
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image."},
{"type": "image", "image": image_inputs},
],
},
]
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = processor(
text=[text],
images=image_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to(model.device)
generated_ids = model.generate(**inputs, max_new_tokens=512, min_p=0.1, do_sample=True, temperature=1.5)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
return output_text[0]
description = generate_description(image_path, model, processor)
print(description)
✨ 主要特性
- 增強細節:生成更全面、細緻的圖像描述。
- 約束放寬:與基礎模型相比,提供限制更少的圖像描述。
- 自然語言輸出:使用自然語言描述圖像中的不同對象並指定其位置。
- 針對圖像生成優化:生成與最先進的文本到圖像生成模型兼容的標題。
- 改進的基礎模型:利用 Qwen2.5 的優勢,可能帶來更好的整體性能和理解能力。
⚠️ 重要提示
這個微調模型是為創建文本到圖像數據集而優化的。因此,在其他任務上的性能可能低於原始模型。
📚 詳細文檔
更多詳細選項,請參考 Qwen/Qwen2.5-VL-7B-Instruct 文檔。
📄 許可證
本項目採用 apache-2.0 許可證。
屬性 |
詳情 |
模型類型 |
多模態 |
基礎模型 |
Qwen/Qwen2.5-VL-7B-Instruct |
管道標籤 |
圖像文本到文本 |
許可證 |
apache-2.0 |