Wang9738 commited on
Commit
4dace3b
1 Parent(s): 7adf43a

Upload 9 files

Browse files
README.md CHANGED
@@ -1,3 +1,158 @@
1
  ---
2
- license: afl-3.0
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: other
3
+ tags:
4
+ - image-captioning
5
+ inference: false
6
+ languages:
7
+ - en
8
+ license: bsd-3-clause
9
+ datasets:
10
+ - ybelkada/football-dataset
11
  ---
12
+
13
+ # BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation
14
+
15
+ Model card for image captioning pretrained on COCO dataset - base architecture (with ViT base backbone) - and fine-tuned on
16
+ [football dataset](https://huggingface.co/datasets/ybelkada/football-dataset).
17
+
18
+ Google Colab notebook for fine-tuning: https://colab.research.google.com/drive/1lbqiSiA0sDF7JDWPeS0tccrM85LloVha?usp=sharing
19
+
20
+ | ![BLIP.gif](https://s3.amazonaws.com/moonup/production/uploads/1670928184033-62441d1d9fdefb55a0b7d12c.gif) |
21
+ |:--:|
22
+ | <b> Pull figure from BLIP official repo | Image source: https://github.com/salesforce/BLIP </b>|
23
+
24
+ ## TL;DR
25
+
26
+ Authors from the [paper](https://arxiv.org/abs/2201.12086) write in the abstract:
27
+
28
+ *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.*
29
+
30
+ ## Usage
31
+
32
+ You can use this model for conditional and un-conditional image captioning
33
+
34
+ ### Using the Pytorch model
35
+
36
+ #### Running the model on CPU
37
+
38
+ <details>
39
+ <summary> Click to expand </summary>
40
+
41
+ ```python
42
+ import requests
43
+ from PIL import Image
44
+ from transformers import BlipProcessor, BlipForConditionalGeneration
45
+
46
+ processor = BlipProcessor.from_pretrained("ybelkada/blip-image-captioning-base")
47
+ model = BlipForConditionalGeneration.from_pretrained("ybelkada/blip-image-captioning-base")
48
+
49
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
50
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
51
+
52
+ # conditional image captioning
53
+ text = "a photography of"
54
+ inputs = processor(raw_image, text, return_tensors="pt")
55
+
56
+ out = model.generate(**inputs)
57
+ print(processor.decode(out[0], skip_special_tokens=True))
58
+ # >>> a photography of a woman and her dog
59
+
60
+ # unconditional image captioning
61
+ inputs = processor(raw_image, return_tensors="pt")
62
+
63
+ out = model.generate(**inputs)
64
+ print(processor.decode(out[0], skip_special_tokens=True))
65
+ >>> a woman sitting on the beach with her dog
66
+ ```
67
+ </details>
68
+
69
+ #### Running the model on GPU
70
+
71
+ ##### In full precision
72
+
73
+ <details>
74
+ <summary> Click to expand </summary>
75
+
76
+ ```python
77
+ import requests
78
+ from PIL import Image
79
+ from transformers import BlipProcessor, BlipForConditionalGeneration
80
+
81
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
82
+ model = BlipForConditionalGeneration.from_pretrained("Salesfoce/blip-image-captioning-base").to("cuda")
83
+
84
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
85
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
86
+
87
+ # conditional image captioning
88
+ text = "a photography of"
89
+ inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
90
+
91
+ out = model.generate(**inputs)
92
+ print(processor.decode(out[0], skip_special_tokens=True))
93
+ # >>> a photography of a woman and her dog
94
+
95
+ # unconditional image captioning
96
+ inputs = processor(raw_image, return_tensors="pt").to("cuda")
97
+
98
+ out = model.generate(**inputs)
99
+ print(processor.decode(out[0], skip_special_tokens=True))
100
+ >>> a woman sitting on the beach with her dog
101
+ ```
102
+ </details>
103
+
104
+ ##### In half precision (`float16`)
105
+
106
+ <details>
107
+ <summary> Click to expand </summary>
108
+
109
+ ```python
110
+ import torch
111
+ import requests
112
+ from PIL import Image
113
+ from transformers import BlipProcessor, BlipForConditionalGeneration
114
+
115
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
116
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base", torch_dtype=torch.float16).to("cuda")
117
+
118
+ img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
119
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
120
+
121
+ # conditional image captioning
122
+ text = "a photography of"
123
+ inputs = processor(raw_image, text, 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 photography of a woman and her dog
128
+
129
+ # unconditional image captioning
130
+ inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
131
+
132
+ out = model.generate(**inputs)
133
+ print(processor.decode(out[0], skip_special_tokens=True))
134
+ >>> a woman sitting on the beach with her dog
135
+ ```
136
+ </details>
137
+
138
+ ## BibTex and citation info
139
+
140
+ ```
141
+ @misc{https://doi.org/10.48550/arxiv.2201.12086,
142
+ doi = {10.48550/ARXIV.2201.12086},
143
+
144
+ url = {https://arxiv.org/abs/2201.12086},
145
+
146
+ author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
147
+
148
+ keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
149
+
150
+ title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
151
+
152
+ publisher = {arXiv},
153
+
154
+ year = {2022},
155
+
156
+ copyright = {Creative Commons Attribution 4.0 International}
157
+ }
158
+ ```
config.json ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_commit_hash": "3007fbe8c3bbd0b8121111dee8e8d06c0f2783c9",
3
+ "_name_or_path": "Salesforce/blip-image-captioning-base",
4
+ "architectures": [
5
+ "BlipForConditionalGeneration"
6
+ ],
7
+ "image_text_hidden_size": 256,
8
+ "initializer_factor": 1.0,
9
+ "initializer_range": 0.02,
10
+ "logit_scale_init_value": 2.6592,
11
+ "model_type": "blip",
12
+ "projection_dim": 512,
13
+ "text_config": {
14
+ "_name_or_path": "",
15
+ "add_cross_attention": false,
16
+ "architectures": null,
17
+ "attention_probs_dropout_prob": 0.0,
18
+ "bad_words_ids": null,
19
+ "begin_suppress_tokens": null,
20
+ "bos_token_id": 30522,
21
+ "chunk_size_feed_forward": 0,
22
+ "cross_attention_hidden_size": null,
23
+ "decoder_start_token_id": null,
24
+ "diversity_penalty": 0.0,
25
+ "do_sample": false,
26
+ "early_stopping": false,
27
+ "encoder_hidden_size": 768,
28
+ "encoder_no_repeat_ngram_size": 0,
29
+ "eos_token_id": 2,
30
+ "exponential_decay_length_penalty": null,
31
+ "finetuning_task": null,
32
+ "forced_bos_token_id": null,
33
+ "forced_eos_token_id": null,
34
+ "hidden_act": "gelu",
35
+ "hidden_dropout_prob": 0.0,
36
+ "hidden_size": 768,
37
+ "id2label": {
38
+ "0": "LABEL_0",
39
+ "1": "LABEL_1"
40
+ },
41
+ "initializer_factor": 1.0,
42
+ "initializer_range": 0.02,
43
+ "intermediate_size": 3072,
44
+ "is_decoder": true,
45
+ "is_encoder_decoder": false,
46
+ "label2id": {
47
+ "LABEL_0": 0,
48
+ "LABEL_1": 1
49
+ },
50
+ "layer_norm_eps": 1e-12,
51
+ "length_penalty": 1.0,
52
+ "max_length": 20,
53
+ "max_position_embeddings": 512,
54
+ "min_length": 0,
55
+ "model_type": "blip_text_model",
56
+ "no_repeat_ngram_size": 0,
57
+ "num_attention_heads": 8,
58
+ "num_beam_groups": 1,
59
+ "num_beams": 1,
60
+ "num_hidden_layers": 12,
61
+ "num_return_sequences": 1,
62
+ "output_attentions": false,
63
+ "output_hidden_states": false,
64
+ "output_scores": false,
65
+ "pad_token_id": 0,
66
+ "prefix": null,
67
+ "problem_type": null,
68
+ "projection_dim": 768,
69
+ "pruned_heads": {},
70
+ "remove_invalid_values": false,
71
+ "repetition_penalty": 1.0,
72
+ "return_dict": true,
73
+ "return_dict_in_generate": false,
74
+ "sep_token_id": 102,
75
+ "suppress_tokens": null,
76
+ "task_specific_params": null,
77
+ "temperature": 1.0,
78
+ "tf_legacy_loss": false,
79
+ "tie_encoder_decoder": false,
80
+ "tie_word_embeddings": true,
81
+ "tokenizer_class": null,
82
+ "top_k": 50,
83
+ "top_p": 1.0,
84
+ "torch_dtype": null,
85
+ "torchscript": false,
86
+ "transformers_version": "4.26.0.dev0",
87
+ "typical_p": 1.0,
88
+ "use_bfloat16": false,
89
+ "use_cache": true,
90
+ "vocab_size": 30524
91
+ },
92
+ "torch_dtype": "float32",
93
+ "transformers_version": null,
94
+ "vision_config": {
95
+ "_name_or_path": "",
96
+ "add_cross_attention": false,
97
+ "architectures": null,
98
+ "attention_dropout": 0.0,
99
+ "bad_words_ids": null,
100
+ "begin_suppress_tokens": null,
101
+ "bos_token_id": null,
102
+ "chunk_size_feed_forward": 0,
103
+ "cross_attention_hidden_size": null,
104
+ "decoder_start_token_id": null,
105
+ "diversity_penalty": 0.0,
106
+ "do_sample": false,
107
+ "dropout": 0.0,
108
+ "early_stopping": false,
109
+ "encoder_no_repeat_ngram_size": 0,
110
+ "eos_token_id": null,
111
+ "exponential_decay_length_penalty": null,
112
+ "finetuning_task": null,
113
+ "forced_bos_token_id": null,
114
+ "forced_eos_token_id": null,
115
+ "hidden_act": "gelu",
116
+ "hidden_size": 768,
117
+ "id2label": {
118
+ "0": "LABEL_0",
119
+ "1": "LABEL_1"
120
+ },
121
+ "image_size": 384,
122
+ "initializer_factor": 1.0,
123
+ "initializer_range": 0.02,
124
+ "intermediate_size": 3072,
125
+ "is_decoder": false,
126
+ "is_encoder_decoder": false,
127
+ "label2id": {
128
+ "LABEL_0": 0,
129
+ "LABEL_1": 1
130
+ },
131
+ "layer_norm_eps": 1e-05,
132
+ "length_penalty": 1.0,
133
+ "max_length": 20,
134
+ "min_length": 0,
135
+ "model_type": "blip_vision_model",
136
+ "no_repeat_ngram_size": 0,
137
+ "num_attention_heads": 12,
138
+ "num_beam_groups": 1,
139
+ "num_beams": 1,
140
+ "num_channels": 3,
141
+ "num_hidden_layers": 12,
142
+ "num_return_sequences": 1,
143
+ "output_attentions": false,
144
+ "output_hidden_states": false,
145
+ "output_scores": false,
146
+ "pad_token_id": null,
147
+ "patch_size": 16,
148
+ "prefix": null,
149
+ "problem_type": null,
150
+ "projection_dim": 512,
151
+ "pruned_heads": {},
152
+ "remove_invalid_values": false,
153
+ "repetition_penalty": 1.0,
154
+ "return_dict": true,
155
+ "return_dict_in_generate": false,
156
+ "sep_token_id": null,
157
+ "suppress_tokens": null,
158
+ "task_specific_params": null,
159
+ "temperature": 1.0,
160
+ "tf_legacy_loss": false,
161
+ "tie_encoder_decoder": false,
162
+ "tie_word_embeddings": true,
163
+ "tokenizer_class": null,
164
+ "top_k": 50,
165
+ "top_p": 1.0,
166
+ "torch_dtype": null,
167
+ "torchscript": false,
168
+ "transformers_version": "4.26.0.dev0",
169
+ "typical_p": 1.0,
170
+ "use_bfloat16": false
171
+ }
172
+ }
gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
preprocessor_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": true,
3
+ "do_normalize": true,
4
+ "do_rescale": true,
5
+ "do_resize": true,
6
+ "image_mean": [
7
+ 0.48145466,
8
+ 0.4578275,
9
+ 0.40821073
10
+ ],
11
+ "image_processor_type": "BlipImageProcessor",
12
+ "image_std": [
13
+ 0.26862954,
14
+ 0.26130258,
15
+ 0.27577711
16
+ ],
17
+ "processor_class": "BlipProcessor",
18
+ "resample": 3,
19
+ "rescale_factor": 0.00392156862745098,
20
+ "size": {
21
+ "height": 384,
22
+ "width": 384
23
+ }
24
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa5948a0f63017ec746980aa998b8084c2b5b079e9b8383ed0a412b6802c1f6b
3
+ size 989827505
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "do_basic_tokenize": true,
4
+ "do_lower_case": true,
5
+ "mask_token": "[MASK]",
6
+ "model_max_length": 512,
7
+ "name_or_path": "Salesforce/blip-image-captioning-base",
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "processor_class": "BlipProcessor",
11
+ "sep_token": "[SEP]",
12
+ "special_tokens_map_file": null,
13
+ "strip_accents": null,
14
+ "tokenize_chinese_chars": true,
15
+ "tokenizer_class": "BertTokenizer",
16
+ "trust_remote_code": false,
17
+ "unk_token": "[UNK]"
18
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff