Views
No views yet
VisCPM is a family of open-source large multimodal models, which support multimodal conversational capabilities (VisCPM-Chat model) and text-to-image generation capabilities (VisCPM-Paint model) in both Chinese and English, achieving state-of-the-art peformance among Chinese open-source multimodal models. VisCPM is trained based on the large language model CPM-Bee with 10B parameters, fusing visual encoder (Q-Former) and visual decoder (Diffusion-UNet) to support visual inputs and outputs. Thanks to the good bilingual capability of CPM-Bee, VisCPM can be pre-trained with English multimodal data only and well generalize to achieve promising Chinese multimodal capabilities.VisCPM是一个开源的多模态大模型系列,支持中英双语的多模态对话能力(VisCPM-Chat模型)和文到图生成能力(VisCPM-Paint模型),在中文多模态开源模型中达到最佳水平。VisCPM基于百亿参数量语言大模型CPM-Bee(10B)训练,融合视觉编码器(Q-Former)和视觉解码器(Diffusion-UNet)以支持视觉信号的输入和输出。得益于CPM-Bee底座优秀的双语能力,VisCPM可以仅通过英文多模态数据预训练,泛化实现优秀的中文多模态能力。VisCPM-Chat支持面向图像进行中英双语多模态对话。该模型使用Q-Former作为视觉编码器,使用CPM-Bee(10B)作为语言交互基底模型,并通过语言建模训练目标融合视觉和语言模型。模型训练包括预训练和指令精调两阶段:VisCPM-Chat进行了预训练,数据包括CC3M、CC12M、COCO、Visual Genome、Laion等。在预训练阶段,语言模型参数保持固定,仅更新Q-Former部分参数,以支持大规模视觉-语言表示的高效对齐。VisCPM-Chat在中文多模态能力方面取得了最佳的平均性能,在通用域对话和复杂推理表现出色,同时也表现出了不错的英文多模态能力。| 模型 | 英文 | 中文 | |||||||
| 多模态对话 | 细节描述 | 复杂推理 | 平均 | 多模态对话 | 细节描述 | 复杂推理 | 平均 | ||
| 英文模型 | MiniGPT4 | 65 | 67.3 | 76.6 | 69.7 | - | - | - | - |
| InstructBLIP | 81.9 | 68 | 91.2 | 80.5 | - | - | - | - | |
| LLaVA | 89.5 | 70.4 | 96.2 | 85.6 | - | - | - | - | |
| 中英双语 | mPLUG-Owl | 64.6 | 47.7 | 80.1 | 64.2 | 76.3 | 61.2 | 77.8 | 72 |
| VisualGLM | 62.4 | 63 | 80.6 | 68.7 | 76.6 | 87.8 | 83.6 | 82.7 | |
| Ziya (LLaMA 13B) | 82.7 | 69.9 | 92.1 | 81.7 | 85 | 74.7 | 82.4 | 80.8 | |
| VisCPM-Chat | 83.3 | 68.9 | 90.5 | 81.1 | 92.7 | 76.1 | 89.2 | 86.3 |
VisCPM-Paint支持中英双语的文到图生成。该模型使用CPM-Bee(10B)作为文本编码器,使用UNet作为图像解码器,并通过扩散模型训练目标融合语言和视觉模型。在训练过程中,语言模型参数始终保持固定。我们使用Stable Diffusion 2.1的UNet参数初始化视觉解码器,并通过逐步解冻其中关键的桥接参数将其与语言模型融合:首先训练文本表示映射到视觉模型的线性层,然后进一步解冻UNet的交叉注意力层。该模型在LAION 2B英文图文对数据上进行了训练。VisCPM-Chat类似,我们发现得益于CPM-Bee的双语能力,VisCPM-Paint可以仅通过英文图文对训练,泛化实现良好的中文文到图生成能力,达到中文开源模型的最佳效果。通过进一步加入20M清洗后的原生中文图文对数据,以及120M翻译到中文的图文对数据,模型的中文文到图生成能力可以获得进一步提升。我们在MSCOCO上采样了3万张图片,计算了FID(Fréchet Inception Distance)和Clip Score,前者用于评估生成图片的质量,后面用于评估生成的图片与输入的匹配程度。| 模型 | 英文 | 中文 | ||
| FID↓ | CLIP Score↑ | FID↓ | CLIP Score↑ | |
| AltDiffusion | 17.16 | 25.24 | 16.09 | 24.05 |
| TaiyiDiffusion | - | - | 15.58 | 22.69 |
| Stable Diffusion | 9.08 | 26.22 | - | - |
| VisCPM-Paint-en | 9.51 | 25.35 | 10.86 | 23.38 |
| VisCPM-Paint-zh | 9.98 | 25.04 | 9.65 | 24.17 |
1conda create -n viscpm python=3.10 -y
2conda activate viscpm
3pip install setuptools
4pip install diffusers jieba matplotlib numpy opencv_python
5pip install pandas Pillow psutil pydantic scipy
6pip install torch==1.13.1 torchscale==0.2.0 torchvision==0.14.1 timm
7pip install transformers==4.28.0
8pip install tqdm typing_extensions
9pip install git+https://github.com/thunlp/OpenDelta.git
10pip install git+https://github.com/OpenBMB/CPM-Bee.git#egg=cpm-live&subdirectory=src1>>> from transformers import AutoModel, AutoTokenizer, AutoImageProcessor
2>>> from PIL import Image
3
4>>> tokenizer = AutoTokenizer.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True)
5>>> processor = AutoImageProcessor.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True)
6>>> model = AutoModel.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True).to('cuda')
7
8>>> data = [{
9>>> 'context': '',
10>>> 'question': 'describe this image in detail.',
11>>> 'image': tokenizer.unk_token * model.query_num,
12>>> '<ans>': ''
13>>> }]
14>>> image = Image.open('case.jpg')
15>>> result = model.generate(data, tokenizer, processor, image)
16>>> print(result[0]['<ans>'])
17这幅图片显示了一群热气球在天空中飞行。这些热气球漂浮在不同的地方,包括山脉、城市和乡村地区。