🚀 Pixtral-12B-Captioner-Relaxed
Pixtral-12B-Captioner-Relaxedは、高度なマルチモーダル大規模言語モデルであるPixtral-12B-2409を命令微調整したバージョンです。この微調整バージョンは、テキストから画像へのモデル用に手作りで選ばれたデータセットに基づいており、与えられた画像のより詳細な説明を提供します。
🚀 クイックスタート
from PIL import Image
from transformers import LlavaForConditionalGeneration, AutoProcessor
from transformers import BitsAndBytesConfig
import torch
import matplotlib.pyplot as plt
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4"
)
model_id = "Ertugrul/Pixtral-12B-Captioner-Relaxed"
model = LlavaForConditionalGeneration.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
processor = AutoProcessor.from_pretrained(model_id)
conversation = [
{
"role": "user",
"content": [
{"type": "text", "text": "Describe the image.\n"},
{
"type": "image",
}
],
}
]
PROMPT = processor.apply_chat_template(conversation, add_generation_prompt=True)
image = Image.open(r"PATH_TO_YOUR_IMAGE")
def resize_image(image, target_size=768):
"""Resize the image to have the target size on the shortest side."""
width, height = image.size
if width < height:
new_width = target_size
new_height = int(height * (new_width / width))
else:
new_height = target_size
new_width = int(width * (new_height / height))
return image.resize((new_width, new_height), Image.LANCZOS)
image = resize_image(image, 768)
inputs = processor(text=PROMPT, images=image, return_tensors="pt").to("cuda")
with torch.no_grad():
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
generate_ids = model.generate(**inputs, max_new_tokens=384, do_sample=True, temperature=0.3, use_cache=True, top_k=20)
output_text = processor.batch_decode(generate_ids[:, inputs.input_ids.shape[1]:], skip_special_tokens=True, clean_up_tokenization_spaces=True)[0]
print(output_text)
✨ 主な機能
- 詳細性の向上:より包括的で微妙な画像の説明を生成します。
- 制約の緩和:ベースモデルと比較して、より制約の少ない画像の説明を提供します。
- 自然言語出力:画像内の異なる主題を説明し、自然言語を使用してそれらの位置を指定します。
- 画像生成に最適化:最先端のテキストから画像への生成モデルと互換性のある形式でキャプションを生成します。
⚠️ 重要提示
この微調整モデルは、テキストから画像へのデータセットの作成に最適化されています。そのため、他の複雑なタスクでのパフォーマンスは、元のモデルと比較して低くなる可能性があります。
🔧 技術詳細
12Bモデルは、半精度で24GBのVRAMが必要です。モデルは8ビットまたは4ビット量子化でロードできますが、パフォーマンスが低下することが予想されます。
📄 ライセンス
このライブラリは、Apache-2.0ライセンスの下で提供されています。
謝辞
より詳細なオプションについては、Pixtral-12B-2409またはmistral-community/pixtral-12bのドキュメントを参照してください。
また、代替の小規模モデルとして、Qwen2-VL-7B-Captioner-Relaxedを試すこともできます。これは同様の方法で学習されています。