Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
languages:
|
3 |
+
- en
|
4 |
+
license: bsd-3-clause
|
5 |
+
---
|
6 |
+
|
7 |
+
# BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation
|
8 |
+
|
9 |
+
Model card for image captioning pretrained on COCO dataset - base architecture (with ViT base backbone).
|
10 |
+
|
11 |
+
| ![BLIP.gif](https://s3.amazonaws.com/moonup/production/uploads/1670928184033-62441d1d9fdefb55a0b7d12c.gif) |
|
12 |
+
|:--:|
|
13 |
+
| <b> Pull figure from BLIP official repo | Image source: https://github.com/salesforce/BLIP </b>|
|
14 |
+
|
15 |
+
## TL;DR
|
16 |
+
|
17 |
+
Authors from the [paper](https://arxiv.org/abs/2201.12086) write in the abstract:
|
18 |
+
|
19 |
+
*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.*
|
20 |
+
|
21 |
+
## Usage
|
22 |
+
|
23 |
+
You can use this model for conditional and un-conditional image captioning
|
24 |
+
|
25 |
+
### Using the Pytorch model
|
26 |
+
|
27 |
+
#### Running the model on CPU
|
28 |
+
|
29 |
+
<details>
|
30 |
+
<summary> Click to expand </summary>
|
31 |
+
|
32 |
+
```python
|
33 |
+
|
34 |
+
from transformers import BlipProcessor, BlipForImageCaptioning
|
35 |
+
|
36 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
37 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-base")
|
38 |
+
|
39 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
40 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
41 |
+
|
42 |
+
# conditional image captioning
|
43 |
+
text = "a photography of"
|
44 |
+
inputs = processor(raw_image, text, return_tensors="pt")
|
45 |
+
|
46 |
+
out = model.generate(**inputs)
|
47 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
48 |
+
|
49 |
+
# unconditional image captioning
|
50 |
+
inputs = processor(raw_image, return_tensors="pt")
|
51 |
+
|
52 |
+
out = model.generate(**inputs)
|
53 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
54 |
+
```
|
55 |
+
</details>
|
56 |
+
|
57 |
+
#### Running the model on GPU
|
58 |
+
|
59 |
+
##### In full precision
|
60 |
+
|
61 |
+
<details>
|
62 |
+
<summary> Click to expand </summary>
|
63 |
+
|
64 |
+
```python
|
65 |
+
|
66 |
+
from transformers import BlipProcessor, BlipForImageCaptioning
|
67 |
+
|
68 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
69 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").to("cuda")
|
70 |
+
|
71 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
72 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
73 |
+
|
74 |
+
# conditional image captioning
|
75 |
+
text = "a photography of"
|
76 |
+
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
|
77 |
+
|
78 |
+
out = model.generate(**inputs)
|
79 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
80 |
+
|
81 |
+
# unconditional image captioning
|
82 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda")
|
83 |
+
|
84 |
+
out = model.generate(**inputs)
|
85 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
86 |
+
```
|
87 |
+
</details>
|
88 |
+
|
89 |
+
##### In half precision (`float16`)
|
90 |
+
|
91 |
+
<details>
|
92 |
+
<summary> Click to expand </summary>
|
93 |
+
|
94 |
+
```python
|
95 |
+
import torch
|
96 |
+
from transformers import BlipProcessor, BlipForImageCaptioning
|
97 |
+
|
98 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
99 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda")
|
100 |
+
|
101 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
102 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
103 |
+
|
104 |
+
# conditional image captioning
|
105 |
+
text = "a photography of"
|
106 |
+
inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16)
|
107 |
+
|
108 |
+
out = model.generate(**inputs)
|
109 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
110 |
+
|
111 |
+
# unconditional image captioning
|
112 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
|
113 |
+
|
114 |
+
out = model.generate(**inputs)
|
115 |
+
print(processor.decode(out[0], skip_special_tokens=True)
|
116 |
+
```
|
117 |
+
</details>
|
118 |
+
|
119 |
+
## BibTex and citation info
|
120 |
+
|
121 |
+
```
|
122 |
+
@misc{https://doi.org/10.48550/arxiv.2201.12086,
|
123 |
+
doi = {10.48550/ARXIV.2201.12086},
|
124 |
+
|
125 |
+
url = {https://arxiv.org/abs/2201.12086},
|
126 |
+
|
127 |
+
author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
|
128 |
+
|
129 |
+
keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
130 |
+
|
131 |
+
title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
|
132 |
+
|
133 |
+
publisher = {arXiv},
|
134 |
+
|
135 |
+
year = {2022},
|
136 |
+
|
137 |
+
copyright = {Creative Commons Attribution 4.0 International}
|
138 |
+
}
|
139 |
+
```
|