说明文档
Arc2Face 模型卡片
<div align="center">
项目主页 | 原始论文 (ArXiv) | 表情适配器论文 (ArXiv) | 代码 | 🤗 Gradio 演示
</div>
🚀 新功能 (2025): Arc2Face 已扩展了细粒度的表情适配器(见下方),能够在任意面部表情下生成任意主体的图像(即使是罕见、不对称、微妙或极端的表情)。该扩展在论文 ID-Consistent, Precise Expression Generation with Blendshape-Guided Diffusion 中有详细说明。
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/exp_teaser.jpg'> </div>
简介
最初,Arc2Face 是一个基于 ID 条件的人脸模型,旨在仅根据 ArcFace ID 嵌入生成某人的多样化、ID 一致的照片。 它在 WebFace42M 人脸识别数据库的恢复版本上进行训练,并在 FFHQ 和 CelebA-HQ 上进一步微调。
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/samples_short.jpg'> </div>
模型详情
它由 2 个组件组成:
- encoder,一个微调过的 CLIP ViT-L/14 模型
- arc2face,一个微调过的 UNet 模型
两者均在 runwayml/stable-diffusion-v1-5 基础上微调而来。 编码器专为将 ID 嵌入投影到 CLIP 潜在空间而定制。 Arc2Face 将预训练骨干网络适配到 ID 到人脸生成的任务,仅以 ID 向量为条件。
ControlNet(姿态)
我们还提供了一个在 Arc2Face 之上训练的 ControlNet 模型,用于姿态控制。
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/controlnet_short.jpg'> </div>
表情适配器
我们的扩展将 Arc2Face 与一个定制的 IP-Adapter 相结合,用于生成基于 FLAME 混合变形参数的精确表情控制的 ID 一致图像。我们还提供了一个可选的参考适配器,可用于直接以输入图像为条件输出,即在一定程度上保留主体的外观和背景。您可以在报告中找到更多详细信息。
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/arc2face_exp.jpg'> </div>
下载核心模型(Arc2Face)
可以直接从此仓库下载模型,或使用 Python:
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="arc2face/config.json", local_dir="./models")
hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="arc2face/diffusion_pytorch_model.safetensors", local_dir="./models")
hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="encoder/config.json", local_dir="./models")
hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="encoder/pytorch_model.bin", local_dir="./models")
请查看我们的 GitHub 仓库 获取完整的推理说明,包括 ControlNet 和表情适配器。
使用 Diffusers 的示例用法(核心模型)
要使用 diffusers 库运行 Arc2Face 模型,首先加载管道组件:
from diffusers import (
StableDiffusionPipeline,
UNet2DConditionModel,
DPMSolverMultistepScheduler,
)
from arc2face import CLIPTextModelWrapper, project_face_embs
import torch
from insightface.app import FaceAnalysis
from PIL import Image
import numpy as np
# Arc2Face 基于 SD1.5 构建
# 可以使用下面的仓库替代已弃用的 'runwayml/stable-diffusion-v1-5'
base_model = 'stable-diffusion-v1-5/stable-diffusion-v1-5'
encoder = CLIPTextModelWrapper.from_pretrained(
'models', subfolder="encoder", torch_dtype=torch.float16
)
unet = UNet2DConditionModel.from_pretrained(
'models', subfolder="arc2face", torch_dtype=torch.float16
)
pipeline = StableDiffusionPipeline.from_pretrained(
base_model,
text_encoder=encoder,
unet=unet,
torch_dtype=torch.float16,
safety_checker=None
)
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
pipeline = pipeline.to('cuda')
然后,选择一张图像来提取 ID 嵌入:
app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
app.prepare(ctx_id=0, det_size=(640, 640))
img = np.array(Image.open('assets/examples/joacquin.png'))[:,:,::-1]
faces = app.get(img)
faces = sorted(faces, key=lambda x:(x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x['bbox'][1]))[-1] # 选择最大的人脸(如果检测到多张人脸)
id_emb = torch.tensor(faces['embedding'], dtype=torch.float16)[None].cuda()
id_emb = id_emb/torch.norm(id_emb, dim=1, keepdim=True) # 归一化嵌入
id_emb = project_face_embs(pipeline, id_emb) # 通过编码器传递
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/joacquin.png' style='width:25%;'> </div>
最后,生成图像:
num_images = 4
images = pipeline(prompt_embeds=id_emb, num_inference_steps=25, guidance_scale=3.0, num_images_per_prompt=num_images).images
<div align="center"> <img src='https://huggingface.co/foivospar/Arc2Face/resolve/main/assets/samples.jpg'> </div>
局限性与偏见
- 每张图像只能生成一个人。
- 姿态受限于正面半球范围,类似于 FFHQ 图像。
- 模型可能反映训练数据或 ID 编码器的偏见。
引用
如果您发现 Arc2Face 对您的研究有用,请考虑引用我们:
Arc2Face 的 BibTeX:
@inproceedings{paraperas2024arc2face,
title={Arc2Face: A Foundation Model for ID-Consistent Human Faces},
author={Paraperas Papantoniou, Foivos and Lattas, Alexandros and Moschoglou, Stylianos and Deng, Jiankang and Kainz, Bernhard and Zafeiriou, Stefanos},
booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
year={2024}
}
此外,如果您使用了表情适配器,请同时引用该扩展:
表情适配器的 BibTeX:
@inproceedings{paraperas2025arc2face_exp,
title={ID-Consistent, Precise Expression Generation with Blendshape-Guided Diffusion},
author={Paraperas Papantoniou, Foivos and Zafeiriou, Stefanos},
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV) Workshops},
year={2025}
}
FoivosPar/Arc2Face
作者 FoivosPar
创建时间: 2024-03-14 11:31:54+00:00
更新时间: 2025-10-08 09:23:48+00:00
在 Hugging Face 上查看