merve HF Staff commited on
Commit
4271c66
·
verified ·
1 Parent(s): 1dabadc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +194 -168
README.md CHANGED
@@ -1,199 +1,225 @@
1
  ---
 
 
 
 
 
2
  library_name: transformers
3
- tags: []
4
  ---
5
 
6
- # Model Card for Model ID
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
 
 
 
 
 
 
 
70
  ## How to Get Started with the Model
71
 
72
  Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
 
 
 
170
 
171
- ## Citation [optional]
 
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
174
 
175
- **BibTeX:**
 
 
 
 
 
176
 
177
- [More Information Needed]
 
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
 
 
 
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
 
 
 
 
198
 
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: mit
3
+ license_link: https://huggingface.co/microsoft/Florence-2-large/resolve/main/LICENSE
4
+ pipeline_tag: image-text-to-text
5
+ tags:
6
+ - vision
7
  library_name: transformers
 
8
  ---
9
 
10
+ > [!NOTE]
11
+ > This is the repository for official transformers converted checkpoint of Microsoft's Florence model.
12
 
13
+ # Florence-2: Advancing a Unified Representation for a Variety of Vision Tasks
14
 
15
+ ## Model Summary
16
 
17
+ **This is a continued pretrained version of Florence-2-large model with 4k context length, only 0.1B samples are used for continue pretraining, thus it might not be trained well. In addition, OCR task has been updated with line separator ('\n'). COCO OD AP 39.8**
18
 
19
+ Florence-2 is an advanced vision foundation model that uses a prompt-based approach to handle a wide range of vision and vision-language tasks. Florence-2 can interpret simple text prompts to perform tasks like captioning, object detection, and segmentation. It leverages our FLD-5B dataset, containing 5.4 billion annotations across 126 million images, to master multi-task learning. The model's sequence-to-sequence architecture enables it to excel in both zero-shot and fine-tuned settings, proving to be a competitive vision foundation model.
20
 
