🚀 Qwen2-VL-7B-Captioner-Relaxed
Qwen2-VL-7B-Captioner-Relaxedは、高度なマルチモーダル大規模言語モデルであるQwen2-VL-7B-Instructを命令微調整したバージョンです。この微調整されたバージョンは、テキストから画像へのモデル用に手作りで選ばれたデータセットに基づいており、与えられた画像に対して大幅に詳細な説明を提供します。
🚀 クイックスタート
from PIL import Image
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from transformers import BitsAndBytesConfig
import torch
model_id = "Ertugrul/Qwen2-VL-7B-Captioner-Relaxed"
model = Qwen2VLForConditionalGeneration.from_pretrained(
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)
conversation = [
{
"role": "user",
"content": [
{
"type": "image",
},
{"type": "text", "text": "Describe this image."},
],
}
]
image = Image.open(r"PATH_TO_YOUR_IMAGE")
text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
inputs = processor(
text=[text_prompt], images=[image], padding=True, return_tensors="pt"
)
inputs = inputs.to("cuda")
with torch.no_grad():
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
output_ids = model.generate(**inputs, max_new_tokens=384, do_sample=True, temperature=0.7, use_cache=True, top_k=50)
generated_ids = [
output_ids[len(input_ids) :]
for input_ids, output_ids in zip(inputs.input_ids, output_ids)
]
output_text = processor.batch_decode(
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
)[0]
print(output_text)
グラディオUI
コーディングをしたくない場合は、選択した画像にキャプションを付けることができるシンプルなGUIがあります。詳細はこちらで確認できます。
qwen2vl-captioner-gui
✨ 主な機能
- 詳細性の向上:より包括的で繊細な画像説明を生成します。
- 制約の緩和:ベースモデルと比較して、より制約の少ない画像説明を提供します。
- 自然言語出力:自然言語を使用して、画像内の異なるサブジェクトを説明し、それらの位置を指定します。
- 画像生成に最適化:最先端のテキストから画像への生成モデルと互換性のある形式でキャプションを生成します。
⚠️ 重要提示
この微調整されたモデルは、テキストから画像へのデータセットの作成に最適化されています。その結果、他のタスク(例:mmmu_valで約10%の低下)でのパフォーマンスは、元のモデルと比較して低くなる可能性があります。
📦 インストール
KeyError: 'qwen2_vl'
や ImportError: cannot import name 'Qwen2VLForConditionalGeneration' from 'transformers'
などのエラーが発生した場合は、ソースから最新バージョンのtransformersライブラリをインストールしてみてください。
pip install git+https://github.com/huggingface/transformers
📚 ドキュメント
より詳細なオプションについては、Qwen2-VL-7B-Instruct のドキュメントを参照してください。
📄 ライセンス
このライブラリはApache-2.0ライセンスの下で提供されています。
謝辞
- Google AI/ML Developer Programsチームが、Google Cloud Creditを提供することでこの作業を支援しました。