模型简介
模型特点
模型能力
使用案例
🚀 【ICLR 2024 🔥】LanguageBind: 通过基于语言的语义对齐将视频-语言预训练扩展到 N 模态
LanguageBind 是一种以语言为中心的多模态预训练方法,借助语言作为不同模态间的纽带,可轻松扩展到分割、检测等任务,还提出了包含视频、红外、深度、音频及对应语言的 VIDAL - 10M 大规模数据集,并通过多视图增强语言描述,提升训练效果。
📄 新闻动态
- [2024.01.27] 👀👀👀 我们的 [MoE - LLaVA](https://github.com/PKU - YuanGroup/MoE - LLaVA) 发布啦!一个 30 亿参数的稀疏模型性能超越了 70 亿参数的密集模型。
- [2024.01.16] 🔥🔥🔥 我们的 LanguageBind 已被 ICLR 2024 接收!我们在此 链接 获得了 6(3)8(6)6(6)6(6) 的评分。
- [2023.12.15] 💪💪💪 我们扩展了 💥💥💥 VIDAL 数据集,现在拥有 1000 万条视频 - 文本数据。我们推出了 LanguageBind_Video 1.5,查看我们的 模型库。
- [2023.12.10] 我们扩展了 💥💥💥 VIDAL 数据集,现在拥有 1000 万条深度数据和 1000 万条热成像数据。我们正在 [Hugging Face](https://huggingface.co/datasets/LanguageBind/VIDAL - Depth - Thermal) 上上传热成像和深度数据,预计整个过程将持续 1 - 2 个月。
- [2023.11.27] 🔥🔥🔥 我们更新了 论文,包含紧急零样本结果,查看我们的 ✨ 结果。
- [2023.11.26] 💥💥💥 我们开源了所有文本源和对应的 YouTube ID,详情见 此处。
- [2023.11.26] 📣📣📣 我们开源了全量微调的 视频 & 音频 模型,性能再次提升,查看我们的 模型库。
- [2023.11.22] 我们即将发布全量微调版本,超大版本 目前正在训练中。
- [2023.11.20] 🚀🚀🚀 [Video - LLaVA](https://github.com/PKU - YuanGroup/Video - LLaVA) 基于 LanguageBind 编码器构建了一个大型视觉 - 语言模型,实现了 🎉 最优性能。
- [2023.10.23] 🎶 LanguageBind - Audio 在 5 个数据集上实现了 🎉🎉🎉 最优 (SOTA) 性能,查看我们的 ✨ 结果!
- [2023.10.14] 😱 发布了更强的 LanguageBind - Video,查看我们的 ✨ [结果](#视频 - 语言)! 视频检查点已在 Huggingface 模型中心 更新!
- [2023.10.10] 我们提供了示例数据,可在 assets 中找到,并描述了 紧急零样本使用方法。
- [2023.10.07] 检查点可在 🤗 Huggingface 模型 上获取。
- [2023.10.04] 代码和 演示 现已可用!欢迎 关注 👀 此仓库以获取最新更新。
✨ 主要特性
💡 高性能,无需中间模态
LanguageBind 是一种 以语言为中心 的多模态预训练方法,以语言作为不同模态之间的纽带,因为语言模态已经得到了充分探索,并且包含丰富的语义信息。
- 下图展示了 LanguageBind 的架构。LanguageBind 可以轻松扩展到分割、检测任务,并且有可能扩展到无限的模态。
⚡️ 多模态、完全对齐且数据量大的数据集
我们提出了 VIDAL - 10M,这是一个包含 视频、红外、深度、音频 及其对应 语言 的 1000 万条数据 的数据集,极大地扩展了视觉模态之外的数据。
- 第二张图展示了我们提出的 VIDAL - 10M 数据集,它包括视频、红外、深度、音频和语言五种模态。
🔥 用于训练的多视图增强描述
我们对语言进行了多视图增强。我们生成了结合 元数据、空间 和 时间 的多视图描述,以极大地增强语言的语义信息。此外,我们还使用 ChatGPT 进一步 增强语言,为每个模态对齐的语言创建一个良好的语义空间。
🤗 演示
本地演示
强烈推荐尝试我们的网页演示,它集成了 LanguageBind 当前支持的所有功能。
python gradio_app.py
在线演示
我们在 Huggingface Spaces 上提供了 在线演示。在这个演示中,你可以计算模态与语言之间的相似度,例如音频与语言、视频与语言以及深度与图像之间的相似度。
📦 安装指南
- Python >= 3.8
- Pytorch >= 1.13.1
- CUDA 版本 >= 11.6
- 安装所需的包:
git clone https://github.com/PKU-YuanGroup/LanguageBind
cd LanguageBind
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
pip install -r requirements.txt
🐳 模型库
表格中的名称代表不同的编码器模型。例如,LanguageBind/LanguageBind_Video_FT
代表全量微调版本,而 LanguageBind/LanguageBind_Video
代表 LoRA 微调版本。
你可以在推荐的 API 使用方法 中自由替换它们。我们建议使用全量微调版本,因为它具有更强的性能。
模态 | LoRA 微调 | 全量微调 |
---|---|---|
视频 | LanguageBind_Video | LanguageBind_Video_FT |
音频 | LanguageBind_Audio | LanguageBind_Audio_FT |
深度 | LanguageBind_Depth | - |
热成像 | LanguageBind_Thermal | - |
版本 | 微调方式 | 模型大小 | 帧数 | HF 链接 | MSR - VTT | DiDeMo | ActivityNet | MSVD |
---|---|---|---|---|---|---|---|---|
LanguageBind_Video | LoRA | 大 | 8 | 链接 | 42.6 | 37.8 | 35.1 | 52.2 |
LanguageBind_Video_FT | 全量微调 | 大 | 8 | 链接 | 42.7 | 38.1 | 36.9 | 53.5 |
LanguageBind_Video_V1.5_FT | 全量微调 | 大 | 8 | 链接 | 42.8 | 39.7 | 38.4 | 54.1 |
LanguageBind_Video_V1.5_FT | 全量微调 | 大 | 12 | 即将推出 | - | - | - | - |
LanguageBind_Video_Huge_V1.5_FT | 全量微调 | 超大 | 8 | 链接 | 44.8 | 39.9 | 41.0 | 53.7 |
LanguageBind_Video_Huge_V1.5_FT | 全量微调 | 超大 | 12 | 即将推出 | - | - | - | - |
💻 使用示例
基础用法
我们在 assets 中提供了一些示例数据集,以便快速了解 LanguageBind 的工作原理。
import torch
from languagebind import LanguageBind, to_device, transform_dict, LanguageBindImageTokenizer
if __name__ == '__main__':
device = 'cuda:0'
device = torch.device(device)
clip_type = {
'video': 'LanguageBind_Video_FT', # also LanguageBind_Video
'audio': 'LanguageBind_Audio_FT', # also LanguageBind_Audio
'thermal': 'LanguageBind_Thermal',
'image': 'LanguageBind_Image',
'depth': 'LanguageBind_Depth',
}
model = LanguageBind(clip_type=clip_type, cache_dir='./cache_dir')
model = model.to(device)
model.eval()
pretrained_ckpt = f'lb203/LanguageBind_Image'
tokenizer = LanguageBindImageTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir/tokenizer_cache_dir')
modality_transform = {c: transform_dict[c](model.modality_config[c]) for c in clip_type.keys()}
image = ['assets/image/0.jpg', 'assets/image/1.jpg']
audio = ['assets/audio/0.wav', 'assets/audio/1.wav']
video = ['assets/video/0.mp4', 'assets/video/1.mp4']
depth = ['assets/depth/0.png', 'assets/depth/1.png']
thermal = ['assets/thermal/0.jpg', 'assets/thermal/1.jpg']
language = ["Training a parakeet to climb up a ladder.", 'A lion climbing a tree to catch a monkey.']
inputs = {
'image': to_device(modality_transform['image'](image), device),
'video': to_device(modality_transform['video'](video), device),
'audio': to_device(modality_transform['audio'](audio), device),
'depth': to_device(modality_transform['depth'](depth), device),
'thermal': to_device(modality_transform['thermal'](thermal), device),
}
inputs['language'] = to_device(tokenizer(language, max_length=77, padding='max_length',
truncation=True, return_tensors='pt'), device)
with torch.no_grad():
embeddings = model(inputs)
print("Video x Text: \n",
torch.softmax(embeddings['video'] @ embeddings['language'].T, dim=-1).detach().cpu().numpy())
print("Image x Text: \n",
torch.softmax(embeddings['image'] @ embeddings['language'].T, dim=-1).detach().cpu().numpy())
print("Depth x Text: \n",
torch.softmax(embeddings['depth'] @ embeddings['language'].T, dim=-1).detach().cpu().numpy())
print("Audio x Text: \n",
torch.softmax(embeddings['audio'] @ embeddings['language'].T, dim=-1).detach().cpu().numpy())
print("Thermal x Text: \n",
torch.softmax(embeddings['thermal'] @ embeddings['language'].T, dim=-1).detach().cpu().numpy())
运行上述代码后,将返回以下结果:
Video x Text:
[[9.9989331e-01 1.0667283e-04]
[1.3255903e-03 9.9867439e-01]]
Image x Text:
[[9.9990666e-01 9.3292067e-05]
[4.6132666e-08 1.0000000e+00]]
Depth x Text:
[[0.9954276 0.00457235]
[0.12042473 0.8795753 ]]
Audio x Text:
[[0.97634876 0.02365119]
[0.02917843 0.97082156]]
Thermal x Text:
[[0.9482511 0.0517489 ]
[0.48746133 0.5125386 ]]
高级用法
由于 LanguageBind 将每个模态绑定在一起,我们还发现了 紧急零样本 功能。使用起来非常简单。
print("Video x Audio: \n", torch.softmax(embeddings['video'] @ embeddings['audio'].T, dim=-1).detach().cpu().numpy())
print("Image x Depth: \n", torch.softmax(embeddings['image'] @ embeddings['depth'].T, dim=-1).detach().cpu().numpy())
print("Image x Thermal: \n", torch.softmax(embeddings['image'] @ embeddings['thermal'].T, dim=-1).detach().cpu().numpy())
运行上述代码后,你将得到:
Video x Audio:
[[1.0000000e+00 0.0000000e+00]
[3.1150486e-32 1.0000000e+00]]
Image x Depth:
[[1. 0.]
[0. 1.]]
Image x Thermal:
[[1. 0.]
[0. 1.]]
🤖 API
我们开源了所有模态的预处理代码。如果你想从 Huggingface 模型中心或本地加载模型(例如 LanguageBind/LanguageBind_Thermal
),可以使用以下代码片段!
热成像
import torch
from languagebind import LanguageBindThermal, LanguageBindThermalTokenizer, LanguageBindThermalProcessor
pretrained_ckpt = 'LanguageBind/LanguageBind_Thermal'
model = LanguageBindThermal.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
tokenizer = LanguageBindThermalTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
thermal_process = LanguageBindThermalProcessor(model.config, tokenizer)
model.eval()
data = thermal_process([r"your/thermal.jpg"], ['your text'], return_tensors='pt')
with torch.no_grad():
out = model(**data)
print(out.text_embeds @ out.image_embeds.T)
深度
import torch
from languagebind import LanguageBindDepth, LanguageBindDepthTokenizer, LanguageBindDepthProcessor
pretrained_ckpt = 'LanguageBind/LanguageBind_Depth'
model = LanguageBindDepth.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
tokenizer = LanguageBindDepthTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
depth_process = LanguageBindDepthProcessor(model.config, tokenizer)
model.eval()
data = depth_process([r"your/depth.png"], ['your text.'], return_tensors='pt')
with torch.no_grad():
out = model(**data)
print(out.text_embeds @ out.image_embeds.T)
视频
import torch
from languagebind import LanguageBindVideo, LanguageBindVideoTokenizer, LanguageBindVideoProcessor
pretrained_ckpt = 'LanguageBind/LanguageBind_Video_FT' # also 'LanguageBind/LanguageBind_Video'
model = LanguageBindVideo.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
tokenizer = LanguageBindVideoTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
video_process = LanguageBindVideoProcessor(model.config, tokenizer)
model.eval()
data = video_process(["your/video.mp4"], ['your text.'], return_tensors='pt')
with torch.no_grad():
out = model(**data)
print(out.text_embeds @ out.image_embeds.T)
音频
import torch
from languagebind import LanguageBindAudio, LanguageBindAudioTokenizer, LanguageBindAudioProcessor
pretrained_ckpt = 'LanguageBind/LanguageBind_Audio_FT' # also 'LanguageBind/LanguageBind_Audio'
model = LanguageBindAudio.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
tokenizer = LanguageBindAudioTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
audio_process = LanguageBindAudioProcessor(model.config, tokenizer)
model.eval()
data = audio_process([r"your/audio.wav"], ['your audio.'], return_tensors='pt')
with torch.no_grad():
out = model(**data)
print(out.text_embeds @ out.image_embeds.T)
图像
请注意,我们的图像编码器与 OpenCLIP 相同。不像其他模态那样经过微调。
import torch
from languagebind import LanguageBindImage, LanguageBindImageTokenizer, LanguageBindImageProcessor
pretrained_ckpt = 'LanguageBind/LanguageBind_Image'
model = LanguageBindImage.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
tokenizer = LanguageBindImageTokenizer.from_pretrained(pretrained_ckpt, cache_dir='./cache_dir')
image_process = LanguageBindImageProcessor(model.config, tokenizer)
model.eval()
data = image_process([r"your/image.jpg"], ['your text.'], return_tensors='pt')
with torch.no_grad():
out = model(**data)
print(out.text_embeds @ out.image_embeds.T)
💥 VIDAL - 10M
数据集详情请见 DATASETS.md。
🗝️ 训练与验证
训练和验证说明请见 TRAIN_AND_VALIDATE.md。
👍 致谢
- OpenCLIP 一个开源的预训练框架。
- CLIP4Clip 一个开源的视频 - 文本检索框架。
- [sRGB - TIR](https://github.com/rpmsnu/sRGB - TIR) 一个用于生成红外(热成像)图像的开源框架。
- GLPN 一个用于生成深度图像的开源框架。
🔒 许可证
- 本项目的大部分内容遵循 MIT 许可证,详情见 [LICENSE](https://github.com/PKU - YuanGroup/LanguageBind/blob/main/LICENSE) 文件。
- 本项目的数据集遵循 CC - BY - NC 4.0 许可证,详情见 [DATASET_LICENSE](https://github.com/PKU - YuanGroup/LanguageBind/blob/main/DATASET_LICENSE) 文件。
✏️ 引用
如果您发现我们的论文和代码在您的研究中很有用,请考虑给我们点个星 :star: 并引用 :pencil:。
@misc{zhu2023languagebind,
title={LanguageBind: Extending Video-Language Pretraining to N-modality by Language-based Semantic Alignment},
author={Bin Zhu and Bin Lin and Munan Ning and Yang Yan and Jiaxi Cui and Wang HongFa and Yatian Pang and Wenhao Jiang and Junwu Zhang and Zongwei Li and Cai Wan Zhang and Zhifeng Li and Wei Liu and Li Yuan},
year={2023},
eprint={2310.01852},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
✨ 星标历史
[](https://star - history.com/#PKU - YuanGroup/LanguageBind&Date)
🤝 贡献者










