🚀 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アーキテクチャに基づいて構築されています。
✨ 主な機能
- 詳細な説明: より包括的で微妙な画像の説明を生成します。
- 制約の緩和: ベースモデルと比較して、制約の少ない画像の説明を提供します。
- 自然言語出力: 画像内の異なる対象を自然言語で説明し、それらの位置を指定します。
- 画像生成に最適化: 最先端のテキストから画像への生成モデルと互換性のある形式でキャプションを生成します。
- 改良されたベースモデル: 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)
📚 ドキュメント
より詳細なオプションについては、Qwen/Qwen2.5-VL-7B-Instructのドキュメントを参照してください。
📄 ライセンス
このプロジェクトは、Apache-2.0ライセンスの下で提供されています。