ybelkada HF staff commited on
Commit
8599e64
1 Parent(s): 0b9ee70

Create README.md

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