モデル概要
モデル特徴
モデル能力
使用事例
🚀 Florence-2: 多様なビジョンタスクの統一表現を進化させる
このモデルは、多様なビジョンとビジョン言語タスクをプロンプトベースのアプローチで扱う高度なビジョン基礎モデルです。簡単なテキストプロンプトを解釈し、キャプショニング、物体検出、セグメンテーションなどのタスクを実行できます。
🚀 クイックスタート
以下のコードを使用して、モデルを始めることができます。
import requests
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
prompt = "<OD>"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=prompt, images=image, return_tensors="pt")
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
do_sample=False,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task="<OD>", image_size=(image.width, image.height))
print(parsed_answer)
✨ 主な機能
モデル概要
これは、Microsoftのモデルにいくつかの修正を加えたものです。修正のPRは元のモデルでオープンされていますが、マージされるまでこのモデルを使用してすべてを正しくセットアップしています。
このHubリポジトリには、MicrosoftのFlorence-2モデルのHuggingFaceのtransformers
実装が含まれています。
Florence-2は、高度なビジョン基礎モデルで、プロンプトベースのアプローチを使用して、幅広いビジョンおよびビジョン言語タスクを処理します。Florence-2は、簡単なテキストプロンプトを解釈して、キャプショニング、物体検出、セグメンテーションなどのタスクを実行できます。これは、1億2600万枚の画像にわたる54億個のアノテーションを含むFLD-5Bデータセットを利用して、マルチタスク学習を習得します。モデルのシーケンスツーシーケンスアーキテクチャにより、ゼロショットとファインチューニングの両方の設定で優れた性能を発揮し、競争力のあるビジョン基礎モデルとなっています。
リソースと技術ドキュメント:
モデル | モデルサイズ | モデル説明 |
---|---|---|
Florence-2-base[HF] | 0.23B | FLD-5Bで事前学習されたモデル |
Florence-2-large[HF] | 0.77B | FLD-5Bで事前学習されたモデル |
Florence-2-base-ft[HF] | 0.23B | 下流タスクのコレクションでファインチューニングされたモデル |
Florence-2-large-ft[HF] | 0.77B | 下流タスクのコレクションでファインチューニングされたモデル |
タスク
このモデルは、プロンプトを変更することで、さまざまなタスクを実行できます。
まず、プロンプトを実行する関数を定義しましょう。
展開するにはクリック
import requests
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
def run_example(task_prompt, text_input=None):
if text_input is None:
prompt = task_prompt
else:
prompt = task_prompt + text_input
inputs = processor(text=prompt, images=image, return_tensors="pt")
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
print(parsed_answer)
これが、Florence-2
が実行できるタスクです。
展開するにはクリック
キャプショニング
prompt = "<CAPTION>"
run_example(prompt)
詳細キャプショニング
prompt = "<DETAILED_CAPTION>"
run_example(prompt)
さらに詳細なキャプショニング
prompt = "<MORE_DETAILED_CAPTION>"
run_example(prompt)
キャプションからフレーズの接地
キャプションからフレーズの接地タスクには、追加のテキスト入力、つまりキャプションが必要です。
キャプションからフレーズの接地結果の形式: {'<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
task_prompt = "<CAPTION_TO_PHRASE_GROUNDING>"
results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")
物体検出
物体検出結果の形式: {'<OD>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['label1', 'label2', ...]} }
prompt = "<OD>"
run_example(prompt)
密な領域のキャプショニング
密な領域のキャプショニング結果の形式: {'<DENSE_REGION_CAPTION>' : {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['label1', 'label2', ...]} }
prompt = "<DENSE_REGION_CAPTION>"
run_example(prompt)
領域提案
密な領域のキャプショニング結果の形式: {'<REGION_PROPOSAL>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
prompt = "<REGION_PROPOSAL>"
run_example(prompt)
OCR
prompt = "<OCR>"
run_example(prompt)
領域付きOCR
領域付きOCRの出力形式: {'<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}
prompt = "<OCR_WITH_REGION>"
run_example(prompt)
より詳細な例については、ノートブックを参照してください。
📚 ドキュメント
Florence-2のゼロショット性能
次の表は、画像キャプショニングと物体検出の評価タスクにおける一般的なビジョン基礎モデルのゼロショット性能を示しています。これらのモデルは、学習段階で評価タスクの学習データに触れていません。
手法 | #パラメータ | COCO Cap. test CIDEr | NoCaps val CIDEr | TextCaps val CIDEr | COCO Det. val2017 mAP |
---|---|---|---|---|---|
Flamingo | 80B | 84.3 | - | - | - |
Florence-2-base | 0.23B | 133.0 | 118.7 | 70.1 | 34.7 |
Florence-2-large | 0.77B | 135.6 | 120.8 | 72.8 | 37.5 |
次の表は、他のビジョン言語評価タスクでの性能比較を続けています。
手法 | Flickr30k test R@1 | Refcoco val Accuracy | Refcoco test-A Accuracy | Refcoco test-B Accuracy | Refcoco+ val Accuracy | Refcoco+ test-A Accuracy | Refcoco+ test-B Accuracy | Refcocog val Accuracy | Refcocog test Accuracy | Refcoco RES val mIoU |
---|---|---|---|---|---|---|---|---|---|---|
Kosmos-2 | 78.7 | 52.3 | 57.4 | 47.3 | 45.5 | 50.7 | 42.2 | 60.6 | 61.7 | - |
Florence-2-base | 83.6 | 53.9 | 58.4 | 49.7 | 51.5 | 56.4 | 47.9 | 66.3 | 65.1 | 34.6 |
Florence-2-large | 84.4 | 56.3 | 61.6 | 51.4 | 53.6 | 57.9 | 49.9 | 68.0 | 67.0 | 35.8 |
Florence-2のファインチューニング性能
私たちは、Florence-2モデルを一連の下流タスクでファインチューニングし、幅広い下流タスクを実行できる2つの汎用モデルFlorence-2-base-ftとFlorence-2-large-ftを作成しました。
次の表は、専用モデルと汎用モデルのさまざまなキャプショニングおよびビジュアル質問応答(VQA)タスクでの性能を比較しています。専用モデルは各タスクに特化してファインチューニングされていますが、汎用モデルはすべてのタスクに対してタスク非依存的にファインチューニングされています。記号 "▲" は、外部OCRを入力として使用していることを示しています。
手法 | #パラメータ | COCO Caption Karpathy test CIDEr | NoCaps val CIDEr | TextCaps val CIDEr | VQAv2 test-dev Acc | TextVQA test-dev Acc | VizWiz VQA test-dev Acc |
---|---|---|---|---|---|---|---|
専用モデル | |||||||
CoCa | 2.1B | 143.6 | 122.4 | - | 82.3 | - | - |
BLIP-2 | 7.8B | 144.5 | 121.6 | - | 82.2 | - | - |
GIT2 | 5.1B | 145.0 | 126.9 | 148.6 | 81.7 | 67.3 | 71.0 |
Flamingo | 80B | 138.1 | - | - | 82.0 | 54.1 | 65.7 |
PaLI | 17B | 149.1 | 127.0 | 160.0▲ | 84.3 | 58.8 / 73.1▲ | 71.6 / 74.4▲ |
PaLI-X | 55B | 149.2 | 126.3 | 147.0 / 163.7▲ | 86.0 | 71.4 / 80.8▲ | 70.9 / 74.6▲ |
汎用モデル | |||||||
Unified-IO | 2.9B | - | 100.0 | - | 77.9 | - | 57.4 |
Florence-2-base-ft | 0.23B | 140.0 | 116.7 | 143.9 | 79.7 | 63.6 | 63.6 |
Florence-2-large-ft | 0.77B | 143.3 | 124.9 | 151.1 | 81.7 | 73.5 | 72.6 |
手法 | #パラメータ | COCO Det. val2017 mAP | Flickr30k test R@1 | RefCOCO val Accuracy | RefCOCO test-A Accuracy | RefCOCO test-B Accuracy | RefCOCO+ val Accuracy | RefCOCO+ test-A Accuracy | RefCOCO+ test-B Accuracy | RefCOCOg val Accuracy | RefCOCOg test Accuracy | RefCOCO RES val mIoU |
---|---|---|---|---|---|---|---|---|---|---|---|---|
専用モデル | ||||||||||||
SeqTR | - | - | - | 83.7 | 86.5 | 81.2 | 71.5 | 76.3 | 64.9 | 74.9 | 74.2 | - |
PolyFormer | - | - | - | 90.4 | 92.9 | 87.2 | 85.0 | 89.8 | 78.0 | 85.8 | 85.9 | 76.9 |
UNINEXT | 0.74B | 60.6 | - | 92.6 | 94.3 | 91.5 | 85.2 | 89.6 | 79.8 | 88.7 | 89.4 | - |
Ferret | 13B | - | - | 89.5 | 92.4 | 84.4 | 82.8 | 88.1 | 75.2 | 85.8 | 86.3 | - |
汎用モデル | ||||||||||||
UniTAB | - | - | - | 88.6 | 91.1 | 83.8 | 81.0 | 85.4 | 71.6 | 84.6 | 84.7 | - |
Florence-2-base-ft | 0.23B | 41.4 | 84.0 | 92.6 | 94.8 | 91.5 | 86.8 | 91.7 | 82.2 | 89.8 | 82.2 | 78.0 |
Florence-2-large-ft | 0.77B | 43.4 | 85.2 | 93.4 | 95.3 | 92.0 | 88.3 | 92.9 | 83.6 | 91.2 | 91.7 | 80.5 |
🔧 技術詳細
BibTexと引用情報
@article{xiao2023florence,
title={Florence-2: Advancing a unified representation for a variety of vision tasks},
author={Xiao, Bin and Wu, Haiping and Xu, Weijian and Dai, Xiyang and Hu, Houdong and Lu, Yumao and Zeng, Michael and Liu, Ce and Yuan, Lu},
journal={arXiv preprint arXiv:2311.06242},
year={2023}
}
📄 ライセンス
このモデルはMITライセンスの下で提供されています。








