ybelkada commited on
Commit
e5e72a4
1 Parent(s): 31f0649

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +124 -0
README.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-text-matching
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 BLIP trained on image-text matching - base architecture (with ViT base backbone) trained on COCO dataset.
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, BlipForImageTextRetrieval
38
+
39
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
40
+ model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco")
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
+ question = "A woman and a dog sitting together in a beach."
46
+ inputs = processor(raw_image, question, return_tensors="pt")
47
+
48
+ itm_scores = model(**inputs)[0]
49
+ cosine_score = model(**inputs, use_itm_head=False)[0]
50
+ ```
51
+ </details>
52
+
53
+ #### Running the model on GPU
54
+
55
+ ##### In full precision
56
+
57
+ <details>
58
+ <summary> Click to expand </summary>
59
+
60
+ ```python
61
+ import requests
62
+ from PIL import Image
63
+ from transformers import BlipProcessor, BlipForImageTextRetrieval
64
+
65
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
66
+ model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco").to("cuda")
67
+
68
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
69
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
70
+
71
+ question = "A woman and a dog sitting together in a beach."
72
+ inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
73
+
74
+ itm_scores = model(**inputs)[0]
75
+ cosine_score = model(**inputs, use_itm_head=False)[0]
76
+ ```
77
+ </details>
78
+
79
+ ##### In half precision (`float16`)
80
+
81
+ <details>
82
+ <summary> Click to expand </summary>
83
+
84
+ ```python
85
+ import torch
86
+ import requests
87
+ from PIL import Image
88
+ from transformers import BlipProcessor, BlipForImageTextRetrieval
89
+
90
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-base-coco")
91
+ model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-base-coco", torch_dtype=torch.float16).to("cuda")
92
+
93
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
94
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
95
+
96
+ question = "A woman and a dog sitting together in a beach."
97
+ inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16)
98
+
99
+ itm_scores = model(**inputs)[0]
100
+ cosine_score = model(**inputs, use_itm_head=False)[0]
101
+ ```
102
+ </details>
103
+
104
+ ## BibTex and citation info
105
+
106
+ ```
107
+ @misc{https://doi.org/10.48550/arxiv.2201.12086,
108
+ doi = {10.48550/ARXIV.2201.12086},
109
+
110
+ url = {https://arxiv.org/abs/2201.12086},
111
+
112
+ author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
113
+
114
+ keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
115
+
116
+ title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
117
+
118
+ publisher = {arXiv},
119
+
120
+ year = {2022},
121
+
122
+ copyright = {Creative Commons Attribution 4.0 International}
123
+ }
124
+ ```