Update README.md
Browse files
README.md
CHANGED
@@ -1,397 +1,329 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
pipeline_tag: visual-question-answering
|
4 |
-
---
|
5 |
-
|
6 |
-
# InternVL2-2B
|
7 |
-
|
8 |
-
[\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[🆕 Blog\]](https://internvl.github.io/blog/) [\[📜 InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[📜 InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
|
9 |
-
|
10 |
-
[\[🗨️ Chat Demo\]](https://internvl.opengvlab.com/) [\[🤗 HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[🚀 Quick Start\]](#quick-start) [\[📖 中文解读\]](https://zhuanlan.zhihu.com/p/675877376)
|
11 |
-
|
12 |
-
## Introduction
|
13 |
-
|
14 |
-
We are excited to announce the release of InternVL 2.0, the latest addition to the InternVL series of multimodal large language models. InternVL 2.0 features a variety of instruction-tuned models, ranging from 2 billion to 108 billion parameters. This repository contains the instruction-tuned InternVL2-2B model.
|
15 |
-
|
16 |
-
Compared to the state-of-the-art open-source multimodal large language models, InternVL 2.0 surpasses most open-source models. It demonstrates competitive performance on par with proprietary commercial models across various capabilities, including document and chart comprehension, infographics QA, scene text understanding and OCR tasks, scientific and mathematical problem solving, as well as cultural understanding and integrated multimodal capabilities.
|
17 |
-
|
18 |
-
InternVL 2.0 is trained with an 8k context window and utilizes training data consisting of long texts, multiple images, and videos, significantly improving its ability to handle these types of inputs compared to InternVL 1.5. For more details, please refer to our blog and GitHub.
|
19 |
-
|
20 |
-
## Model Details
|
21 |
-
|
22 |
-
InternVL 2.0 is a multimodal large language model series, featuring models of various sizes. For each size, we release instruction-tuned models optimized for multimodal tasks. InternVL2-2B consists of [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px), an MLP projector, and [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b).
|
23 |
-
|
24 |
-
## Performance
|
25 |
-
|
26 |
-
| Benchmark | PaliGemma-3B | Phi-3-Vision | Mini-InternVL-2B-1.5 | InternVL2-2B |
|
27 |
-
| :--------------------------: | :----------: | :----------: | :------------------: | :----------: |
|
28 |
-
| Model Size | 2.9B | 4.2B | 2.2B | 2.2B |
|
29 |
-
| | | | | |
|
30 |
-
| DocVQA<sub>test</sub> | - | - | 85.0 | 86.9 |
|
31 |
-
| ChartQA<sub>test</sub> | - | 81.4 | 74.8 | 76.2 |
|
32 |
-
| InfoVQA<sub>test</sub> | - | - | 55.4 | 58.9 |
|
33 |
-
| TextVQA<sub>val</sub> | 68.1 | 70.9 | 70.5 | 73.4 |
|
34 |
-
| OCRBench | 614 | 639 | 654 | 784 |
|
35 |
-
| MME<sub>sum</sub> | 1686.1 | 1508.0 | 1901.5 | 1876.8 |
|
36 |
-
| RealWorldQA | 55.2 | 58.8 | 57.9 | 57.3 |
|
37 |
-
| AI2D<sub>test</sub> | 68.3 | 76.7 | 69.8 | 74.1 |
|
38 |
-
| MMMU<sub>val</sub> | 34.9 | 40.4 | 34.6 | 34.3 |
|
39 |
-
| MMBench-EN<sub>test</sub> | 71.0 | 73.6 | 70.9 | 73.2 |
|
40 |
-
| MMBench-CN<sub>test</sub> | 63.6 | - | 66.2 | 70.9 |
|
41 |
-
| CCBench<sub>dev</sub> | 29.6 | 24.1 | 63.5 | 74.7 |
|
42 |
-
| MMVet<sub>GPT-4-0613</sub> | - | - | 39.3 | 44.6 |
|
43 |
-
| MMVet<sub>GPT-4-Turbo</sub> | 33.1 | 44.1 | 35.5 | 39.5 |
|
44 |
-
| SEED-Image | 69.6 | 70.9 | 69.8 | 71.6 |
|
45 |
-
| HallBench<sub>avg</sub> | 32.2 | 39.0 | 37.5 | 37.9 |
|
46 |
-
| MathVista<sub>testmini</sub> | 28.7 | 44.5 | 41.1 | 46.3 |
|
47 |
-
|
48 |
-
- We simultaneously use InternVL and VLMEvalKit repositories for model evaluation. Specifically, the results reported for DocVQA, ChartQA, InfoVQA, TextVQA, MME, AI2D, MMBench, CCBench, MMVet, and SEED-Image were tested using the InternVL repository. MMMU, OCRBench, RealWorldQA, HallBench, and MathVista were evaluated using the VLMEvalKit.
|
49 |
-
|
50 |
-
- Please note that evaluating the same model using different testing toolkits like InternVL and VLMEvalKit can result in slight differences, which is normal. Updates to code versions and variations in environment and hardware can also cause minor discrepancies in results.
|
51 |
-
|
52 |
-
- It is important to mention that the MMVet scores we report are evaluated using GPT-4-0613 as the judge model. Different versions of GPT-4 can lead to significant variations in the scores for this dataset. For instance, using GPT-4-Turbo would result in significantly lower scores.
|
53 |
-
|
54 |
-
Limitations: Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information.
|
55 |
-
|
56 |
-
## Quick Start
|
57 |
-
|
58 |
-
We provide an example code to run InternVL2-2B using `transformers`.
|
59 |
-
|
60 |
-
> Please use transformers==4.37.2 to ensure the model works normally.
|
61 |
-
|
62 |
-
```python
|
63 |
-
import torch
|
64 |
-
import torchvision.transforms as T
|
65 |
-
from PIL import Image
|
66 |
-
from torchvision.transforms.functional import InterpolationMode
|
67 |
-
from transformers import AutoModel, AutoTokenizer
|
68 |
-
|
69 |
-
IMAGENET_MEAN = (0.485, 0.456, 0.406)
|
70 |
-
IMAGENET_STD = (0.229, 0.224, 0.225)
|
71 |
-
|
72 |
-
|
73 |
-
def build_transform(input_size):
|
74 |
-
MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
|
75 |
-
transform = T.Compose([
|
76 |
-
T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
|
77 |
-
T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
|
78 |
-
T.ToTensor(),
|
79 |
-
T.Normalize(mean=MEAN, std=STD)
|
80 |
-
])
|
81 |
-
return transform
|
82 |
-
|
83 |
-
|
84 |
-
def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
|
85 |
-
best_ratio_diff = float('inf')
|
86 |
-
best_ratio = (1, 1)
|
87 |
-
area = width * height
|
88 |
-
for ratio in target_ratios:
|
89 |
-
target_aspect_ratio = ratio[0] / ratio[1]
|
90 |
-
ratio_diff = abs(aspect_ratio - target_aspect_ratio)
|
91 |
-
if ratio_diff < best_ratio_diff:
|
92 |
-
best_ratio_diff = ratio_diff
|
93 |
-
best_ratio = ratio
|
94 |
-
elif ratio_diff == best_ratio_diff:
|
95 |
-
if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
|
96 |
-
best_ratio = ratio
|
97 |
-
return best_ratio
|
98 |
-
|
99 |
-
|
100 |
-
def dynamic_preprocess(image, min_num=1, max_num=6, image_size=448, use_thumbnail=False):
|
101 |
-
orig_width, orig_height = image.size
|
102 |
-
aspect_ratio = orig_width / orig_height
|
103 |
-
|
104 |
-
# calculate the existing image aspect ratio
|
105 |
-
target_ratios = set(
|
106 |
-
(i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
|
107 |
-
i * j <= max_num and i * j >= min_num)
|
108 |
-
target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
|
109 |
-
|
110 |
-
# find the closest aspect ratio to the target
|
111 |
-
target_aspect_ratio = find_closest_aspect_ratio(
|
112 |
-
aspect_ratio, target_ratios, orig_width, orig_height, image_size)
|
113 |
-
|
114 |
-
# calculate the target width and height
|
115 |
-
target_width = image_size * target_aspect_ratio[0]
|
116 |
-
target_height = image_size * target_aspect_ratio[1]
|
117 |
-
blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
|
118 |
-
|
119 |
-
# resize the image
|
120 |
-
resized_img = image.resize((target_width, target_height))
|
121 |
-
processed_images = []
|
122 |
-
for i in range(blocks):
|
123 |
-
box = (
|
124 |
-
(i % (target_width // image_size)) * image_size,
|
125 |
-
(i // (target_width // image_size)) * image_size,
|
126 |
-
((i % (target_width // image_size)) + 1) * image_size,
|
127 |
-
((i // (target_width // image_size)) + 1) * image_size
|
128 |
-
)
|
129 |
-
# split the image
|
130 |
-
split_img = resized_img.crop(box)
|
131 |
-
processed_images.append(split_img)
|
132 |
-
assert len(processed_images) == blocks
|
133 |
-
if use_thumbnail and len(processed_images) != 1:
|
134 |
-
thumbnail_img = image.resize((image_size, image_size))
|
135 |
-
processed_images.append(thumbnail_img)
|
136 |
-
return processed_images
|
137 |
-
|
138 |
-
|
139 |
-
def load_image(image_file, input_size=448, max_num=6):
|
140 |
-
image = Image.open(image_file).convert('RGB')
|
141 |
-
transform = build_transform(input_size=input_size)
|
142 |
-
images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
|
143 |
-
pixel_values = [transform(image) for image in images]
|
144 |
-
pixel_values = torch.stack(pixel_values)
|
145 |
-
return pixel_values
|
146 |
-
|
147 |
-
|
148 |
-
path = '
|
149 |
-
model = AutoModel.from_pretrained(
|
150 |
-
path,
|
151 |
-
torch_dtype=torch.bfloat16,
|
152 |
-
low_cpu_mem_usage=True,
|
153 |
-
trust_remote_code=True).eval().cuda()
|
154 |
-
|
155 |
-
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
156 |
-
# set the max number of tiles in `max_num`
|
157 |
-
pixel_values = load_image('./examples/image1.jpg', max_num=6).to(torch.bfloat16).cuda()
|
158 |
-
|
159 |
-
generation_config = dict(
|
160 |
-
num_beams=1,
|
161 |
-
max_new_tokens=1024,
|
162 |
-
do_sample=False,
|
163 |
-
)
|
164 |
-
|
165 |
-
# pure-text conversation (纯文本对话)
|
166 |
-
question = 'Hello, who are you?'
|
167 |
-
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
|
168 |
-
print(f'User: {question}')
|
169 |
-
print(f'Assistant: {response}')
|
170 |
-
|
171 |
-
question = 'Can you tell me a story?'
|
172 |
-
response, history = model.chat(tokenizer, None, question, generation_config, history=history, return_history=True)
|
173 |
-
print(f'User: {question}')
|
174 |
-
print(f'Assistant: {response}')
|
175 |
-
|
176 |
-
# single-image single-round conversation (单图单轮对话)
|
177 |
-
question = '<image>\nPlease describe the image shortly.'
|
178 |
-
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
179 |
-
print(f'User: {question}')
|
180 |
-
print(f'Assistant: {response}')
|
181 |
-
|
182 |
-
# single-image multi-round conversation (单图多轮对话)
|
183 |
-
question = '<image>\nPlease describe the image in detail.'
|
184 |
-
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
|
185 |
-
print(f'User: {question}')
|
186 |
-
print(f'Assistant: {response}')
|
187 |
-
|
188 |
-
question = 'Please write a poem according to the image.'
|
189 |
-
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=history, return_history=True)
|
190 |
-
print(f'User: {question}')
|
191 |
-
print(f'Assistant: {response}')
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
pixel_values =
|
197 |
-
|
198 |
-
|
199 |
-
question = '
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
print(f'
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
print(f'
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
```
|
331 |
-
|
332 |
-
## 简介
|
333 |
-
|
334 |
-
我们很高兴宣布 InternVL 2.0 的发布,这是 InternVL 系列多模态大语言模型的最新版本。InternVL 2.0 提供了多种指令微调的模型,参数从 20 亿到 1080 亿不等。此仓库包含经过指令微调的 InternVL2-2B 模型。
|
335 |
-
|
336 |
-
与最先进的开源多模态大语言模型相比,InternVL 2.0 超越了大多数开源模型。它在各种能力上表现出与闭源商业模型相媲美的竞争力,包括文档和图表理解、信息图表问答、场景文本理解和 OCR 任务、科学和数学问题解决,以及文化理解和综合多模态能力。
|
337 |
-
|
338 |
-
InternVL 2.0 使用 8k 上下文窗口进行训练,训练数据包含长文本、多图和视频数据,与 InternVL 1.5 相比,其处理这些类型输入的能力显著提高。更多详细信息,请参阅我们的博客和 GitHub。
|
339 |
-
|
340 |
-
## 模型细节
|
341 |
-
|
342 |
-
InternVL 2.0 是一个多模态大语言模型系列,包含各种规模的模型。对于每个规模的模型,我们都会发布针对多模态任务优化的指令微调模型。InternVL2-2B 包含 [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px)、一个 MLP 投影器和 [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b)。
|
343 |
-
|
344 |
-
## 性能测试
|
345 |
-
|
346 |
-
| 评测数据集 | PaliGemma-3B | Phi-3-Vision | Mini-InternVL-2B-1.5 | InternVL2-2B |
|
347 |
-
| :--------------------------: | :----------: | :----------: | :------------------: | :----------: |
|
348 |
-
| 模型大小 | 2.9B | 4.2B | 2.2B | 2.2B |
|
349 |
-
| | | | | |
|
350 |
-
| DocVQA<sub>test</sub> | - | - | 85.0 | 86.9 |
|
351 |
-
| ChartQA<sub>test</sub> | - | 81.4 | 74.8 | 76.2 |
|
352 |
-
| InfoVQA<sub>test</sub> | - | - | 55.4 | 58.9 |
|
353 |
-
| TextVQA<sub>val</sub> | 68.1 | 70.9 | 70.5 | 73.4 |
|
354 |
-
| OCRBench | 614 | 639 | 654 | 784 |
|
355 |
-
| MME<sub>sum</sub> | 1686.1 | 1508.0 | 1901.5 | 1876.8 |
|
356 |
-
| RealWorldQA | 55.2 | 58.8 | 57.9 | 57.3 |
|
357 |
-
| AI2D<sub>test</sub> | 68.3 | 76.7 | 69.8 | 74.1 |
|
358 |
-
| MMMU<sub>val</sub> | 34.9 | 40.4 | 34.6 | 34.3 |
|
359 |
-
| MMBench-EN<sub>test</sub> | 71.0 | 73.6 | 70.9 | 73.2 |
|
360 |
-
| MMBench-CN<sub>test</sub> | 63.6 | - | 66.2 | 70.9 |
|
361 |
-
| CCBench<sub>dev</sub> | 29.6 | 24.1 | 63.5 | 74.7 |
|
362 |
-
| MMVet<sub>GPT-4-0613</sub> | - | - | 39.3 | 44.6 |
|
363 |
-
| MMVet<sub>GPT-4-Turbo</sub> | 33.1 | 44.1 | 35.5 | 39.5 |
|
364 |
-
| SEED-Image | 69.6 | 70.9 | 69.8 | 71.6 |
|
365 |
-
| HallBench<sub>avg</sub> | 32.2 | 39.0 | 37.5 | 37.9 |
|
366 |
-
| MathVista<sub>testmini</sub> | 28.7 | 44.5 | 41.1 | 46.3 |
|
367 |
-
|
368 |
-
- 我们同时使用 InternVL 和 VLMEvalKit 仓库进行模型评估。具体来说,DocVQA、ChartQA、InfoVQA、TextVQA、MME、AI2D、MMBench、CCBench、MMVet 和 SEED-Image 的结果是使用 InternVL 仓库测试的。MMMU、OCRBench、RealWorldQA、HallBench 和 MathVista 是使用 VLMEvalKit 进行评估的。
|
369 |
-
|
370 |
-
- 请注意,使用不同的测试工具包(如 InternVL 和 VLMEvalKit)评估同一模型可能会导致细微差异,这是正常的。代码版本的更新、环境和硬件的变化也可能导致结果的微小差异。
|
371 |
-
|
372 |
-
- 需要提到的是,我们报告的 MMVet 分数是使用 GPT-4-0613 作为评判模型评估的。不同版本的 GPT-4 会导致该数据集分数的显著变化。例如,使用 GPT-4-Turbo 会导致分数显著降低。
|
373 |
-
|
374 |
-
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
375 |
-
|
376 |
-
## 开源许可证
|
377 |
-
|
378 |
-
该项目采用 MIT 许可证发布,而 InternLM 则采用 Apache-2.0 许可证。
|
379 |
-
|
380 |
-
## 引用
|
381 |
-
|
382 |
-
如果您发现此项目对您的研究有用,可以考虑引用我们的论文:
|
383 |
-
|
384 |
-
```BibTeX
|
385 |
-
@article{chen2023internvl,
|
386 |
-
title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},
|
387 |
-
author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},
|
388 |
-
journal={arXiv preprint arXiv:2312.14238},
|
389 |
-
year={2023}
|
390 |
-
}
|
391 |
-
@article{chen2024far,
|
392 |
-
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
393 |
-
author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
|
394 |
-
journal={arXiv preprint arXiv:2404.16821},
|
395 |
-
year={2024}
|
396 |
-
}
|
397 |
-
```
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
pipeline_tag: visual-question-answering
|
4 |
+
---
|
5 |
+
|
6 |
+
# InternVL2-2B
|
7 |
+
|
8 |
+
[\[📂 GitHub\]](https://github.com/OpenGVLab/InternVL) [\[🆕 Blog\]](https://internvl.github.io/blog/) [\[📜 InternVL 1.0 Paper\]](https://arxiv.org/abs/2312.14238) [\[📜 InternVL 1.5 Report\]](https://arxiv.org/abs/2404.16821)
|
9 |
+
|
10 |
+
[\[🗨️ Chat Demo\]](https://internvl.opengvlab.com/) [\[🤗 HF Demo\]](https://huggingface.co/spaces/OpenGVLab/InternVL) [\[🚀 Quick Start\]](#quick-start) [\[📖 中文解读\]](https://zhuanlan.zhihu.com/p/675877376)
|
11 |
+
|
12 |
+
## Introduction
|
13 |
+
|
14 |
+
We are excited to announce the release of InternVL 2.0, the latest addition to the InternVL series of multimodal large language models. InternVL 2.0 features a variety of instruction-tuned models, ranging from 2 billion to 108 billion parameters. This repository contains the instruction-tuned InternVL2-2B model.
|
15 |
+
|
16 |
+
Compared to the state-of-the-art open-source multimodal large language models, InternVL 2.0 surpasses most open-source models. It demonstrates competitive performance on par with proprietary commercial models across various capabilities, including document and chart comprehension, infographics QA, scene text understanding and OCR tasks, scientific and mathematical problem solving, as well as cultural understanding and integrated multimodal capabilities.
|
17 |
+
|
18 |
+
InternVL 2.0 is trained with an 8k context window and utilizes training data consisting of long texts, multiple images, and videos, significantly improving its ability to handle these types of inputs compared to InternVL 1.5. For more details, please refer to our blog and GitHub.
|
19 |
+
|
20 |
+
## Model Details
|
21 |
+
|
22 |
+
InternVL 2.0 is a multimodal large language model series, featuring models of various sizes. For each size, we release instruction-tuned models optimized for multimodal tasks. InternVL2-2B consists of [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px), an MLP projector, and [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b).
|
23 |
+
|
24 |
+
## Performance
|
25 |
+
|
26 |
+
| Benchmark | PaliGemma-3B | Phi-3-Vision | Mini-InternVL-2B-1.5 | InternVL2-2B |
|
27 |
+
| :--------------------------: | :----------: | :----------: | :------------------: | :----------: |
|
28 |
+
| Model Size | 2.9B | 4.2B | 2.2B | 2.2B |
|
29 |
+
| | | | | |
|
30 |
+
| DocVQA<sub>test</sub> | - | - | 85.0 | 86.9 |
|
31 |
+
| ChartQA<sub>test</sub> | - | 81.4 | 74.8 | 76.2 |
|
32 |
+
| InfoVQA<sub>test</sub> | - | - | 55.4 | 58.9 |
|
33 |
+
| TextVQA<sub>val</sub> | 68.1 | 70.9 | 70.5 | 73.4 |
|
34 |
+
| OCRBench | 614 | 639 | 654 | 784 |
|
35 |
+
| MME<sub>sum</sub> | 1686.1 | 1508.0 | 1901.5 | 1876.8 |
|
36 |
+
| RealWorldQA | 55.2 | 58.8 | 57.9 | 57.3 |
|
37 |
+
| AI2D<sub>test</sub> | 68.3 | 76.7 | 69.8 | 74.1 |
|
38 |
+
| MMMU<sub>val</sub> | 34.9 | 40.4 | 34.6 | 34.3 |
|
39 |
+
| MMBench-EN<sub>test</sub> | 71.0 | 73.6 | 70.9 | 73.2 |
|
40 |
+
| MMBench-CN<sub>test</sub> | 63.6 | - | 66.2 | 70.9 |
|
41 |
+
| CCBench<sub>dev</sub> | 29.6 | 24.1 | 63.5 | 74.7 |
|
42 |
+
| MMVet<sub>GPT-4-0613</sub> | - | - | 39.3 | 44.6 |
|
43 |
+
| MMVet<sub>GPT-4-Turbo</sub> | 33.1 | 44.1 | 35.5 | 39.5 |
|
44 |
+
| SEED-Image | 69.6 | 70.9 | 69.8 | 71.6 |
|
45 |
+
| HallBench<sub>avg</sub> | 32.2 | 39.0 | 37.5 | 37.9 |
|
46 |
+
| MathVista<sub>testmini</sub> | 28.7 | 44.5 | 41.1 | 46.3 |
|
47 |
+
|
48 |
+
- We simultaneously use InternVL and VLMEvalKit repositories for model evaluation. Specifically, the results reported for DocVQA, ChartQA, InfoVQA, TextVQA, MME, AI2D, MMBench, CCBench, MMVet, and SEED-Image were tested using the InternVL repository. MMMU, OCRBench, RealWorldQA, HallBench, and MathVista were evaluated using the VLMEvalKit.
|
49 |
+
|
50 |
+
- Please note that evaluating the same model using different testing toolkits like InternVL and VLMEvalKit can result in slight differences, which is normal. Updates to code versions and variations in environment and hardware can also cause minor discrepancies in results.
|
51 |
+
|
52 |
+
- It is important to mention that the MMVet scores we report are evaluated using GPT-4-0613 as the judge model. Different versions of GPT-4 can lead to significant variations in the scores for this dataset. For instance, using GPT-4-Turbo would result in significantly lower scores.
|
53 |
+
|
54 |
+
Limitations: Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information.
|
55 |
+
|
56 |
+
## Quick Start
|
57 |
+
|
58 |
+
We provide an example code to run InternVL2-2B using `transformers`.
|
59 |
+
|
60 |
+
> Please use transformers==4.37.2 to ensure the model works normally.
|
61 |
+
|
62 |
+
```python
|
63 |
+
import torch
|
64 |
+
import torchvision.transforms as T
|
65 |
+
from PIL import Image
|
66 |
+
from torchvision.transforms.functional import InterpolationMode
|
67 |
+
from transformers import AutoModel, AutoTokenizer
|
68 |
+
|
69 |
+
IMAGENET_MEAN = (0.485, 0.456, 0.406)
|
70 |
+
IMAGENET_STD = (0.229, 0.224, 0.225)
|
71 |
+
|
72 |
+
|
73 |
+
def build_transform(input_size):
|
74 |
+
MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
|
75 |
+
transform = T.Compose([
|
76 |
+
T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
|
77 |
+
T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
|
78 |
+
T.ToTensor(),
|
79 |
+
T.Normalize(mean=MEAN, std=STD)
|
80 |
+
])
|
81 |
+
return transform
|
82 |
+
|
83 |
+
|
84 |
+
def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
|
85 |
+
best_ratio_diff = float('inf')
|
86 |
+
best_ratio = (1, 1)
|
87 |
+
area = width * height
|
88 |
+
for ratio in target_ratios:
|
89 |
+
target_aspect_ratio = ratio[0] / ratio[1]
|
90 |
+
ratio_diff = abs(aspect_ratio - target_aspect_ratio)
|
91 |
+
if ratio_diff < best_ratio_diff:
|
92 |
+
best_ratio_diff = ratio_diff
|
93 |
+
best_ratio = ratio
|
94 |
+
elif ratio_diff == best_ratio_diff:
|
95 |
+
if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
|
96 |
+
best_ratio = ratio
|
97 |
+
return best_ratio
|
98 |
+
|
99 |
+
|
100 |
+
def dynamic_preprocess(image, min_num=1, max_num=6, image_size=448, use_thumbnail=False):
|
101 |
+
orig_width, orig_height = image.size
|
102 |
+
aspect_ratio = orig_width / orig_height
|
103 |
+
|
104 |
+
# calculate the existing image aspect ratio
|
105 |
+
target_ratios = set(
|
106 |
+
(i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
|
107 |
+
i * j <= max_num and i * j >= min_num)
|
108 |
+
target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
|
109 |
+
|
110 |
+
# find the closest aspect ratio to the target
|
111 |
+
target_aspect_ratio = find_closest_aspect_ratio(
|
112 |
+
aspect_ratio, target_ratios, orig_width, orig_height, image_size)
|
113 |
+
|
114 |
+
# calculate the target width and height
|
115 |
+
target_width = image_size * target_aspect_ratio[0]
|
116 |
+
target_height = image_size * target_aspect_ratio[1]
|
117 |
+
blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
|
118 |
+
|
119 |
+
# resize the image
|
120 |
+
resized_img = image.resize((target_width, target_height))
|
121 |
+
processed_images = []
|
122 |
+
for i in range(blocks):
|
123 |
+
box = (
|
124 |
+
(i % (target_width // image_size)) * image_size,
|
125 |
+
(i // (target_width // image_size)) * image_size,
|
126 |
+
((i % (target_width // image_size)) + 1) * image_size,
|
127 |
+
((i // (target_width // image_size)) + 1) * image_size
|
128 |
+
)
|
129 |
+
# split the image
|
130 |
+
split_img = resized_img.crop(box)
|
131 |
+
processed_images.append(split_img)
|
132 |
+
assert len(processed_images) == blocks
|
133 |
+
if use_thumbnail and len(processed_images) != 1:
|
134 |
+
thumbnail_img = image.resize((image_size, image_size))
|
135 |
+
processed_images.append(thumbnail_img)
|
136 |
+
return processed_images
|
137 |
+
|
138 |
+
|
139 |
+
def load_image(image_file, input_size=448, max_num=6):
|
140 |
+
image = Image.open(image_file).convert('RGB')
|
141 |
+
transform = build_transform(input_size=input_size)
|
142 |
+
images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
|
143 |
+
pixel_values = [transform(image) for image in images]
|
144 |
+
pixel_values = torch.stack(pixel_values)
|
145 |
+
return pixel_values
|
146 |
+
|
147 |
+
|
148 |
+
path = 'radna/Triton-InternVL2-2B'
|
149 |
+
model = AutoModel.from_pretrained(
|
150 |
+
path,
|
151 |
+
torch_dtype=torch.bfloat16,
|
152 |
+
low_cpu_mem_usage=True,
|
153 |
+
trust_remote_code=True).eval().cuda()
|
154 |
+
|
155 |
+
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
156 |
+
# set the max number of tiles in `max_num`
|
157 |
+
pixel_values = load_image('./examples/image1.jpg', max_num=6).to(torch.bfloat16).cuda()
|
158 |
+
|
159 |
+
generation_config = dict(
|
160 |
+
num_beams=1,
|
161 |
+
max_new_tokens=1024,
|
162 |
+
do_sample=False,
|
163 |
+
)
|
164 |
+
|
165 |
+
# pure-text conversation (纯文本对话)
|
166 |
+
question = 'Hello, who are you?'
|
167 |
+
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
|
168 |
+
print(f'User: {question}')
|
169 |
+
print(f'Assistant: {response}')
|
170 |
+
|
171 |
+
question = 'Can you tell me a story?'
|
172 |
+
response, history = model.chat(tokenizer, None, question, generation_config, history=history, return_history=True)
|
173 |
+
print(f'User: {question}')
|
174 |
+
print(f'Assistant: {response}')
|
175 |
+
|
176 |
+
# single-image single-round conversation (单图单轮对话)
|
177 |
+
question = '<image>\nPlease describe the image shortly.'
|
178 |
+
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
179 |
+
print(f'User: {question}')
|
180 |
+
print(f'Assistant: {response}')
|
181 |
+
|
182 |
+
# single-image multi-round conversation (单图多轮对话)
|
183 |
+
question = '<image>\nPlease describe the image in detail.'
|
184 |
+
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
|
185 |
+
print(f'User: {question}')
|
186 |
+
print(f'Assistant: {response}')
|
187 |
+
|
188 |
+
question = 'Please write a poem according to the image.'
|
189 |
+
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=history, return_history=True)
|
190 |
+
print(f'User: {question}')
|
191 |
+
print(f'Assistant: {response}')
|
192 |
+
|
193 |
+
|
194 |
+
video_path = './examples/red-panda.mp4'
|
195 |
+
# pixel_values, num_patches_list = load_video(video_path, num_segments=32, max_num=1)
|
196 |
+
pixel_values, num_patches_list = load_video(video_path, num_segments=8, max_num=2)
|
197 |
+
pixel_values = pixel_values.to(torch.bfloat16).cuda()
|
198 |
+
video_prefix = '\n'.join([f'Frame{i+1}:<image>' for i in range(len(num_patches_list))])
|
199 |
+
question = video_prefix + 'What is the red panda doing?'
|
200 |
+
# Frame1:<image>\nFrame2:<image>\n...\nFrame31:<image>\n{question}
|
201 |
+
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
202 |
+
num_patches_list=num_patches_list,
|
203 |
+
history=None, return_history=True)
|
204 |
+
print(f'User: {question}')
|
205 |
+
print(f'Assistant: {response}')
|
206 |
+
|
207 |
+
question = 'Describe this video in detail.'
|
208 |
+
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
209 |
+
num_patches_list=num_patches_list,
|
210 |
+
history=history, return_history=True)
|
211 |
+
print(f'User: {question}')
|
212 |
+
print(f'Assistant: {response}')
|
213 |
+
```
|
214 |
+
|
215 |
+
## Deployment
|
216 |
+
|
217 |
+
### LMDeploy
|
218 |
+
|
219 |
+
LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
|
220 |
+
|
221 |
+
```sh
|
222 |
+
pip install lmdeploy
|
223 |
+
```
|
224 |
+
|
225 |
+
You can run batch inference locally with the following python code:
|
226 |
+
|
227 |
+
```python
|
228 |
+
from lmdeploy.vl import load_image
|
229 |
+
from lmdeploy import ChatTemplateConfig, pipeline
|
230 |
+
|
231 |
+
model = 'OpenGVLab/InternVL2-2B'
|
232 |
+
system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
|
233 |
+
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
234 |
+
chat_template_config = ChatTemplateConfig('internlm2-chat')
|
235 |
+
chat_template_config.meta_instruction = system_prompt
|
236 |
+
pipe = pipeline(model, chat_template_config=chat_template_config)
|
237 |
+
response = pipe(('describe this image', image))
|
238 |
+
print(response)
|
239 |
+
```
|
240 |
+
|
241 |
+
## License
|
242 |
+
|
243 |
+
This project is released under the MIT license, while InternLM is licensed under the Apache-2.0 license.
|
244 |
+
|
245 |
+
## Citation
|
246 |
+
|
247 |
+
If you find this project useful in your research, please consider citing:
|
248 |
+
|
249 |
+
```BibTeX
|
250 |
+
@article{chen2023internvl,
|
251 |
+
title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},
|
252 |
+
author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},
|
253 |
+
journal={arXiv preprint arXiv:2312.14238},
|
254 |
+
year={2023}
|
255 |
+
}
|
256 |
+
@article{chen2024far,
|
257 |
+
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
258 |
+
author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
|
259 |
+
journal={arXiv preprint arXiv:2404.16821},
|
260 |
+
year={2024}
|
261 |
+
}
|
262 |
+
```
|
263 |
+
|
264 |
+
## 简介
|
265 |
+
|
266 |
+
我们很高兴宣布 InternVL 2.0 的发布,这是 InternVL 系列多模态大语言模型的最新版本。InternVL 2.0 提供了多种指令微调的模型,参数从 20 亿到 1080 亿不等。此仓库包含经过指令微调的 InternVL2-2B 模型。
|
267 |
+
|
268 |
+
与最先进的开源多模态大语言模型相比,InternVL 2.0 超越了大多数开源模型。它在各种能力上表现出与闭源商业模型相媲美的竞争力,包括文档和图表理解、信息图表问答、场景文本理解和 OCR 任务、科学和数学问题解决,以及文化理解和综合多模态能力。
|
269 |
+
|
270 |
+
InternVL 2.0 使用 8k 上下文窗口进行训练,训练数据包含长文本、多图和视频数据,与 InternVL 1.5 相比,其处理这些类型输入的能力显著提高。更多详细信息,请参阅我们的博客和 GitHub。
|
271 |
+
|
272 |
+
## 模型细节
|
273 |
+
|
274 |
+
InternVL 2.0 是一个多模态大语言模型系列,包含各种规模的模型。对于每个规模的模型,我们都会发布针对多模态任务优化的指令微调模型。InternVL2-2B 包含 [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px)、一个 MLP 投影器和 [internlm2-chat-1_8b](https://huggingface.co/internlm/internlm2-chat-1_8b)。
|
275 |
+
|
276 |
+
## 性能测试
|
277 |
+
|
278 |
+
| 评测数据集 | PaliGemma-3B | Phi-3-Vision | Mini-InternVL-2B-1.5 | InternVL2-2B |
|
279 |
+
| :--------------------------: | :----------: | :----------: | :------------------: | :----------: |
|
280 |
+
| 模型大小 | 2.9B | 4.2B | 2.2B | 2.2B |
|
281 |
+
| | | | | |
|
282 |
+
| DocVQA<sub>test</sub> | - | - | 85.0 | 86.9 |
|
283 |
+
| ChartQA<sub>test</sub> | - | 81.4 | 74.8 | 76.2 |
|
284 |
+
| InfoVQA<sub>test</sub> | - | - | 55.4 | 58.9 |
|
285 |
+
| TextVQA<sub>val</sub> | 68.1 | 70.9 | 70.5 | 73.4 |
|
286 |
+
| OCRBench | 614 | 639 | 654 | 784 |
|
287 |
+
| MME<sub>sum</sub> | 1686.1 | 1508.0 | 1901.5 | 1876.8 |
|
288 |
+
| RealWorldQA | 55.2 | 58.8 | 57.9 | 57.3 |
|
289 |
+
| AI2D<sub>test</sub> | 68.3 | 76.7 | 69.8 | 74.1 |
|
290 |
+
| MMMU<sub>val</sub> | 34.9 | 40.4 | 34.6 | 34.3 |
|
291 |
+
| MMBench-EN<sub>test</sub> | 71.0 | 73.6 | 70.9 | 73.2 |
|
292 |
+
| MMBench-CN<sub>test</sub> | 63.6 | - | 66.2 | 70.9 |
|
293 |
+
| CCBench<sub>dev</sub> | 29.6 | 24.1 | 63.5 | 74.7 |
|
294 |
+
| MMVet<sub>GPT-4-0613</sub> | - | - | 39.3 | 44.6 |
|
295 |
+
| MMVet<sub>GPT-4-Turbo</sub> | 33.1 | 44.1 | 35.5 | 39.5 |
|
296 |
+
| SEED-Image | 69.6 | 70.9 | 69.8 | 71.6 |
|
297 |
+
| HallBench<sub>avg</sub> | 32.2 | 39.0 | 37.5 | 37.9 |
|
298 |
+
| MathVista<sub>testmini</sub> | 28.7 | 44.5 | 41.1 | 46.3 |
|
299 |
+
|
300 |
+
- 我们同时使用 InternVL 和 VLMEvalKit 仓库进行模型评估。具体来说,DocVQA、ChartQA、InfoVQA、TextVQA、MME、AI2D、MMBench、CCBench、MMVet 和 SEED-Image 的结果是使用 InternVL 仓库测试的。MMMU、OCRBench、RealWorldQA、HallBench 和 MathVista 是使用 VLMEvalKit 进行评估的。
|
301 |
+
|
302 |
+
- 请注意,使用不同的测试工具包(如 InternVL 和 VLMEvalKit)评估同一模型可能会导致细微差异,这是正常的。代码版本的更新、环境和硬件的变化也可能导致结果的微小差异。
|
303 |
+
|
304 |
+
- 需要提到的是,我们报告的 MMVet 分数是使用 GPT-4-0613 作为评判模型评估的。不同版本的 GPT-4 会导致该数据集分数的显著变化。例如,使用 GPT-4-Turbo 会导致分数显著降低。
|
305 |
+
|
306 |
+
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
307 |
+
|
308 |
+
## 开源许可证
|
309 |
+
|
310 |
+
该项目采用 MIT 许可证发布,而 InternLM 则采用 Apache-2.0 许可证。
|
311 |
+
|
312 |
+
## 引用
|
313 |
+
|
314 |
+
如果您发现此项目对您的研究有用,可以考虑引用我们的论文:
|
315 |
+
|
316 |
+
```BibTeX
|
317 |
+
@article{chen2023internvl,
|
318 |
+
title={InternVL: Scaling up Vision Foundation Models and Aligning for Generic Visual-Linguistic Tasks},
|
319 |
+
author={Chen, Zhe and Wu, Jiannan and Wang, Wenhai and Su, Weijie and Chen, Guo and Xing, Sen and Zhong, Muyan and Zhang, Qinglong and Zhu, Xizhou and Lu, Lewei and Li, Bin and Luo, Ping and Lu, Tong and Qiao, Yu and Dai, Jifeng},
|
320 |
+
journal={arXiv preprint arXiv:2312.14238},
|
321 |
+
year={2023}
|
322 |
+
}
|
323 |
+
@article{chen2024far,
|
324 |
+
title={How Far Are We to GPT-4V? Closing the Gap to Commercial Multimodal Models with Open-Source Suites},
|
325 |
+
author={Chen, Zhe and Wang, Weiyun and Tian, Hao and Ye, Shenglong and Gao, Zhangwei and Cui, Erfei and Tong, Wenwen and Hu, Kongzhi and Luo, Jiapeng and Ma, Zheng and others},
|
326 |
+
journal={arXiv preprint arXiv:2404.16821},
|
327 |
+
year={2024}
|
328 |
+
}
|
329 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|