Giter VIP home page Giter VIP logo

blendface's Introduction

BlendFace (ICCV2023)

    Overview The official PyTorch implementation for the following paper:

BlendFace: Re-designing Identity Encoders for Face-Swapping,
Kaede Shiohara, Xingchao Yang, Takafumi Taketomi,
ICCV 2023

Attention

This project is only for research purpose. Please do not apply it to illegal and unethical scenarios.
The code is distributed under the CC BY-NC-SA 4.0 license.

Changelog

2023/09/22: Released training code for BlendFace.
2023/09/09: Released demo code and model for face-swapping.
2023/07/21: Released demo code and pretrained models.

Recomended Development Environment

  • GPU: NVIDIA A100
  • CUDA: 11.4

Installation

Docker

(1) Pull a docker image from docker hub:

docker pull pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime

(2) Replace the absolute path to this repository in ./exec.sh.
(3) Execute the image:

bash exec.sh

Pretrained Models

We provide trained models for ArcFace and BlendFace and place them to checkpoints/.

Demo

We provide a demo code to compute identity similarities of ArcFace and BlendFace for an actual positive pair (images/anchor.png and images/positive.png), negative pair (images/anchor.png and images/negative.png), and pseudo-positive pair (images/anchor.png and images/swapped.png).

python3 demo.py

The result will be displayed as follows:

> ArcFace| Positive: 0.7967, Negative: 0.0316, Swapped: 0.6212
> BlendFace| Positive: 0.8186, Negative: -0.0497, Swapped: 0.8015

It can be seen that ArcFace underestimates the similarity for the pseudo-positive pair while BlendFace predicts properly it, which indicates BlendFace mitigates the biases while keeping the discriminativeness for the negative sample.

Face-Swapping

We also provide code for face-swapping (AEI-Net + BlendFace). The pretrained checkpoint is here.
Move to /workspace/swapping.

cd /workspace/swapping

Swap target face with source face:

python3 inference.py \
    -w checkpoints/blendswap.pth \ # path to checkpoint
    -s examples/source.png \ # path to source image
    -t examples/target.png \ # path to target image
    -o examples/output.png # path to output image

Note: source images should be aligned following InsightFace and target images should be aligned following FFHQ.

Training BlendFace

Please see training/README.md.

Acknowledgements

We borrow some code from InsightFace and FaceShifter (unofficial).

Citation

If you find our work useful for your research, please consider citing our paper:

@InProceedings{Shiohara_2023_ICCV,
    author    = {Shiohara, Kaede and Yang, Xingchao and Taketomi, Takafumi},
    title     = {BlendFace: Re-designing Identity Encoders for Face-Swapping},
    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
    month     = {October},
    year      = {2023},
    pages     = {7634-7644}
}

blendface's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blendface's Issues

Results of this model.

The swap result of this model is not good.
The similarity of the source face with the swapped face is very poor.

Note that-> I have used proper alignment methods as mentioned in this repository.

I will upload the similarity matrix and result later.

channels of Decoder

self.Decoder_inchannel = [1024, 2048, 1024, 512, 256, 128]
self.Decoder_outchannel = [1024, 512, 256, 128, 64, 32]
self.Decoder = nn.ModuleDict({f'layer_{i}' : nn.Sequential(
nn.ConvTranspose2d(self.Decoder_inchannel[i], self.Decoder_outchannel[i], kernel_size=4, stride=2, padding=1),
nn.BatchNorm2d(self.Decoder_outchannel[i]),
nn.LeakyReLU(0.1)
)for i in range(6)})

self.Decoder_inchannel1 is not equal to self.Decoder_outchannel0.is there a problem here
i think there is an issue with setting the number of channels.

Bad swap results

@mapooon
Thank you for your work.
I have been testing out your face swap model and the results seems to be quite bad.

steps taken:

  1. download blendswap.pth
  2. use insightface detector and face_align in their utils on both source and target
  3. change target to (256, 256) when converting to tensor
  4. result (supposed to be emma on cage lol)
    output

Any advice on how to make it work properly?

RuntimeError: mat1 and mat2 shapes cannot be multiplied

Is there a specific size requirement for the source and target images? I successfully swapped faces using the provided source (112x112) and target (256x256). However, when I resized the source image from 112x112 to 256x256, an error occurred.

I have no name!@cbf99791397b:/workspace/swapping$ python3 inference.py -w /workspace/checkpoints/blendswap.pth -s examples/source.png -t examples/target.png -o examples/output.png
Traceback (most recent call last):
  File "/workspace/swapping/inference.py", line 31, in <module>
    output = model(target_img, source_img)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/workspace/swapping/blendswap.py", line 60, in forward
    z_id = self.Z_e(source_img)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/container.py", line 204, in forward
    input = module(input)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/workspace/swapping/model/iresnet.py", line 151, in forward
    x = self.fc(x.float() if self.fp16 else x)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x131072 and 25088x512)

how to align faces

I notice that the result depends on how well the face is aligned, there is some script to align faces, it would be nice to be able to swap faces when the faces are not aligned

visualization

Figure 9 in your paper visualizes the images of ArcFace and BleedFace. If convenient, could you please provide some details? I really appreciate my interest in this aspect, thank you!

how to use this docker,

Hello author, thank you for your excellent work and code sharing, I have a question, how to use this docker, how to place the source data and target data in the workspace directory, and which file to run to change the face

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.