🚀 感知编码器(Perception Encoder)
感知编码器(Perception Encoder)是一种通过简单的视觉 - 语言学习训练的先进编码器,用于图像和视频理解。它能在多种视觉任务中展现出卓越性能,为下游任务提供强大的通用特征。
🚀 快速开始
感知编码器(PE)是一系列大规模视觉编码器模型,在众多视觉任务中表现出色。通过使用强大的对比预训练方法并在合成对齐视频上进行微调,PE不仅在分类和检索任务上超越了所有现有模型,还能在内部生成强大的通用特征,以支持下游任务。
✨ 主要特性
- 先进性能:在零样本图像分类和检索以及零样本视频分类和检索等任务中取得了极其出色的结果。
- 多规模选择:提供了不同规模的模型配置,包括B/16、L/14和G/14,以满足不同的应用需求。
- 通用特征:内部生成的强大通用特征可有效迁移到下游任务。
📦 安装指南
我们在 https://github.com/facebookresearch/perception_models 提供了模型加载代码。
git clone https://github.com/facebookresearch/perception_models.git
cd perception_models
conda create --name perception_models python=3.12
conda activate perception_models
# 安装PyTorch
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 xformers --index-url https://download.pytorch.org/whl/cu124
# 我们使用torchcodec将视频解码为PyTorch张量
conda install ffmpeg -c conda-forge
pip install torchcodec==0.1 --index-url=https://download.pytorch.org/whl/cu124
pip install -e .
这将安装可编辑版本的仓库,允许您在不每次重新安装包的情况下对代码进行更改。
💻 使用示例
基础用法
import torch
from PIL import Image
import core.vision_encoder.pe as pe
import core.vision_encoder.transforms as transforms
print("CLIP configs:", pe.CLIP.available_configs())
model = pe.CLIP.from_config("PE-Core-B16-224", pretrained=True)
model = model.cuda()
preprocess = transforms.get_image_transform(model.image_size)
tokenizer = transforms.get_text_tokenizer(model.context_length)
image = preprocess(Image.open("docs/assets/cat.png")).unsqueeze(0).cuda()
text = tokenizer(["a diagram", "a dog", "a cat"]).cuda()
with torch.no_grad(), torch.autocast("cuda"):
image_features, text_features, logit_scale = model(image, text)
text_probs = (logit_scale * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs)
您可以在GitHub仓库中找到更多详细信息。
📚 详细文档
模型详情
📃 技术报告
📂 Github
感知编码器(PE)是一种通过简单的视觉 - 语言学习训练的先进编码器,用于图像和视频理解。它在论文 "Perception Encoder: The best visual embeddings are not at the output of the network" 中被提出。
模型开发者:Meta
模型概述:感知编码器(PE)是一系列大规模视觉编码器模型,在多种视觉任务中具有先进的性能。通过使用强大的对比预训练方法并在合成对齐视频上进行微调,PE不仅在分类和检索任务上超越了所有现有模型,还能在内部生成强大的通用特征,以支持下游任务。PE通过对齐调整解锁了大规模对比预训练向利用这些通用特征的下游任务迁移的能力。

模型配置
PE核心目前有3种规模。PE核心G是主要的检查点,L和B模型是从它蒸馏而来的。
规模 |
塔 |
参数 |
宽度 |
深度 |
MLP |
头数 |
CLIP维度 |
分辨率 / 上下文长度 |
B/16 |
视觉 |
0.09B |
768 |
12 |
3072 |
12 |
1024 |
224px |
|
文本 |
0.31B |
1024 |
24 |
4096 |
16 |
1024 |
32 个标记 |
L/14 |
视觉 |
0.32B |
1024 |
24 |
4096 |
16 |
1024 |
336px |
|
文本 |
0.31B |
1024 |
24 |
4096 |
16 |
1024 |
32 个标记 |
G/14 |
视觉 |
1.88B |
1536 |
50 |
8960 |
16 |
1280 |
448px |
|
文本 |
0.47B |
1280 |
24 |
5120 |
20 |
1280 |
72 个标记 |
所有PE核心模型在视觉塔顶部使用一个具有8个头的注意力池化块。L和B模型另外还有一个用于全局聚合的类标记。更多详细信息请参阅论文。
模型性能
PE核心在零样本图像分类和检索以及零样本视频分类和检索方面都取得了极其出色的结果。以下是其在这些领域的部分性能表现。
模型 |
检查点 |
IN-1k |
IN-v2 |
IN-A |
ObjectNet |
COCO-T2I |
Kinetics-400 |
VTT-T2I |
B/16 224px |
PE-Core-B16-224 |
78.4 |
71.7 |
62.4 |
71.9 |
50.9 |
65.6 |
47.6 |
L/14 336px |
PE-Core-L14-336 |
83.5 |
77.9 |
89.0 |
84.7 |
57.1 |
73.4 |
50.3 |
G/14 448px |
PE-Core-G14-448 |
85.4 |
80.2 |
92.6 |
88.2 |
58.1 |
76.9 |
51.2 |
PE核心在诸如ObjectNet和ImageNet - A等“困难”基准测试中表现尤为出色。
📄 许可证
本项目采用Apache - 2.0许可证。
📖 引用
如果您发现我们的代码对您的研究有用,请考虑引用:
@article{bolya2025PerceptionEncoder,
title={Perception Encoder: The best visual embeddings are not at the output of the network},
author={Daniel Bolya and Po-Yao Huang and Peize Sun and Jang Hyun Cho and Andrea Madotto and Chen Wei and Tengyu Ma and Jiale Zhi and Jathushan Rajasegaran and Hanoona Rasheed and Junke Wang and Marco Monteiro and Hu Xu and Shiyu Dong and Nikhila Ravi and Daniel Li and Piotr Doll{\'a}r and Christoph Feichtenhofer},
journal={arXiv},
year={2025}
}
@article{cho2025PerceptionLM,
title={PerceptionLM: Open-Access Data and Models for Detailed Visual Understanding},
author={Jang Hyun Cho and Andrea Madotto and Effrosyni Mavroudi and Triantafyllos Afouras and Tushar Nagarajan and Muhammad Maaz and Yale Song and Tengyu Ma and Shuming Hu and Hanoona Rasheed and Peize Sun and Po-Yao Huang and Daniel Bolya and Suyog Jain and Miguel Martin and Huiyu Wang and Nikhila Ravi and Shashank Jain and Temmy Stark and Shane Moon and Babak Damavandi and Vivian Lee and Andrew Westbury and Salman Khan and Philipp Kr\"{a}henb\"{u}hl and Piotr Doll{\'a}r and Lorenzo Torresani and Kristen Grauman and Christoph Feichtenhofer},
journal={arXiv},
year={2025}
}