README.md 9.16 KB
Newer Older
ShuoZhang2003's avatar
ShuoZhang2003 committed
1
<p align="left">
ShuoZhang2003's avatar
ShuoZhang2003 committed
2
        English</a>&nbsp | &nbsp<a href="README_cn.md">中文</a>&nbsp
ShuoZhang2003's avatar
ShuoZhang2003 committed
3
4
</p>
<br><br>
lvskiller's avatar
readme  
lvskiller committed
5

ShuoZhang2003's avatar
ShuoZhang2003 committed
6
# Monkey: Image Resolution and Text Label Are Important Things for Large Multi-modal Models
Melos's avatar
Melos committed
7

Yuliang Liu's avatar
Yuliang Liu committed
8
9
10
11
12
<br>
<p align="center">
    <img src="images/logo_monkey.png" width="300"/>
<p>
<br>
lvskiller's avatar
readme  
lvskiller committed
13
14

<div align="center">
Yuliang Liu's avatar
Yuliang Liu committed
15
Zhang Li*, Biao Yang*, Qiang Liu, Zhiyin Ma, Shuo Zhang, Jingxu Yang, Yabo Sun, Yuliang Liu†, Xiang Bai†
lvskiller's avatar
readme  
lvskiller committed
16
17
18
19
</div>
<div align="center">
<strong>Huazhong University of Science and Technology, Kingsoft</strong>
</div>
Yuliang Liu's avatar
Yuliang Liu committed
20
<p align="center">
ShuoZhang2003's avatar
ShuoZhang2003 committed
21
<a href="https://arxiv.org/abs/2311.06607">Paper</a>&nbsp&nbsp | &nbsp&nbsp<a href="http://27.18.7.151:7680/">Demo</a>&nbsp&nbsp | &nbsp&nbsp<a href="http://27.18.7.151:7681/">Demo_chat</a>&nbsp&nbsp | &nbsp&nbsp<a href="http://huggingface.co/datasets/echo840/Detailed_Caption">Detailed Caption</a>&nbsp&nbsp | &nbsp&nbsp<a href="http://huggingface.co/echo840/Monkey">Model Weight</a>&nbsp&nbsp  |  <a href="https://www.wisemodel.cn/models/HUST-VLRLab/Monkey/">Model Weight in wisemodel</a>&nbsp&nbsp
lvskiller's avatar
lvskiller committed
22
<!--     | &nbsp&nbsp<a href="Monkey Model">Monkey Models</a>&nbsp | &nbsp <a href="http://huggingface.co/echo840/Monkey">Tutorial</a> -->
Yuliang Liu's avatar
Yuliang Liu committed
23
</p>
lvskiller's avatar
lvskiller committed
24

Melos's avatar
Melos committed
25
-----
Yuliang Liu's avatar
Yuliang Liu committed
26
  
Yuliang Liu's avatar
Yuliang Liu committed
27
**Monkey** brings a training-efficient approach to effectively improve the input resolution capacity up to 896 x 1344 pixels without pretraining from the start. To bridge the gap between simple text labels and high input resolution, we propose a multi-level description generation method, which automatically provides rich information that can guide the model to learn the contextual association between scenes and objects. With the synergy of these two designs, our model achieved excellent results on multiple benchmarks. By comparing our model with various LMMs, including GPT4V, our model demonstrates promising performance in image captioning by paying attention to textual information and capturing fine details within the images; its improved input resolution also enables remarkable performance in document images with dense text. 
Yuliang Liu's avatar
Yuliang Liu committed
28
    
