Views
No views yet
| Bleu-4 | METEOR | CIDEr | SPICE |
|---|---|---|---|
| 0.38 | 0.30 | 1.29 | 0.23 |
1from transformers.pytorch_transformers import BertConfig, BertTokenizer
2from oscar.modeling.modeling_bert import BertForImageCaptioning
3from oscar.wrappers import OscarTensorizer
4
5ckpt = "path/to/the/checkpoint"
6device = "cuda" if torch.cuda.is_available() else "cpu"
7
8# original code
9config = BertConfig.from_pretrained(ckpt)
10tokenizer = BertTokenizer.from_pretrained(ckpt)
11model = BertForImageCaptioning.from_pretrained(ckpt, config=config).to(device)
12
13# This takes care of the preprocessing
14tensorizer = OscarTensorizer(tokenizer=tokenizer, device=device)
15
16# numpy-arrays with shape (1, num_boxes, feat_size)
17# feat_size is 2054 by default in VinVL
18visual_features = torch.from_numpy(feat_obj).to(device).unsqueeze(0)
19
20# labels are usually extracted by the features extractor
21labels = [['boat', 'boat', 'boat', 'bottom', 'bush', 'coat', 'deck', 'deck', 'deck', 'dock', 'hair', 'jacket']]
22
23inputs = tensorizer.encode(visual_features, labels=labels)
24outputs = model(**inputs)
25
26pred = tensorizer.decode(outputs)
27
28# the output looks like this:
29# pred = {0: [{'caption': 'a red and white boat traveling down a river next to a small boat.', 'conf': 0.7070220112800598]}1
2@misc{han2021image,
3 title={Image Scene Graph Generation (SGG) Benchmark},
4 author={Xiaotian Han and Jianwei Yang and Houdong Hu and Lei Zhang and Jianfeng Gao and Pengchuan Zhang},
5 year={2021},
6 eprint={2107.12604},
7 archivePrefix={arXiv},
8 primaryClass={cs.CV}
9}1@inproceedings{zhang2021vinvl,
2 title={Vinvl: Revisiting visual representations in vision-language models},
3 author={Zhang, Pengchuan and Li, Xiujun and Hu, Xiaowei and Yang, Jianwei and Zhang, Lei and Wang, Lijuan and Choi, Yejin and Gao, Jianfeng},
4 booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
5 pages={5579--5588},
6 year={2021}
7}