license: apache-2.0
library_name: perception-encoder
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 |
224像素 |
|
文本 |
0.31B |
1024 |
24 |
4096 |
16 |
1024 |
32词元 |
L/14 |
视觉 |
0.32B |
1024 |
24 |
4096 |
16 |
1024 |
336像素 |
|
文本 |
0.31B |
1024 |
24 |
4096 |
16 |
1024 |
32词元 |
G/14 |
视觉 |
1.88B |
1536 |
50 |
8960 |
16 |
1280 |
448像素 |
|
文本 |
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 224像素 |
PE-Core-B16-224 |
78.4 |
71.7 |
62.4 |
71.9 |
50.9 |
65.6 |
47.6 |
L/14 336像素 |
PE-Core-L14-336 |
83.5 |
77.9 |
89.0 |
84.7 |
57.1 |
73.4 |
50.3 |
G/14 448像素 |
PE-Core-G14-448 |
85.4 |
80.2 |
92.6 |
88.2 |
58.1 |
76.9 |
51.2 |
PE核心版在ObjectNet和ImageNet-A等困难基准测试中表现尤为突出。
使用指南
PE代码库
预训练代码详见: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-G14-448", 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}
}