Yuliang Liu's avatar
Yuliang Liu committed
29
## News 
ShuoZhang2003's avatar
ShuoZhang2003 committed
30
* ```2023.12.16``` 🚀🚀🚀 Monkey can be trained using 8 NVIDIA 3090 GPUs. See subsection [train](#Train) for details.
Yuliang Liu's avatar
Yuliang Liu committed
31
* ```2023.11.25``` 🚀🚀🚀 Monkey-chat demo is released. 
Yuliang Liu's avatar
Yuliang Liu committed
32
33
* ```2023.11.06``` 🚀🚀🚀 Monkey [paper](https://arxiv.org/abs/2311.06607) is released.

lvskiller's avatar
lvskiller committed
34

lvskiller's avatar
readme  
lvskiller committed
35
36
## Spotlights

Yuliang Liu's avatar
Yuliang Liu committed
37
- **Contextual associations.** Our method demonstrates a superior ability to infer the relationships between targets more effectively when answering questions, which results in delivering more comprehensive and insightful results.
Melos's avatar
Melos committed
38
39
- **Support resolution up to 1344 x 896.** Surpassing the standard 448 x 448 resolution typically employed for LMMs, this significant increase in resolution augments the ability to discern and understand unnoticeable or tightly clustered objects and dense text. 
- **Enhanced general performance.** We carried out testing across 16 diverse datasets, leading to impressive performance by our Monkey model in tasks such as Image Captioning, General Visual Question Answering, Text-centric Visual Question Answering, and Document-oriented Visual Question Answering.
lvskiller's avatar
readme  
lvskiller committed
40

ShuoZhang2003's avatar
ShuoZhang2003 committed
41

lvskiller's avatar
lvskiller committed
42
43
44
45
46
47
48
49
50
51
52
## Environment

```python
conda create -n monkey python=3.9
conda activate monkey
git clone https://github.com/Yuliang-Liu/Monkey.git
cd ./Monkey
pip install -r requirements.txt
```


Yuliang Liu's avatar
Yuliang Liu committed
53
## Demo
lvskiller's avatar
readme  
lvskiller committed
54

ShuoZhang2003's avatar
ShuoZhang2003 committed
55
56
[Demo](http://27.18.7.151:7680/) is fast and easy to use. Simply uploading an image from your desktop or phone, or capture one directly. 
[Demo_chat](http://27.18.7.151:7681/) is also launched as an upgraded version of the original demo to deliver an enhanced interactive experience.
ShuoZhang2003's avatar
ShuoZhang2003 committed
57
58

Before 14/11/2023, we have observed that for some random pictures Monkey can achieve more accurate results than GPT4V.  
Yuliang Liu's avatar
Yuliang Liu committed
59
60
<br>
<p align="center">
Yuliang Liu's avatar
Yuliang Liu committed
61
    <img src="images/demo_gpt4v_compare4.png" width="900"/>
Yuliang Liu's avatar
Yuliang Liu committed
62
63
64
<p>
<br>

ShuoZhang2003's avatar
ShuoZhang2003 committed
65
We also provide the source code and the model weight for the original demo, allowing you to customize certain parameters for a more unique experience. The specific operations are as follows:
lvskiller's avatar
lvskiller committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 1. Make sure you have configured the [environment](#environment).
 2. You can choose to use the demo offline or online:
- **Offline:** 
	- Download the [Model Weight](http://huggingface.co/echo840/Monkey). 
	- Modify `DEFAULT_CKPT_PATH="pathto/Monkey"` in the `demo.py` file to your model weight path. 
	- Run the demo using the following command: 
	```
	python demo.py
	```
- **Online:** 
	- Run the demo and download model weights online with the following command: 
	```
	python demo.py -c echo840/Monkey 
	```
ShuoZhang2003's avatar
ShuoZhang2003 committed
80

ShuoZhang2003's avatar
ShuoZhang2003 committed
81
82
83
84
85
86
87
88
89
90
91
In order to generate more detailed captions, we provide some prompt examples so that you can conduct more interesting explorations. You can modify these two variables in the `caption` function to implement different prompt inputs for the caption task, as shown below:
```
query = "Generate the detailed caption in English. Answer:"
chat_query = "Generate the detailed caption in English. Answer:"
```
- Generate the detailed caption in English.
- Explain the visual content of the image in great detail.
- Analyze the image in a comprehensive and detailed manner.
- Describe the image in as much detail as possible in English without duplicating it.
- Describe the image in as much detail as possible in English, including as many elements from the image as possible, but without repetition.

lvskiller's avatar
lvskiller committed
92
93
94
95
96

## Dataset

We have open-sourced the data generated by the multi-level description generation method. You can download it at [Detailed Caption](https://huggingface.co/datasets/echo840/Detailed_Caption).

ShuoZhang2003's avatar
ShuoZhang2003 committed
97

lvskiller's avatar
lvskiller committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
## Evaluate

We offer evaluation code for 14 Visual Question Answering (VQA) datasets in the `evaluate_vqa.py` file, facilitating a quick verification of results.  The specific operations are as follows:

 1. Make sure you have configured the [environment](#environment).
 2. Modify `sys.path.append("pathto/Monkey")`  to your model weight path.
 3. Prepare the datasets required for evaluation. 
 4. Run the evaluation code.

 Take ESTVQA as an example:
 - Prepare data according to the following directory structure:
```
├── data
|	├── estvqa
|		├── test_image
|			├── {image_path0}
|			├── {image_path1}
ShuoZhang2003's avatar
ShuoZhang2003 committed
115
116
|				  ·
|				  ·
Melos's avatar
Melos committed
117
|	├── estvqa.jsonl
lvskiller's avatar
lvskiller committed
118
119
120
121
122
123
124
125
126
```
 - Example of the format of each line of the annotated `.jsonl` file:
```
{"image": "data/estvqa/test_image/011364.jpg", "question": "What is this store?", "answer": "pizzeria", "question_id": 0}
```
 - Modify the dictionary `ds_collections`:
```
ds_collections = {
	'estvqa_test': {
Melos's avatar
Melos committed
127
128
129
		'test': 'data/estvqa/estvqa.jsonl',
		'metric': 'anls',
		'max_new_tokens': 100,
lvskiller's avatar
lvskiller committed
130
131
132
133
134
135
136
137
138
	},
	...
}
```
 - Run the following command:
```
bash eval/eval.sh 'EVAL_PTH' 'SAVE_NAME'
```

ShuoZhang2003's avatar
ShuoZhang2003 committed
139

lvskiller's avatar
lvskiller committed
140
141
142
143
144
145
146
## Train

We also offer Monkey's model definition and training code, which you can explore above. You can execute the training code through executing `finetune_ds_debug.sh`.

**ATTENTION:** Specify the path to your training data, which should be a json file consisting of a list of conversations.


Yuliang Liu's avatar
Yuliang Liu committed
147
## Performance
lvskiller's avatar
lvskiller committed
148

Yuliang Liu's avatar
Yuliang Liu committed
149
<br>
Yuliang Liu's avatar
Yuliang Liu committed
150

Yuliang Liu's avatar
Yuliang Liu committed
151
<p align="center">
Yuliang Liu's avatar
Yuliang Liu committed
152
    <img src="images/radar.png" width="800"/>
Yuliang Liu's avatar
Yuliang Liu committed
153
154
<p>
<br>
Yuliang Liu's avatar
Yuliang Liu committed
155
156


lvskiller's avatar
readme  
lvskiller committed
157
158
## Cases

Yuliang Liu's avatar
Yuliang Liu committed
159
Our model can accurately describe the details in the image.
lvskiller's avatar
readme  
lvskiller committed
160

Yuliang Liu's avatar
Yuliang Liu committed
161
162
163
164
165
<br>
<p align="center">
    <img src="images/caption_1.png" width="700"/>
<p>
<br>
lvskiller's avatar
lvskiller committed
166

ShuoZhang2003's avatar
ShuoZhang2003 committed
167
168
169
170
171
172
173
Our model performs particularly well in dense text question answering tasks. For example, in the dense text of item labels, Monkey can accurately answer various information about the item, and its performance is very impressive compared to other LMMs including GPT4V.

<br>
<p align="center">
    <img src="images/dense_text_1.png" width="700"/>
<p>
<br>
lvskiller's avatar
readme  
lvskiller committed
174

Yuliang Liu's avatar
Yuliang Liu committed
175
176
<br>
<p align="center">
ShuoZhang2003's avatar
ShuoZhang2003 committed
177
    <img src="images/dense_text_2.png" width="700"/>
Yuliang Liu's avatar
Yuliang Liu committed
178
179
<p>
<br>
lvskiller's avatar
readme  
lvskiller committed
180

ShuoZhang2003's avatar
ShuoZhang2003 committed
181
Monkey also performs equally well in daily life scenes. It can complete various Q&A and caption tasks and describe various details in the image in detail, even the inconspicuous watermark.
lvskiller's avatar
readme  
lvskiller committed
182

Yuliang Liu's avatar
Yuliang Liu committed
183
184
<br>
<p align="center">
ShuoZhang2003's avatar
ShuoZhang2003 committed
185
    <img src="images/qa_caption.png" width="700"/>
Yuliang Liu's avatar
Yuliang Liu committed
186
187
<p>
<br>
lvskiller's avatar
readme  
lvskiller committed
188

Yuliang Liu's avatar
Yuliang Liu committed
189
We qualitatively compare with existing LMMs including GPT4V, Qwen-vl, etc, which shows inspiring results. One can have a try using the provided demo. 
lvskiller's avatar
readme  
lvskiller committed
190

Yuliang Liu's avatar
Yuliang Liu committed
191
192
193
194
195
<br>
<p align="center">
    <img src="images/compare.png" width="800"/>
<p>
<br>
lvskiller's avatar
lvskiller committed
196

ShuoZhang2003's avatar
ShuoZhang2003 committed
197

Yuliang Liu's avatar
Yuliang Liu committed
198
199
200
201
## Citing Monkey
If you wish to refer to the baseline results published here, please use the following BibTeX entries:

```BibTeX
Yuliang Liu's avatar
Yuliang Liu committed
202
@article{li2023monkey,
Yuliang Liu's avatar
Yuliang Liu committed
203
  title={Monkey: Image Resolution and Text Label Are Important Things for Large Multi-modal Models},
Yuliang Liu's avatar
Yuliang Liu committed
204
  author={Li, Zhang and Yang, Biao and Liu, Qiang and Ma, Zhiyin and Zhang, Shuo and Yang, Jingxu and Sun, Yabo and Liu, Yuliang and Bai, Xiang},
Yuliang Liu's avatar
Yuliang Liu committed
205
206
207
208
209
210
  journal={arXiv preprint arXiv:2311.06607},
  year={2023}
}
```

If you find the Monkey cute, please star. It would be a great encouragement for us.
lvskiller's avatar
lvskiller committed
211

ShuoZhang2003's avatar
ShuoZhang2003 committed
212

lvskiller's avatar
readme  
lvskiller committed
213
214
## Acknowledgement

Melos's avatar
Melos committed
215
[Qwen-VL](https://github.com/QwenLM/Qwen-VL.git): the codebase we built upon. Thanks for the authors of Qwen for providing the framework.
lvskiller's avatar
readme  
lvskiller committed
216

Yuliang Liu's avatar
Yuliang Liu committed
217

Yuliang Liu's avatar
Yuliang Liu committed
218
## Copyright
Yuliang Liu's avatar
Yuliang Liu committed
219
We welcome suggestions to help us improve the Monkey. For any query, please contact Dr. Yuliang Liu: ylliu@hust.edu.cn. If you find something interesting, please also feel free to share with us through email or open an issue. Thanks!