update
Browse files
README.md
CHANGED
@@ -1,3 +1,67 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: Multimodal Small Language Model, Phi-2, VQA
|
6 |
---
|
7 |
+
# :smiling_imp: IMP
|
8 |
+
|
9 |
+
The :smiling_imp: IMP project aims to provide a family of a strong multimodal `small` language models (MSLMs). Our `IMP-v0-3B` model is a strong MSLM with only **3B** parameters, which is build upon a small yet powerful SLM [Phi-2 ](https://huggingface.co/microsoft/phi-2)(2.7B) and a powerful visual encoder [SigLIP ](https://huggingface.co/google/siglip-so400m-patch14-384)(0.4B), and trained on the [LLaVA-v1.5](https://github.com/haotian-liu/LLaVA) training set.
|
10 |
+
|
11 |
+
As shown in the Table below, `IMP-v0-3B` significantly outperforms the counterparts of similar model sizes, and even achieves slightly better performance than the strong LLaVA-7B model on various multimodal benchmarks.
|
12 |
+
|
13 |
+
We release our model weights and provide an example below to run our model . Detailed technical report and corresponding training/evaluation code will be released soon on our [GitHub repo](https://github.com/MILVLG/imp). We will persistently improve our model and release the next versions to further improve model performance :)
|
14 |
+
|
15 |
+
## How to use
|
16 |
+
|
17 |
+
You can use the following code for model inference. We minimize the required dependency libraries that only the `transformers` and `torch` packages are used. The format of text instructions is similar to [LLaVA](https://github.com/haotian-liu/LLaVA).
|
18 |
+
|
19 |
+
```Python
|
20 |
+
import torch
|
21 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
22 |
+
from PIL import Image
|
23 |
+
|
24 |
+
torch.set_default_device("cuda")
|
25 |
+
|
26 |
+
#Create model
|
27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
28 |
+
"milvlg/imp-v0",
|
29 |
+
torch_dtype=torch.float16,
|
30 |
+
device_map="auto",
|
31 |
+
trust_remote_code=True)
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained("milvlg/imp-v0", trust_remote_code=True)
|
33 |
+
|
34 |
+
#Set inputs
|
35 |
+
text = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat are the colors of the bus in the image? ASSISTANT:"
|
36 |
+
image = Image.open("images/bus.jpg")
|
37 |
+
|
38 |
+
input_ids = tokenizer(text, return_tensors='pt').input_ids
|
39 |
+
image_tensor = model.process_images([image])
|
40 |
+
|
41 |
+
#Generate the answer
|
42 |
+
output_ids = model.generate(
|
43 |
+
input_ids,
|
44 |
+
max_new_tokens=100,
|
45 |
+
images=image_tensor,
|
46 |
+
use_cache=True)[0]
|
47 |
+
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
|
48 |
+
```
|
49 |
+
|
50 |
+
## Model evaluation
|
51 |
+
We perform evaluation on 8 commonly-used benchmarks to validate the effectiveness of our model, including 5 academic VQA benchmarks and 3 recent MLLM benchmarks.
|
52 |
+
|
53 |
+
| Models | Size | VQAv2 | GQA |VisWiz | SQA (IMG) | TextVQA | POPE | MME | MMB |MM-Vet|
|
54 |
+
|:--------:|:-----:|:----:|:----:|:-------------:|:--------:|:-----:|:----:|:-------:|:-------:|:-------:|
|
55 |
+
| [LLaVA-v1.5-lora](https://huggingface.co/liuhaotian/llava-v1.5-7b) | 7B |79.10 | **63.00** |47.80 | 68.40 |58.20| 86.40 | **1476.9** | 66.10 |30.2|
|
56 |
+
| [TinyGPT-V](https://huggingface.co/Tyrannosaurus/TinyGPT-V) | 3B | - | 33.60 | 24.80 | - | - | -| - | - |-|
|
57 |
+
| [LLaVA-Phi](https://arxiv.org/pdf/2401.02330.pdf) | 3B | 71.40 | - | 35.90 | 68.40 | 48.60 | 85.00 | 1335.1 | 59.80 |28.9|
|
58 |
+
| [MobileVLM](https://huggingface.co/mtgv/MobileVLM-3B) | 3B | - | 59.00 | - | 61.00 | 47.50 | 84.90 | 1288.9 | 59.60 |-|
|
59 |
+
| [MC-LLaVA-3b](https://huggingface.co/visheratin/MC-LLaVA-3b) | 3B | 64.24 | 49.6 | 24.88 | - | 38.59 | 80.59 | - | - |-|
|
60 |
+
| **IMP-v0 (ours)** | 3B | **79.45** | 58.55 | **50.09** |**69.96**| **59.38** | **88.02**| 1434 | **66.49** |**33.1**|
|
61 |
+
|
62 |
+
|
63 |
+
## License
|
64 |
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) file for details.
|
65 |
+
|
66 |
+
## About us
|
67 |
+
Project :smiling_imp: IMP is maintained by the [MILVLG](https://github.com/MILVLG) group led by Prof. Zhou Yu and Jun Yu, and mainly developed by Zhenwei Shao and Xuecheng Ouyang. We hope our model may server as a strong baseline to inspire future research on MSLMs and derivative applications on mobile devices and robotics.
|
md.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
torch.set_default_device("cuda")
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(
|
8 |
-
"../Imp-v0-3b",
|
9 |
-
torch_dtype=torch.float16,
|
10 |
-
device_map="auto",
|
11 |
-
trust_remote_code=True)
|
12 |
-
tokenizer = AutoTokenizer.from_pretrained("../Imp-v0-3b", trust_remote_code=True)
|
13 |
-
|
14 |
-
text = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat are the colors of the bus in the image? ASSISTANT:"
|
15 |
-
image = Image.open("images/bus.jpg")
|
16 |
-
|
17 |
-
input_ids = tokenizer(text, return_tensors='pt').input_ids
|
18 |
-
image_tensor = model.image_preprocess(image)
|
19 |
-
|
20 |
-
output_ids = model.generate(
|
21 |
-
input_ids,
|
22 |
-
max_new_tokens=100,
|
23 |
-
images=image_tensor,
|
24 |
-
use_cache=True)[0]
|
25 |
-
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|