HuggingFace镜像/PE-Core-S16-384
模型介绍
文件和版本
分析

模型详情

[

📃技术报告📃 技术报告📃技术报告

](https://arxiv.org/abs/2504.13181) [

📂Github📂 Github📂Github

](https://github.com/facebookresearch/perception_models/)

感知编码器(Perception Encoder, PE)是一种通过简单的视觉-语言学习训练的先进编码器,用于图像和视频理解。它在论文《Perception Encoder: The best visual embeddings are not at the output of the network》中首次提出。

模型开发者:Meta

模型概述:感知编码器(PE)是一系列大规模视觉编码器模型,在多种视觉任务上均实现了最先进的性能。通过采用稳健的对比预训练方案,并在合成对齐视频上进行微调,PE不仅在分类和检索任务上超越了现有所有模型,还能在内部生成强大的通用特征,可扩展用于下游任务。PE通过对齐调优,使大规模对比预训练能够迁移至下游任务,充分利用这些通用特征。

感知编码器:核心版

PE核心版是我们的基础模型,通过稳健的图像预训练计划进行训练,并在由我们的合成视频数据引擎生成的数据上进行微调。

模型配置

PE核心版目前提供3种尺寸。PE核心版G是主要检查点,L和B模型则是从G模型蒸馏而来。

规模网络塔参数数量宽度深度MLP头数CLIP维度分辨率/上下文长度
B/16视觉0.09B768123072121024224px
文本0.31B102424409616102432 tokens
L/14视觉0.32B1024244096161024336px
文本0.31B102424409616102432 tokens
G/14视觉1.88B1536508960161280448px
文本0.47B128024512020128072 tokens

所有PE核心版模型在视觉塔顶部均使用具有8个头的注意力池化块。此外,L和B模型还具有用于全局聚合的类别标记。更多详情请参见论文。

模型性能

PE核心版在零样本图像分类与检索,以及零样本视频分类与检索任务中均取得了全面且优异的成绩。以下展示其在这些领域的部分性能表现。

模型检查点IN-1kIN-v2IN-AObjectNetCOCO-T2IKinetics-400VTT-T2I
B/16 224pxPE-Core-B16-22478.471.762.471.950.965.647.6
L/14 336pxPE-Core-L14-33683.577.989.084.757.173.450.3
G/14 448pxPE-Core-G14-44885.480.292.688.258.176.951.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
# Install PyTorch
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 xformers --index-url https://download.pytorch.org/whl/cu124
# We use torchcodec for decoding videos into PyTorch tensors
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())
# CLIP configs: ['PE-Core-G14-448', 'PE-Core-L14-336', 'PE-Core-B16-224']

model = pe.CLIP.from_config("PE-Core-L14-336", pretrained=True)  # Downloads from HF
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)  # prints: [[0.0, 0.0, 1.0]]

更多详情可在 GitHub 仓库中查看。

引用

如果您发现我们的代码对您的研究有所帮助,请考虑引用:

@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}
}