Views
No views yet
| Model | Classification | VQA | Retrieval | Grounding | IND | OOD | Overall |
|---|---|---|---|---|---|---|---|
| Phi-3.5-V, Full-model fine-tuned (#crop=4) | 52.8 | 50.3 | 57.8 | 72.3 | 62.8 | 47.4 | 55.9 |
| Phi-3.5-V, LoRA | 54.8 | 54.9 | 62.3 | 79.5 | 66.5 | 52.0 | 60.1 |
| LLaVA-1.6, LoRA | 54.7 | 50.3 | 56.2 | 64.0 | 61.0 | 47.5 | 55.0 |
| LLaVA-1.6, LoRA | 61.2 | 49.9 | 67.4 | 86.1 | 67.5 | 57.1 | 62.9 |
| Qwen2-VL-2B, LoRA | 59.0 | 49.4 | 65.4 | 73.4 | 66.0 | 52.6 | 60.1 |
| Qwen2-VL-7B, LoRA (this model) | 62.6 | 57.8 | 69.9 | 81.7 | 72.2 | 57.8 | 65.8 |

1git clone https://github.com/TIGER-AI-Lab/VLM2Vec.git
2pip install -r requirements.txt1from src.model import MMEBModel
2from src.arguments import ModelArguments
3from src.model_utils import load_processor, QWEN2_VL, vlm_image_tokens
4from PIL import Image
5import torch
6
7model_args = ModelArguments(
8 model_name='Qwen/Qwen2-VL-7B-Instruct',
9 checkpoint_path='TIGER-Lab/VLM2Vec-Qwen2VL-7B',
10 pooling='last',
11 normalize=True,
12 model_backbone='qwen2_vl',
13 lora=True
14)
15
16processor = load_processor(model_args)
17model = MMEBModel.load(model_args)
18model = model.to('cuda', dtype=torch.bfloat16)
19model.eval()
20
21# Image + Text -> Text
22inputs = processor(text=f'{vlm_image_tokens[QWEN2_VL]} Represent the given image with the following question: What is in the image',
23 images=Image.open('figures/example.jpg'),
24 return_tensors="pt")
25inputs = {key: value.to('cuda') for key, value in inputs.items()}
26inputs['pixel_values'] = inputs['pixel_values'].unsqueeze(0)
27inputs['image_grid_thw'] = inputs['image_grid_thw'].unsqueeze(0)
28qry_output = model(qry=inputs)["qry_reps"]
29
30string = 'A cat and a dog'
31inputs = processor(text=string,
32 images=None,
33 return_tensors="pt")
34inputs = {key: value.to('cuda') for key, value in inputs.items()}
35tgt_output = model(tgt=inputs)["tgt_reps"]
36print(string, '=', model.compute_similarity(qry_output, tgt_output))
37## A cat and a dog = tensor([[0.3301]], device='cuda:0', dtype=torch.bfloat16)
38
39string = 'A cat and a tiger'
40inputs = processor(text=string,
41 images=None,
42 return_tensors="pt")
43inputs = {key: value.to('cuda') for key, value in inputs.items()}
44tgt_output = model(tgt=inputs)["tgt_reps"]
45print(string, '=', model.compute_similarity(qry_output, tgt_output))
46## A cat and a tiger = tensor([[0.2891]], device='cuda:0', dtype=torch.bfloat16)@article{jiang2024vlm2vec,
title={VLM2Vec: Training Vision-Language Models for Massive Multimodal Embedding Tasks},
author={Jiang, Ziyan and Meng, Rui and Yang, Xinyi and Yavuz, Semih and Zhou, Yingbo and Chen, Wenhu},
journal={arXiv preprint arXiv:2410.05160},
year={2024}
}