library_name: perception-encoder
license: apache-2.0
pipeline_tag: zero-shot-image-classification
模型详情
\[📄 技术报告\]
\[📖 Github\]
感知编码器(Perception Encoder,PE)是通过简单视觉-语言学习训练的最先进的图像和视频理解编码器。该模型在论文《感知编码器:最佳视觉嵌入不在网络输出端》中首次提出。
模型开发者: Meta
模型概述: 感知编码器(PE)是一系列大规模视觉编码器模型,在多种视觉任务上实现了最先进的性能。通过使用鲁棒的对比预训练方案并在合成对齐的视频上进行微调,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 tokens |
L/14 |
视觉 |
0.32B |
1024 |
24 |
4096 |
16 |
1024 |
336px |
|
文本 |
0.31B |
1024 |
24 |
4096 |
16 |
1024 |
32 tokens |
G/14 |
视觉 |
1.88B |
1536 |
50 |
8960 |
16 |
1280 |
448px |
|
文本 |
0.47B |
1280 |
24 |
5120 |
20 |
1280 |
72 tokens |
所有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)上表现尤为突出。
使用方法
模型加载代码
我们在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配置:", 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(["一个图表", "一只狗", "一只猫"]).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("标签概率:", text_probs)
更多详情请参见GitHub仓库。
引用
如果您发现我们的代码对研究有帮助,请考虑引用:
@article{bolya2025PerceptionEncoder,
title={感知编码器:最佳视觉嵌入不在网络输出端},
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:开放获取的详细视觉理解数据和模型},
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}
}