模型简介
模型特点
模型能力
使用案例
🚀 MiniCPM-V 2.6:手机端适用的单图像、多图像和视频的GPT - 4V级别多模态大语言模型
MiniCPM-V 2.6是一款功能强大的多模态大语言模型,能够处理单图像、多图像和视频输入,在性能、效率和易用性方面表现出色,为用户提供了便捷高效的多模态交互体验。
📢 最新消息
- [2025.01.14] 🔥🔥 我们开源了 MiniCPM-o 2.6,相较于 MiniCPM-V 2.6 有显著的性能提升,并且支持实时语音对话和多模态直播,快来试试吧。
✨ MiniCPM-V 2.6 主要特性
MiniCPM-V 2.6 是MiniCPM-V系列中最新且功能最强大的模型。该模型基于SigLip - 400M和Qwen2 - 7B构建,总参数达80亿。与MiniCPM-Llama3-V 2.5相比,它的性能有显著提升,并为多图像和视频理解引入了新特性。MiniCPM-V 2.6的显著特性包括:
- 🔥 卓越性能:在最新版本的OpenCompass上,MiniCPM-V 2.6在8个流行基准测试中取得了平均65.2分的成绩。仅80亿参数的它,在单图像理解方面超越了广泛使用的专有模型,如GPT - 4o mini、GPT - 4V、Gemini 1.5 Pro和Claude 3.5 Sonnet。
- 🖼️ 多图像理解与上下文学习:MiniCPM-V 2.6还能进行 多图像对话和推理。在Mantis - Eval、BLINK、Mathverse mv和Sciverse mv等流行的多图像基准测试中,它达到了 业界领先水平,并展现出了出色的上下文学习能力。
- 🎬 视频理解:MiniCPM-V 2.6可以 接受视频输入,进行对话并为时空信息提供密集字幕。在有/无字幕的Video - MME测试中,它的表现优于 GPT - 4V、Claude 3.5 Sonnet和LLaVA - NeXT - Video - 34B。
- 💪 强大的OCR能力及其他特性:MiniCPM-V 2.6可以处理任意宽高比且像素高达180万(如1344x1344)的图像。在OCRBench上,它达到了 业界领先水平,超越了GPT - 4o、GPT - 4V和Gemini 1.5 Pro等专有模型。基于最新的 RLAIF - V 和 VisCPM 技术,它具备 可靠的行为,在Object HalBench上的幻觉率显著低于GPT - 4o和GPT - 4V,并支持英语、中文、德语、法语、意大利语、韩语等 多语言能力。
- 🚀 卓越效率:除了模型规模友好外,MiniCPM-V 2.6还展现了 业界领先的令牌密度(即每个视觉令牌编码的像素数)。处理180万像素的图像时,它仅生成640个令牌,比大多数模型少75%。这直接提高了推理速度、首令牌延迟、内存使用和功耗。因此,MiniCPM-V 2.6可以在iPad等终端设备上高效支持 实时视频理解。
- 💫 易于使用:MiniCPM-V 2.6可以通过多种方式轻松使用:(1) llama.cpp 和 ollama 支持在本地设备上进行高效的CPU推理;(2) 提供 int4 和 GGUF 格式的16种量化模型;(3) vLLM 支持高吞吐量和内存高效推理;(4) 可在新领域和任务上进行微调;(5) 可使用 Gradio 快速搭建本地WebUI演示;(6) 提供在线Web 演示。
📊 评估

单图像评估结果(OpenCompass、MME、MMVet、OCRBench、MMMU、MathVista、MMB、AI2D、TextVQA、DocVQA、HallusionBench、Object HalBench)
多图像评估结果(Mantis Eval、BLINK Val、Mathverse mv、Sciverse mv、MIRB)
视频评估结果(Video - MME和Video - ChatGPT)
点击查看TextVQA、VizWiz、VQAv2、OK - VQA的少样本评估结果。
🌟 示例





点击查看更多示例。


我们在终端设备上部署了MiniCPM-V 2.6。演示视频是在iPad Pro上的原始屏幕录制,未进行编辑。




