Views
No views yet




1from huggingface_hub import hf_hub_download
2
3hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="arc2face/config.json", local_dir="./models")
4hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="arc2face/diffusion_pytorch_model.safetensors", local_dir="./models")
5hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="encoder/config.json", local_dir="./models")
6hf_hub_download(repo_id="FoivosPar/Arc2Face", filename="encoder/pytorch_model.bin", local_dir="./models")diffusers library, first load the pipeline components:1from diffusers import (
2 StableDiffusionPipeline,
3 UNet2DConditionModel,
4 DPMSolverMultistepScheduler,
5)
6
7from arc2face import CLIPTextModelWrapper, project_face_embs
8
9import torch
10from insightface.app import FaceAnalysis
11from PIL import Image
12import numpy as np
13
14# Arc2Face is built upon SD1.5
15# The repo below can be used instead of the now deprecated 'runwayml/stable-diffusion-v1-5'
16base_model = 'stable-diffusion-v1-5/stable-diffusion-v1-5'
17
18encoder = CLIPTextModelWrapper.from_pretrained(
19 'models', subfolder="encoder", torch_dtype=torch.float16
20)
21
22unet = UNet2DConditionModel.from_pretrained(
23 'models', subfolder="arc2face", torch_dtype=torch.float16
24)
25
26pipeline = StableDiffusionPipeline.from_pretrained(
27 base_model,
28 text_encoder=encoder,
29 unet=unet,
30 torch_dtype=torch.float16,
31 safety_checker=None
32 )
33pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
34pipeline = pipeline.to('cuda')1app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
2app.prepare(ctx_id=0, det_size=(640, 640))
3
4img = np.array(Image.open('assets/examples/joacquin.png'))[:,:,::-1]
5
6faces = app.get(img)
7faces = sorted(faces, key=lambda x:(x['bbox'][2]-x['bbox'][0])*(x['bbox'][3]-x['bbox'][1]))[-1] # select largest face (if more than one detected)
8id_emb = torch.tensor(faces['embedding'], dtype=torch.float16)[None].cuda()
9id_emb = id_emb/torch.norm(id_emb, dim=1, keepdim=True) # normalize embedding
10id_emb = project_face_embs(pipeline, id_emb) # pass through the encoder
1num_images = 4
2images = pipeline(prompt_embeds=id_emb, num_inference_steps=25, guidance_scale=3.0, num_images_per_prompt=num_images).images
1@inproceedings{paraperas2024arc2face,
2 title={Arc2Face: A Foundation Model for ID-Consistent Human Faces},
3 author={Paraperas Papantoniou, Foivos and Lattas, Alexandros and Moschoglou, Stylianos and Deng, Jiankang and Kainz, Bernhard and Zafeiriou, Stefanos},
4 booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
5 year={2024}
6}1@inproceedings{paraperas2025arc2face_exp,
2 title={ID-Consistent, Precise Expression Generation with Blendshape-Guided Diffusion},
3 author={Paraperas Papantoniou, Foivos and Zafeiriou, Stefanos},
4 booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV) Workshops},
5 year={2025}
6}