21
+ Resources and Technical Documentation:
22
+ + [Florence-2 technical report](https://arxiv.org/abs/2311.06242).
23
+ + [Jupyter Notebook for inference and visualization of Florence-2-large](https://huggingface.co/microsoft/Florence-2-large/blob/main/sample_inference.ipynb)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ | Model | Model size | Model Description |
26
+ | ------- | ------------- | ------------- |
27
+ | Florence-2-base[[HF]](https://huggingface.co/florence-community/Florence-2-base) | 0.23B | Pretrained model with FLD-5B
28
+ | Florence-2-large[[HF]](https://huggingface.co/florence-community/Florence-2-large) | 0.77B | Pretrained model with FLD-5B
29
+ | Florence-2-base-ft[[HF]](https://huggingface.co/florence-community/Florence-2-base-ft) | 0.23B | Finetuned model on a colletion of downstream tasks
30
+ | Florence-2-large-ft[[HF]](https://huggingface.co/florence-community/Florence-2-large-ft) | 0.77B | Finetuned model on a colletion of downstream tasks
31
+
32
  ## How to Get Started with the Model
33
 
34
  Use the code below to get started with the model.
35
 
36
+ ```python
37
+ import torch
38
+ import requests
39
+ from PIL import Image
40
+ from transformers import AutoProcessor, Florence2ForConditionalGeneration, BitsAndBytesConfig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
 
42
 
43
+ model = Florence2ForConditionalGeneration.from_pretrained(
44
+ "florence-community/Florence-2-large",
45
+ dtype=torch.bfloat16,
46
+ device_map="auto",
47
+ )
48
+ processor = AutoProcessor.from_pretrained("florence-community/Florence-2-large")
49
 
50
+ url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
51
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
52
 
53
+ task_prompt = "<OD>"
54
+ inputs = processor(text=task_prompt, images=image, return_tensors="pt").to(model.device, torch.bfloat16)
55
 
56
+ generated_ids = model.generate(
57
+ **inputs,
58
+ max_new_tokens=1024,
59
+ num_beams=3,
60
+ )
61
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
62
 
63
+ image_size = image.size
64
+ parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=image_size)
65
 
66
+ print(parsed_answer)
67
 
68
+ ```
69
 
 
70
 
71
+ ## Tasks
72
 
73
+ This model is capable of performing different tasks through changing the prompts.
74
 
75
+ First, let's define a function to run a prompt.
76
 
77
+ Here are the tasks `Florence-2` could perform:
78
+
79
+ <details>
80
+ <summary> Click to expand </summary>
81
 
 
82
 
 
83
 
84
+ ### Caption
85
+ ```python
86
+ prompt = "<CAPTION>"
87
+ run_example(prompt)
88
+ ```
89
 
90
+ ### Detailed Caption
91
+ ```python
92
+ prompt = "<DETAILED_CAPTION>"
93
+ run_example(prompt)
94
+ ```
95
+
96
+ ### More Detailed Caption
97
+ ```python
98
+ prompt = "<MORE_DETAILED_CAPTION>"
99
+ run_example(prompt)
100
+ ```
101
+
102
+ ### Caption to Phrase Grounding
103
+ caption to phrase grounding task requires additional text input, i.e. caption.
104
+
105
+ Caption to phrase grounding results format:
106
+ {'\<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
107
+ ```python
108
+ task_prompt = "<CAPTION_TO_PHRASE_GROUNDING>"
109
+ results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")
110
+ ```
111
+
112
+ ### Object Detection
113
+
114
+ OD results format:
115
+ {'\<OD>': {'bboxes': [[x1, y1, x2, y2], ...],
116
+ 'labels': ['label1', 'label2', ...]} }
117
+
118
+ ```python
119
+ prompt = "<OD>"
120
+ run_example(prompt)
121
+ ```
122
+
123
+ ### Dense Region Caption
124
+ Dense region caption results format:
125
+ {'\<DENSE_REGION_CAPTION>' : {'bboxes': [[x1, y1, x2, y2], ...],
126
+ 'labels': ['label1', 'label2', ...]} }
127
+ ```python
128
+ prompt = "<DENSE_REGION_CAPTION>"
129
+ run_example(prompt)
130
+ ```
131
+
132
+ ### Region proposal
133
+ Dense region caption results format:
134
+ {'\<REGION_PROPOSAL>': {'bboxes': [[x1, y1, x2, y2], ...],
135
+ 'labels': ['', '', ...]}}
136
+ ```python
137
+ prompt = "<REGION_PROPOSAL>"
138
+ run_example(prompt)
139
+ ```
140
+
141
+ ### OCR
142
+
143
+ ```python
144
+ prompt = "<OCR>"
145
+ run_example(prompt)
146
+ ```
147
+
148
+ ### OCR with Region
149
+ OCR with region output format:
150
+ {'\<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}
151
+ ```python
152
+ prompt = "<OCR_WITH_REGION>"
153
+ run_example(prompt)
154
+ ```
155
+
156
+
157
+ </details>
158
+
159
+ # Benchmarks
160
+
161
+ ## Florence-2 Zero-shot performance
162
+
163
+ The following table presents the zero-shot performance of generalist vision foundation models on image captioning and object detection evaluation tasks. These models have not been exposed to the training data of the evaluation tasks during their training phase.
164
+
165
+ | Method | #params | COCO Cap. test CIDEr | NoCaps val CIDEr | TextCaps val CIDEr | COCO Det. val2017 mAP |
166
+ |--------|---------|----------------------|------------------|--------------------|-----------------------|
167
+ | Flamingo | 80B | 84.3 | - | - | - |
168
+ | Florence-2-base| 0.23B | 133.0 | 118.7 | 70.1 | 34.7 |
169
+ | Florence-2-large| 0.77B | 135.6 | 120.8 | 72.8 | 37.5 |
170
+
171
+
172
+ The following table continues the comparison with performance on other vision-language evaluation tasks.
173
+
174
+ | Method | 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 |
175
+ |--------|----------------------|----------------------|-------------------------|-------------------------|-----------------------|--------------------------|--------------------------|-----------------------|------------------------|----------------------|
176
+ | Kosmos-2 | 78.7 | 52.3 | 57.4 | 47.3 | 45.5 | 50.7 | 42.2 | 60.6 | 61.7 | - |
177
+ | Florence-2-base | 83.6 | 53.9 | 58.4 | 49.7 | 51.5 | 56.4 | 47.9 | 66.3 | 65.1 | 34.6 |
178
+ | Florence-2-large | 84.4 | 56.3 | 61.6 | 51.4 | 53.6 | 57.9 | 49.9 | 68.0 | 67.0 | 35.8 |
179
+
180
+
181
+
182
+ ## Florence-2 finetuned performance
183
+
184
+ We finetune Florence-2 models with a collection of downstream tasks, resulting two generalist models *Florence-2-base-ft* and *Florence-2-large-ft* that can conduct a wide range of downstream tasks.
185
+
186
+ The table below compares the performance of specialist and generalist models on various captioning and Visual Question Answering (VQA) tasks. Specialist models are fine-tuned specifically for each task, whereas generalist models are fine-tuned in a task-agnostic manner across all tasks. The symbol "▲" indicates the usage of external OCR as input.
187
+
188
+ | Method | # Params | COCO Caption Karpathy test CIDEr | NoCaps val CIDEr | TextCaps val CIDEr | VQAv2 test-dev Acc | TextVQA test-dev Acc | VizWiz VQA test-dev Acc |
189
+ |----------------|----------|-----------------------------------|------------------|--------------------|--------------------|----------------------|-------------------------|
190
+ | **Specialist Models** | | | | | | | |
191
+ | CoCa | 2.1B | 143.6 | 122.4 | - | 82.3 | - | - |
192
+ | BLIP-2 | 7.8B | 144.5 | 121.6 | - | 82.2 | - | - |
193
+ | GIT2 | 5.1B | 145.0 | 126.9 | 148.6 | 81.7 | 67.3 | 71.0 |
194
+ | Flamingo | 80B | 138.1 | - | - | 82.0 | 54.1 | 65.7 |
195
+ | PaLI | 17B | 149.1 | 127.0 | 160.0▲ | 84.3 | 58.8 / 73.1▲ | 71.6 / 74.4▲ |
196
+ | PaLI-X | 55B | 149.2 | 126.3 | 147.0 / 163.7▲ | 86.0 | 71.4 / 80.8▲ | 70.9 / 74.6▲ |
197
+ | **Generalist Models** | | | | | | | |
198
+ | Unified-IO | 2.9B | - | 100.0 | - | 77.9 | - | 57.4 |
199
+ | Florence-2-base-ft | 0.23B | 140.0 | 116.7 | 143.9 | 79.7 | 63.6 | 63.6 |
200
+ | Florence-2-large-ft | 0.77B | 143.3 | 124.9 | 151.1 | 81.7 | 73.5 | 72.6 |
201
+
202
+
203
+ | Method | # Params | 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 |
204
+ |----------------------|----------|-----------------------|--------------------|----------------------|-------------------------|-------------------------|------------------------|---------------------------|---------------------------|------------------------|-----------------------|------------------------|
205
+ | **Specialist Models** | | | | | | | | | | | | |
206
+ | SeqTR | - | - | - | 83.7 | 86.5 | 81.2 | 71.5 | 76.3 | 64.9 | 74.9 | 74.2 | - |
207
+ | PolyFormer | - | - | - | 90.4 | 92.9 | 87.2 | 85.0 | 89.8 | 78.0 | 85.8 | 85.9 | 76.9 |
208
+ | UNINEXT | 0.74B | 60.6 | - | 92.6 | 94.3 | 91.5 | 85.2 | 89.6 | 79.8 | 88.7 | 89.4 | - |
209
+ | Ferret | 13B | - | - | 89.5 | 92.4 | 84.4 | 82.8 | 88.1 | 75.2 | 85.8 | 86.3 | - |
210
+ | **Generalist Models** | | | | | | | | | | | | |
211
+ | UniTAB | - | - | - | 88.6 | 91.1 | 83.8 | 81.0 | 85.4 | 71.6 | 84.6 | 84.7 | - |
212
+ | 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 |
213
+ | 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 |
214
+
215
+
216
+ ## BibTex and citation info
217
+
218
+ ```
219
+ @article{xiao2023florence,
220
+ title={Florence-2: Advancing a unified representation for a variety of vision tasks},
221
+ 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},
222
+ journal={arXiv preprint arXiv:2311.06242},
223
+ year={2023}
224
+ }
225
+ ```