💻 演示
点击此处尝试 MiniCPM-V 2.6 的演示。
💻 使用示例
基础用法
在NVIDIA GPU上使用Huggingface transformers进行推理。在Python 3.10上测试的依赖项如下:
Pillow==10.1.0
torch==2.1.2
torchvision==0.16.2
transformers==4.40.0
sentencepiece==0.1.99
decord
# test.py
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
image = Image.open('xx.jpg').convert('RGB')
question = 'What is in the image?'
msgs = [{'role': 'user', 'content': [image, question]}]
res = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer
)
print(res)
## if you want to use streaming, please make sure sampling=True and stream=True
## the model.chat will return a generator
res = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer,
sampling=True,
stream=True
)
generated_text = ""
for new_text in res:
generated_text += new_text
print(new_text, flush=True, end='')
高级用法
多图像对话
点击查看使用多图像输入运行MiniCPM-V 2.6的Python代码。
```python import torch from PIL import Image from transformers import AutoModel, AutoTokenizermodel = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True, attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager model = model.eval().cuda() tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
image1 = Image.open('image1.jpg').convert('RGB') image2 = Image.open('image2.jpg').convert('RGB') question = 'Compare image 1 and image 2, tell me about the differences between image 1 and image 2.'
msgs = [{'role': 'user', 'content': [image1, image2, question]}]
answer = model.chat( image=None, msgs=msgs, tokenizer=tokenizer ) print(answer)
</details>
#### 上下文少样本学习
<details>
<summary> 点击查看使用少样本输入运行MiniCPM-V 2.6的Python代码。 </summary>
```python
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
question = "production date"
image1 = Image.open('example1.jpg').convert('RGB')
answer1 = "2023.08.04"
image2 = Image.open('example2.jpg').convert('RGB')
answer2 = "2007.04.24"
image_test = Image.open('test.jpg').convert('RGB')
msgs = [
{'role': 'user', 'content': [image1, question]}, {'role': 'assistant', 'content': [answer1]},
{'role': 'user', 'content': [image2, question]}, {'role': 'assistant', 'content': [answer2]},
{'role': 'user', 'content': [image_test, question]}
]
answer = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer
)
print(answer)
视频对话
点击查看使用视频输入运行MiniCPM-V 2.6的Python代码。
```python import torch from PIL import Image from transformers import AutoModel, AutoTokenizer from decord import VideoReader, cpu # pip install decordmodel = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True, attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager model = model.eval().cuda() tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
MAX_NUM_FRAMES=64 # if cuda OOM set a smaller number
def encode_video(video_path): def uniform_sample(l, n): gap = len(l) / n idxs = [int(i * gap + gap / 2) for i in range(n)] return [l[i] for i in idxs]
vr = VideoReader(video_path, ctx=cpu(0))
sample_fps = round(vr.get_avg_fps() / 1) # FPS
frame_idx = [i for i in range(0, len(vr), sample_fps)]
if len(frame_idx) > MAX_NUM_FRAMES:
frame_idx = uniform_sample(frame_idx, MAX_NUM_FRAMES)
frames = vr.get_batch(frame_idx).asnumpy()
frames = [Image.fromarray(v.astype('uint8')) for v in frames]
print('num frames:', len(frames))
return frames
video_path ="video_test.mp4" frames = encode_video(video_path) question = "Describe the video" msgs = [ {'role': 'user', 'content': frames + [question]}, ]
Set decode params for video
params={} params["use_image_id"] = False params["max_slice_nums"] = 2 # use 1 if cuda OOM and video resolution > 448*448
answer = model.chat( image=None, msgs=msgs, tokenizer=tokenizer, **params ) print(answer)
</details>
更多使用细节请查看 [GitHub](https://github.com/OpenBMB/MiniCPM-V)。
## 📦 llama.cpp推理
MiniCPM-V 2.6可以使用llama.cpp运行。更多详情请查看我们的 [llama.cpp](https://github.com/OpenBMB/llama.cpp/tree/minicpm-v2.5/examples/minicpmv) 分支。
## 📦 Int4量化版本
下载Int4量化版本以减少GPU内存(7GB)使用:[MiniCPM-V-2_6-int4](https://huggingface.co/openbmb/MiniCPM-V-2_6-int4)。
## 📄 许可证
#### 模型许可证
* 本仓库中的代码遵循 [Apache - 2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) 许可证发布。
* MiniCPM-V系列模型权重的使用必须严格遵循 [MiniCPM Model License.md](https://github.com/OpenBMB/MiniCPM/blob/main/MiniCPM%20Model%20License.md)。
* MiniCPM的模型和权重完全免费用于学术研究。填写 ["问卷"](https://modelbest.feishu.cn/share/base/form/shrcnpV5ZT9EJ6xYjh3Kx0J6v8g) 进行注册后,MiniCPM-V 2.6的权重也可免费用于商业用途。
#### 声明
* 作为一个多模态大语言模型,MiniCPM-V 2.6通过学习大量多模态语料生成内容,但它无法理解、表达个人观点或进行价值判断。MiniCPM-V 2.6生成的任何内容均不代表模型开发者的观点和立场。
* 我们不对使用MinCPM-V模型产生的任何问题负责,包括但不限于数据安全问题、舆论风险,或因模型误导、误用、传播或滥用而产生的任何风险和问题。
## 🔧 关键技术及其他多模态项目
👏 欢迎探索MiniCPM-V 2.6的关键技术和我们团队的其他多模态项目:
[VisCPM](https://github.com/OpenBMB/VisCPM/tree/main) | [RLHF-V](https://github.com/RLHF-V/RLHF-V) | [LLaVA-UHD](https://github.com/thunlp/LLaVA-UHD) | [RLAIF-V](https://github.com/RLHF-V/RLAIF-V)
## 📖 引用
如果您觉得我们的工作有帮助,请考虑引用我们的论文 📝 并给这个项目点赞 ❤️!
```bib
@article{yao2024minicpm,
title={MiniCPM-V: A GPT-4V Level MLLM on Your Phone},
author={Yao, Yuan and Yu, Tianyu and Zhang, Ao and Wang, Chongyi and Cui, Junbo and Zhu, Hongji and Cai, Tianchi and Li, Haoyu and Zhao, Weilin and He, Zhihui and others},
journal={arXiv preprint arXiv:2408.01800},
year={2024}
}








