Falcon Perception 是一个拥有 0.6B 参数的早期融合视觉语言模型,专门用于开放词汇接地与实例分割任务。给定一张图像和一个自然语言查询,该模型能够返回零个、一个或多个匹配实例,并提供像素级精确的掩码。
该模型围绕简洁的接口构建。图像块和文本标记通过单一 Transformer 协同处理,并采用混合注意力掩码:图像标记构建双向视觉上下文,而文本和任务标记则在图像条件下进行因果解码。对于每个实例,模型按固定顺序生成简短的结构化任务标记序列,即先 <|coord|>,再 <|size|>,最后 <|seg|>。其中,<|seg|> 标记作为掩码查询,其隐藏状态经投影后与上采样图像特征进行点积运算,无需自回归掩码生成即可产生全分辨率的二值掩码。
https://github.com/tiiuae/Falcon-Perceptiontiiuae/PBenchtiiuae/Falcon-OCRpip install "torch>=2.5" transformers pillow einops pycocotools该模型需要 PyTorch 2.5 或更新版本以支持 FlexAttention。首次调用可能会较慢,因为 torch.compile 可能需要构建优化的内核。
import torch
from PIL import Image
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"tiiuae/falcon-perception",
trust_remote_code=True,
device_map={"": "cuda:0"},
)
image = Image.open("photo.jpg")
preds = model.generate(image, "cat")[0]
for p in preds:
print(p["xy"], p["hw"])import numpy as np
from pycocotools import mask as mask_utils
for p in preds:
rle = p["mask_rle"]
# pycocotools expects bytes for counts
m = {"size": rle["size"], "counts": rle["counts"].encode("utf-8")}
mask = mask_utils.decode(m).astype(bool) # H x W
print(mask.shape, mask.sum())model.generate(images, queries, **kwargs)| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
images | PIL.Image 或 list | 必需 | 单张图像或图像列表 |
queries | str 或 list[str] | 必需 | 查询字符串,每张图像对应一个 |
max_new_tokens | int | 2048 | 最大解码步数 |
min_dimension | int | 256 | 调整大小后图像边的最小尺寸 |
max_dimension | int | 1024 | 调整大小后图像边的最大尺寸 |
compile | bool | True | 首次调用时运行 torch.compile |
返回值: list[list[dict]],每张图像对应一个列表。
每个预测字典包含:
{
"xy": {"x": float, "y": float}, # center in normalized coordinates (0 to 1)
"hw": {"h": float, "w": float}, # size in normalized coordinates (0 to 1)
"mask_rle": {"counts": str, "size": [H, W]}, # COCO RLE at original resolution
}Falcon Perception 专为密集目标定位场景设计,其主要挑战在于开放词汇条件下的目标定位。这包括:
它并非旨在作为通用的视觉-语言助手,无法用于开放式推理、长文本生成或多步骤视觉问答(VQA)。
该架构采用单栈早期融合方案:
<|coord|>、<|size|> 和 <|seg|><|seg|> 令牌成为一个掩码查询,并通过与上采样图像特征的点积生成全分辨率掩码技术报告显示:
完整表格、设置细节和消融实验详见报告。
如果您使用 Falcon Perception,请引用:
@article{bevli2026falcon,
title = {Falcon Perception},
author = {Bevli, Aviraj and Chaybouti, Sofian and Dahou, Yasser and Hacid, Hakim and Huynh, Ngoc Dung and Le Khac, Phuc H. and Narayan, Sanath and Para, Wamiq Reyaz and Singh, Ankit},
journal = {arXiv preprint arXiv:2603.27365},
year = {2026},
url = {https://arxiv.org/abs/2603.27365}
}