Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- visual-question-answering
|
4 |
+
languages:
|
5 |
+
- en
|
6 |
+
license: bsd-3-clause
|
7 |
+
---
|
8 |
+
|
9 |
+
# BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation
|
10 |
+
|
11 |
+
Model card for image captioning pretrained on COCO dataset - base architecture (with ViT large backbone).
|
12 |
+
|
13 |
+
| ![BLIP.gif](https://s3.amazonaws.com/moonup/production/uploads/1670928184033-62441d1d9fdefb55a0b7d12c.gif) |
|
14 |
+
|:--:|
|
15 |
+
| <b> Pull figure from BLIP official repo | Image source: https://github.com/salesforce/BLIP </b>|
|
16 |
+
|
17 |
+
## TL;DR
|
18 |
+
|
19 |
+
Authors from the [paper](https://arxiv.org/abs/2201.12086) write in the abstract:
|
20 |
+
|
21 |
+
*Vision-Language Pre-training (VLP) has advanced the performance for many vision-language tasks. However, most existing pre-trained models only excel in either understanding-based tasks or generation-based tasks. Furthermore, performance improvement has been largely achieved by scaling up the dataset with noisy image-text pairs collected from the web, which is a suboptimal source of supervision. In this paper, we propose BLIP, a new VLP framework which transfers flexibly to both vision-language understanding and generation tasks. BLIP effectively utilizes the noisy web data by bootstrapping the captions, where a captioner generates synthetic captions and a filter removes the noisy ones. We achieve state-of-the-art results on a wide range of vision-language tasks, such as image-text retrieval (+2.7% in average recall@1), image captioning (+2.8% in CIDEr), and VQA (+1.6% in VQA score). BLIP also demonstrates strong generalization ability when directly transferred to videolanguage tasks in a zero-shot manner. Code, models, and datasets are released.*
|
22 |
+
|
23 |
+
## Usage
|
24 |
+
|
25 |
+
You can use this model for conditional and un-conditional image captioning
|
26 |
+
|
27 |
+
### Using the Pytorch model
|
28 |
+
|
29 |
+
#### Running the model on CPU
|
30 |
+
|
31 |
+
<details>
|
32 |
+
<summary> Click to expand </summary>
|
33 |
+
|
34 |
+
```python
|
35 |
+
import requests
|
36 |
+
from PIL import Image
|
37 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
38 |
+
|
39 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
40 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
41 |
+
|
42 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
43 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
44 |
+
|
45 |
+
# conditional image captioning
|
46 |
+
text = "a photography of"
|
47 |
+
inputs = processor(raw_image, text, return_tensors="pt")
|
48 |
+
|
49 |
+
out = model.generate(**inputs)
|
50 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
51 |
+
# >>> a photography of a woman and her dog
|
52 |
+
|
53 |
+
# unconditional image captioning
|
54 |
+
inputs = processor(raw_image, return_tensors="pt")
|
55 |
+
|
56 |
+
out = model.generate(**inputs)
|
57 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
58 |
+
>>> a woman sitting on the beach with her dog
|
59 |
+
```
|
60 |
+
</details>
|
61 |
+
|
62 |
+
#### Running the model on GPU
|
63 |
+
|
64 |
+
##### In full precision
|
65 |
+
|
66 |
+
<details>
|
67 |
+
<summary> Click to expand </summary>
|
68 |
+
|
69 |
+
```python
|
70 |
+
import requests
|
71 |
+
from PIL import Image
|
72 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
73 |
+
|
74 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
75 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-large").to("cuda")
|
76 |
+
|
77 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
78 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
79 |
+
|
80 |
+
# conditional image captioning
|
81 |
+
text = "a photography of"
|
82 |
+
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
|
83 |
+
|
84 |
+
out = model.generate(**inputs)
|
85 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
86 |
+
# >>> a photography of a woman and her dog
|
87 |
+
|
88 |
+
# unconditional image captioning
|
89 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda")
|
90 |
+
|
91 |
+
out = model.generate(**inputs)
|
92 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
93 |
+
>>> a woman sitting on the beach with her dog
|
94 |
+
```
|
95 |
+
</details>
|
96 |
+
|
97 |
+
##### In half precision (`float16`)
|
98 |
+
|
99 |
+
<details>
|
100 |
+
<summary> Click to expand </summary>
|
101 |
+
|
102 |
+
```python
|
103 |
+
import torch
|
104 |
+
import requests
|
105 |
+
from PIL import Image
|
106 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
107 |
+
|
108 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
109 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large", torch_dtype=torch.float16).to("cuda")
|
110 |
+
|
111 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
112 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
113 |
+
|
114 |
+
# conditional image captioning
|
115 |
+
text = "a photography of"
|
116 |
+
inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16)
|
117 |
+
|
118 |
+
out = model.generate(**inputs)
|
119 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
120 |
+
# >>> a photography of a woman and her dog
|
121 |
+
|
122 |
+
# unconditional image captioning
|
123 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
|
124 |
+
|
125 |
+
out = model.generate(**inputs)
|
126 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
127 |
+
>>> a woman sitting on the beach with her dog
|
128 |
+
```
|
129 |
+
</details>
|
130 |
+
|
131 |
+
## BibTex and citation info
|
132 |
+
|
133 |
+
```
|
134 |
+
@misc{https://doi.org/10.48550/arxiv.2201.12086,
|
135 |
+
doi = {10.48550/ARXIV.2201.12086},
|
136 |
+
|
137 |
+
url = {https://arxiv.org/abs/2201.12086},
|
138 |
+
|
139 |
+
author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
|
140 |
+
|
141 |
+
keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
142 |
+
|
143 |
+
title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
|
144 |
+
|
145 |
+
publisher = {arXiv},
|
146 |
+
|
147 |
+
year = {2022},
|
148 |
+
|
149 |
+
copyright = {Creative Commons Attribution 4.0 International}
|
150 |
+
}
|
151 |
+
```
|