Initial update
Browse files- README.md +118 -1
- config.json +55 -0
- preprocessor_config.json +6 -0
- pytorch_model.bin +3 -0
- tokenizer.json +0 -0
- vocab.json +0 -0
README.md
CHANGED
@@ -1,4 +1,121 @@
|
|
1 |
---
|
|
|
|
|
|
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: en
|
3 |
+
tags:
|
4 |
+
- bridgetower
|
5 |
license: mit
|
6 |
+
datasets:
|
7 |
+
- conceptual_captions
|
8 |
+
- sbu_captions
|
9 |
+
- visual_genome
|
10 |
+
- mscoco_captions
|
11 |
---
|
12 |
+
|
13 |
+
# BridgeTower large-itm-mlm model
|
14 |
+
|
15 |
+
The BridgeTower model was proposed in "BridgeTower: Building Bridges Between Encoders in Vision-Language Representative Learning" by Xiao Xu, Chenfei Wu, Shachar Rosenman, Vasudev Lal, Wanxiang Che, Nan Duan.
|
16 |
+
The model was pretrained on English language using masked language modeling (MLM) and image text matching (ITM)objectives. It was introduced in
|
17 |
+
[this paper](https://arxiv.org/pdf/2206.08657.pdf) and first released in
|
18 |
+
[this repository](https://github.com/microsoft/BridgeTower).
|
19 |
+
|
20 |
+
BridgeTower got accepted to [AAAI'23](https://aaai.org/Conferences/AAAI-23/).
|
21 |
+
|
22 |
+
## Model description
|
23 |
+
|
24 |
+
The abstract from the paper is the following:
|
25 |
+
Vision-Language (VL) models with the Two-Tower architecture have dominated visual-language representation learning in recent years. Current VL models either use lightweight uni-modal encoders and learn to extract, align and fuse both modalities simultaneously in a deep cross-modal encoder, or feed the last-layer uni-modal representations from the deep pre-trained uni-modal encoders into the top cross-modal encoder. Both approaches potentially restrict vision-language representation learning and limit model performance. In this paper, we propose BridgeTower, which introduces multiple bridge layers that build a connection between the top layers of uni-modal encoders and each layer of the cross-modal encoder. This enables effective bottom-up cross-modal alignment and fusion between visual and textual representations of different semantic levels of pre-trained uni-modal encoders in the cross-modal encoder. Pre-trained with only 4M images, BridgeTower achieves state-of-the-art performance on various downstream vision-language tasks. In particular, on the VQAv2 test-std set, BridgeTower achieves an accuracy of 78.73%, outperforming the previous state-of-the-art model METER by 1.09% with the same pre-training data and almost negligible additional parameters and computational costs. Notably, when further scaling the model, BridgeTower achieves an accuracy of 81.15%, surpassing models that are pre-trained on orders-of-magnitude larger datasets.
|
26 |
+
|
27 |
+
## Intended uses & limitations(TODO)
|
28 |
+
|
29 |
+
|
30 |
+
### How to use
|
31 |
+
|
32 |
+
Here is how to use this model to perform image and text matching:
|
33 |
+
|
34 |
+
```python
|
35 |
+
from transformers import BridgeTowerProcessor, BridgeTowerForImageAndTextRetrieval
|
36 |
+
import requests
|
37 |
+
from PIL import Image
|
38 |
+
|
39 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
40 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
41 |
+
texts = ["An image of two cats chilling on a couch", "A football player scoring a goal"]
|
42 |
+
|
43 |
+
processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-large-itm-mlm")
|
44 |
+
model = BridgeTowerForImageAndTextRetrieval.from_pretrained("BridgeTower/bridgetower-large-itm-mlm")
|
45 |
+
|
46 |
+
# forward pass
|
47 |
+
scores = dict()
|
48 |
+
for text in texts:
|
49 |
+
# prepare inputs
|
50 |
+
encoding = processor(image, text, return_tensors="pt")
|
51 |
+
outputs = model(**encoding)
|
52 |
+
scores[text] = outputs.logits[0,1].item()
|
53 |
+
```
|
54 |
+
|
55 |
+
Here is how to use this model to perfom masked language modeling:
|
56 |
+
|
57 |
+
```python
|
58 |
+
from transformers import BridgeTowerProcessor, BridgeTowerForMaskedLM
|
59 |
+
from PIL import Image
|
60 |
+
import requests
|
61 |
+
|
62 |
+
url = "http://images.cocodataset.org/val2017/000000360943.jpg"
|
63 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
64 |
+
text = "a <mask> looking out of the window"
|
65 |
+
|
66 |
+
processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-large-itm-mlm")
|
67 |
+
model = BridgeTowerForMaskedLM.from_pretrained("BridgeTower/bridgetower-large-itm-mlm")
|
68 |
+
|
69 |
+
# prepare inputs
|
70 |
+
encoding = processor(image, text, return_tensors="pt")
|
71 |
+
|
72 |
+
# forward pass
|
73 |
+
outputs = model(**encoding)
|
74 |
+
|
75 |
+
results = processor.decode(outputs.logits.argmax(dim=-1).squeeze(0).tolist())
|
76 |
+
|
77 |
+
print(results)
|
78 |
+
.a cat looking out of the window.
|
79 |
+
```
|
80 |
+
|
81 |
+
### Limitations and bias
|
82 |
+
|
83 |
+
TODO
|
84 |
+
|
85 |
+
## Training data
|
86 |
+
|
87 |
+
The BridgeTower model was pretrained on four public image-caption datasets:
|
88 |
+
- [Conceptual Captions(CC)](https://ai.google.com/research/ConceptualCaptions/),
|
89 |
+
- [SBU Captions](https://www.cs.rice.edu/~vo9/sbucaptions/),
|
90 |
+
- [MSCOCO Captions](https://arxiv.org/pdf/1504.00325.pdf),
|
91 |
+
- [Visual Genome](https://visualgenome.org/)
|
92 |
+
|
93 |
+
The total number of unique images in the combined data is 4M.
|
94 |
+
|
95 |
+
## Training procedure
|
96 |
+
|
97 |
+
### Preprocessing
|
98 |
+
|
99 |
+
TODO
|
100 |
+
|
101 |
+
### Pretraining
|
102 |
+
|
103 |
+
The model was pre-trained for 100k steps on 8 NVIDIA A100 GPUs with a batch size of 4096.
|
104 |
+
The optimizer used was AdamW with a learning rate of 1e-5. No data augmentation was used except for center-crop. The image resolution in pre-training is set to 288 x 288.
|
105 |
+
|
106 |
+
## Evaluation results
|
107 |
+
Please refer to [Table 5](https://arxiv.org/pdf/2206.08657.pdf) for BridgeTower's performance on Image Retrieval and other down stream tasks.
|
108 |
+
|
109 |
+
### BibTeX entry and citation info
|
110 |
+
```bibtex
|
111 |
+
@article{xu2022bridge,
|
112 |
+
title={Bridge-Tower: Building Bridges Between Encoders in Vision-Language Representation Learning},
|
113 |
+
author={Xu, Xiao and
|
114 |
+
Wu, Chenfei and
|
115 |
+
Rosenman, Shachar and
|
116 |
+
Lal, Vasudev and
|
117 |
+
Duan, Nan},
|
118 |
+
journal={arXiv preprint arXiv:2206.08657},
|
119 |
+
year={2022}
|
120 |
+
}
|
121 |
+
```
|
config.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"share_cross_modal_transformer_layers": true,
|
3 |
+
"drop_rate": 0.1,
|
4 |
+
"head_hidden_scale": 2,
|
5 |
+
"hidden_act": "gelu",
|
6 |
+
"hidden_size": 1024,
|
7 |
+
"initializer_factor": 1,
|
8 |
+
"is_encoder_decoder": false,
|
9 |
+
"layer_norm_eps": 1e-05,
|
10 |
+
"share_link_tower_layers": false,
|
11 |
+
"link_tower_type": "add",
|
12 |
+
"num_attention_heads": 16,
|
13 |
+
"num_hidden_layers": 6,
|
14 |
+
"tie_word_embeddings": false,
|
15 |
+
"text_config_dict": null,
|
16 |
+
"init_layernorm_from_vision_encoder": false,
|
17 |
+
"text_config": {
|
18 |
+
"architectures": [
|
19 |
+
"BridgeTowerTextModel"
|
20 |
+
],
|
21 |
+
"vocab_size": 50265,
|
22 |
+
"hidden_size": 1024,
|
23 |
+
"num_hidden_layers": 24,
|
24 |
+
"num_attention_heads": 16,
|
25 |
+
"intermediate_size": 4096,
|
26 |
+
"hidden_act": "gelu",
|
27 |
+
"hidden_dropout_prob": 0.1,
|
28 |
+
"attention_probs_dropout_prob": 0.1,
|
29 |
+
"max_position_embeddings": 514,
|
30 |
+
"type_vocab_size": 1,
|
31 |
+
"initializer_factor": 1,
|
32 |
+
"initializer_range": 0.02,
|
33 |
+
"layer_norm_eps": 1e-05,
|
34 |
+
"pad_token_id": 1,
|
35 |
+
"bos_token_id": 0,
|
36 |
+
"eos_token_id": 2,
|
37 |
+
"position_embedding_type": "absolute",
|
38 |
+
"use_cache": true,
|
39 |
+
"classifier_dropout": null
|
40 |
+
},
|
41 |
+
"vision_config_dict": null,
|
42 |
+
"vision_config": {
|
43 |
+
"architectures": [
|
44 |
+
"BridgeTowerVisionModel"
|
45 |
+
],
|
46 |
+
"hidden_size": 1024,
|
47 |
+
"num_hidden_layers": 24,
|
48 |
+
"patch_size": 14,
|
49 |
+
"image_size": 294,
|
50 |
+
"initializer_factor": 1,
|
51 |
+
"stop_gradient": false,
|
52 |
+
"share_layernorm": true,
|
53 |
+
"remove_last_layer": false
|
54 |
+
}
|
55 |
+
}
|
preprocessor_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_text_len":50,
|
3 |
+
"size":294,
|
4 |
+
"tokenizer":"roberta-large",
|
5 |
+
"vocab_size":50265
|
6 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:93b54c0972e9f09851fb7d62f278ea6c086855c73f4cd399cd8ed3104c39a23c
|
3 |
+
size 3668725385
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|