faceswap使用手冊

cd faceswappython

cd faceswap-mastergit

python faceswap.py gui程序員

 

Notice: This repository is not operated or maintained by /u/deepfakes. Please read the explanation below for details.github

deepfakes_faceswapshell

Faceswap is a tool that utilizes deep learning to recognize and swap faces in pictures and videos.api

Faceswap是一種利用深度學習來識別和交換圖片和視頻中的人臉的工具。app


Manifestoless

Faceswap is not porn.ide

When faceswaping using an AI was first developed and became published, the technology was groundbreaking, it was a huge step in AI development. It was also completely ignored outside of academia. The code was confusing and fragmentary, it required a thorough understanding of state of the art AI techniques and a lot of effort to get anything out of it. One individual brought it together into one cohesive collection. It ran, it worked, and as is so often the way with new technology emerging on the internet, it was immediately used to create porn. The problem was that this was the first AI code that anyone could download, run and learn by experimentation without becoming a PHD candidate in math, computer theory, psychology, and more. Before "deepfakes" these techniques were like black magic, only practiced by those who could understand all of the inner workings as described in esoteric and endlessly complicated books and papers.工具

當使用人工智能進行人臉掃描首次開發並出版時,這項技術是突破性的,它是人工智能開發中的一個巨大步驟。它在學術界以外也被徹底忽視了。這段代碼既混亂又支離破碎,它須要對最早進的人工智能技術有一個透徹的理解,而且須要大量的努力才能從中獲得任何東西。一我的把它集中到一個有凝聚力的集合中。它運行,它起做用,就像互聯網上出現新技術的方式同樣,它馬上被用來製做色情。問題是,這是第一我的工智能代碼,任何人均可以經過實驗下載、運行和學習,而沒必要成爲數學、計算機理論、心理學等領域的博士生。在「深挖」以前,這些技巧就像黑色魔法,只有那些可以理解全部內在工做的人才能使用,如深奧和無休止複雜的書籍和論文所描述的。

"Deepfakes" changed all that and anyone could participate in AI development. To us developers, the release of this code has opened up a fantastic learning opportunity. To build on ideas developed by others, to collaborate with coders with a huge variety of skills, to experiment with AI whilst learning new skills and ultimately contribute towards an emerging technology which will only see more mainstream use as it progresses.

「Deepfakes」改變了這一切,任何人均可以參與人工智能的開發。對於咱們的開發人員來講,這段代碼的發佈爲咱們提供了一個極好的學習機會。以其餘人開發的想法爲基礎,與具備豐富技能的編碼人員合做,在學習新技能的同時進行人工智能實驗,並最終爲一項新興技術作出貢獻,而這項技術只有在不斷髮展的過程當中才能看到更多的主流應用。

Are there some out there doing horrible things with similar software? Yes. And because of this, the developers have been following strict ethical standards. Many of us don't even use it to create videos at all, we just tinker with the code to see what it all does. Sadly, the media concentrates only on the unethical uses of this software. That is unfortunately a nature of how it was first exposed to the public, but it is not representative of why it was created, how we use it now, or what we see in it's future. Like any technology, it can be used for good or it can be abused. It is our intention to develop faceswap in a way that it's potential for abuse is minimized whilst maximizing it's potential as a tool for learning, experimenting and, yes, for legitimate faceswaping.

有沒有一些人用相似的軟件作可怕的事情?對。正由於如此,開發商一直遵循嚴格的道德標準。咱們中的許多人甚至根本不使用它來建立視頻,咱們只是修補代碼,看看它都作了什麼。不幸的是,媒體只關注這個軟件的不道德使用。不幸的是,這是它首次向公衆公開的本質,但它並不能表明它的產生緣由、咱們如今如何使用它,或者咱們在它的將來看到什麼。像任何技術同樣,它能夠被用於好的方面,也能夠被濫用。咱們的目的是以一種方式開發Faceswap,它的濫用潛力被最小化,同時最大限度地發揮它做爲學習、試驗和合法的Faceswap工具的潛力。

We are not trying to denigrate celebrities or to demean anyone. We are programmers, we are engineers, we are Hollywood VFX artists, we are activists, we are hobbyists, we are human beings. To this end, we feel that it's time to come out with a standard statement of what this software is and isn't as far as us developers are concerned.

咱們不想貶低名人或貶低任何人。咱們是程序員,咱們是工程師,咱們是好萊塢的視覺特效藝術家,咱們是活動家,咱們是業餘愛好者,咱們是人類。爲此,咱們認爲是時候拿出一個標準聲明來講明這個軟件什麼是而什麼不是美國開發者所關心的。

  • Faceswap is not for creating porn     Faceswap不用於建立色情
  • Faceswap is not for changing faces without consent or with the intent of hiding it's use.    Faceswap不適用於未經贊成或意圖隱藏其用途的更改面。
  • Faceswap is not for any illicit, unethical, or questionable purposes.   faceswap不用於任何非法、不道德或可疑的目的。
  • Faceswap exists to experiment and discover AI techniques, for social or political commentary, for movies, and for any number of ethical and reasonable uses.    Faceswap的存在是爲了試驗和發現人工智能技術、社會或政治評論、電影以及任何道德和合理的用途。

We are very troubled by the fact that faceswap can be used for unethical and disreputable things. However, we support the development of tools and techniques that can be used ethically as well as provide education and experience in AI for anyone who wants to learn it hands-on. We will take a zero tolerance approach to anyone using this software for any unethical purposes and will actively discourage any such uses.咱們很不安的事實是,faceswap能夠用於不道德和不名譽的事情。然而,咱們支持開發可用於倫理的工具和技術,併爲任何想親自學習人工智能的人提供教育和經驗。咱們將對任何出於任何不道德目的使用本軟件的人採起零容忍的方法,並將積極鼓勵任何此類使用。

How To setup and run the project如何設置和運行項目

Faceswap is a Python program that will run on multiple Operating Systems including Windows, Linux and MacOS.

See INSTALL.md for full installation instructions. You will need a modern GPU with CUDA support for best performance.

Overview概況

The project has multiple entry points. You will have to:該項目有多個入口點。你必須:

  • Gather photos (or use the one provided in the training data provided below) 收集圖像(或使用下面提供的訓練數據)
  • Extract faces from your raw photos 從原始照片中提取人臉
  • Train a model on your photos (or use the one provided in the training data provided below) 在照片上訓練模型(或使用下面提供的訓練數據中提供的模型)
  • Convert your sources with the model 用上一步訓練好的模型轉換你的源

Check out USAGE.md for more detailed instructions. 查看USAGE.md裏面有更詳細的指導

Extract提取

From your setup folder, run python faceswap.py extract. This will take photos from src folder and extract faces into extract folder.

從安裝文件夾中,運行python faceswap.py extract。這將從SRC文件夾拍攝照片,並將面提取到extract文件夾中。

Train

From your setup folder, run python faceswap.py train. This will take photos from two folders containing pictures of both faces and train a model that will be saved inside the models folder.

從設置文件夾中,運行python faceswap.py train。這將從包含兩個面的圖片的兩個文件夾中拍攝照片,並訓練將保存在model文件夾中的模型。

Convert

From your setup folder, run python faceswap.py convert. This will take photos from original folder and apply new faces into modified folder.

從安裝文件夾中,運行python faceswap.py convert。這將從原始文件夾拍攝照片,並將新面應用到modified文件夾中。

GUI

Alternatively you can run the GUI by running python faceswap.py gui

或者,您能夠經過運行python faceswap.py gui來運行gui。

General notes:

  • All of the scripts mentioned have -h/--help options with arguments that they will accept. You're smart, you can figure out how this works, right?!

NB: there is a conversion tool for video. This can be accessed by running python tools.py effmpeg -h. Alternatively you can use ffmpeg to convert video into photos, process images, and convert images back to video.

Some tips:

Reusing existing models will train much faster than starting from nothing.
If there is not enough training data, start with someone who looks similar, then switch the data.

Help I need support!

Discord Server

Your best bet is to join the Faceswap Discord server where there are plenty of users willing to help. Please note that, like this repo, this is a SFW Server!

Faceswap-Playground

Alternatively you can post questions in the Faceswap Playground. Please do not post general support questions in this repo.

How to contribute

For people interested in the generative models

  • Go to the 'faceswap-model' to discuss/suggest/commit alternatives to the current algorithm.

For devs

  • Read this README entirely
  • Fork the repo
  • Download the data with the link provided above
  • Play with it
  • Check issues with the 'dev' tag
  • For devs more interested in computer vision and openCV, look at issues with the 'opencv' tag. Also feel free to add your own alternatives/improvments

For non-dev advanced users

  • Read this README entirely
  • Clone the repo
  • Download the data with the link provided above
  • Play with it
  • Check issues with the 'advuser' tag
  • Also go to the 'faceswap-playground' repo and help others.

For end-users

  • Get the code here and play with it if you can
  • You can also go to the 'faceswap-playground' repo and help or get help from others.
  • Be patient. This is relatively new technology for developers as well. Much effort is already being put into making this program easy to use for the average user. It just takes time!
  • Notice Any issue related to running the code has to be open in the 'faceswap-playground' project!

For haters

Sorry, no time for that.

About github.com/deepfakes

What is this repo?

It is a community repository for active users.

Why this repo?

The joshua-wu repo seems not active. Simple bugs like missing http:// in front of urls have not been solved since days.

Why is it named 'deepfakes' if it is not /u/deepfakes?

  1. Because a typosquat would have happened sooner or later as project grows
  2. Because we wanted to recognize the original author
  3. Because it will better federate contributors and users

What if /u/deepfakes feels bad about that?

This is a friendly typosquat, and it is fully dedicated to the project. If /u/deepfakes wants to take over this repo/user and drive the project, he is welcomed to do so (Raise an issue, and he will be contacted on Reddit). Please do not send /u/deepfakes messages for help with the code you find here.

About machine learning

How does a computer know how to recognise/shape a faces? How does machine learning work? What is a neural network?

It's complicated. Here's a good video that makes the process understandable: 

Here's a slightly more in depth video that tries to explain the basic functioning of a neural network: 

tl;dr: training data + trial and error

 

 

 

 

 

 

faceswap/USAGE.md

Before attempting any of this, please make sure you have read, understood and completed the installation instructions. If you are experiencing issues, please raise them in the faceswap-playground repository instead of the main repo.

Workflow

So, you want to swap faces in pictures and videos? Well hold up, because first you gotta understand what this collection of scripts will do, how it does it and what it can't currently do.

The basic operation of this script is simple. It trains a machine learning model to recognize and transform two faces based on pictures. The machine learning model is our little "bot" that we're teaching to do the actual swapping and the pictures are the "training data" that we use to train it. Note that the bot is primarily processing faces. Other objects might not work.

So here's our plan. We want to create a reality where Donald Trump lost the presidency to Nic Cage; we have his inauguration video; let's replace Trump with Cage.

Gathering raw data

In order to accomplish this, the bot needs to learn to recognize both face A (Trump) and face B (Nic Cage). By default, the bot doesn't know what a Trump or a Nic Cage looks like. So we need to show it some pictures and let it guess which is which. So we need pictures of both of these faces first.

A possible source is Google, DuckDuckGo or Bing image search. There are scripts to download large amounts of images. Alternatively, if you have a video of the person you're looking for (from interviews, public speeches, or movies), you can convert this video to still images and use those. see Extracting video frames for more information.

Feel free to list your image sets in the faceswap-playground, or add more methods to this file.

So now we have a folder full of pictures of Trump and a separate folder of Nic Cage. Let's save them in our directory where we put the faceswap project. Example: ~/faceswap/photo/trump and ~/faceswap/photo/cage

EXTRACT

So here's a problem. We have a ton of pictures of both our subjects, but they're just pictures of them doing stuff or in an environment with other people. Their bodies are on there, they're on there with other people... It's a mess. We can only train our bot if the data we have is consistent and focusses on the subject we want to swap. This is where faceswap first comes in.

# To convert trump: python faceswap.py extract -i ~/faceswap/photo/trump -o ~/faceswap/data/trump # To convert cage: python faceswap.py extract -i ~/faceswap/photo/cage -o ~/faceswap/data/cage

We specify our photo input directory and the output folder where our training data will be saved. The script will then try its best to recognize face landmarks, crop the image to that size, and save it to the output folder. Note: this script will make grabbing test data much easier, but it is not perfect. It will (incorrectly) detect multiple faces in some photos and does not recognize if the face is the person who we want to swap. Therefore: Always check your training data before you start training. The training data will influence how good your model will be at swapping.

You can see the full list of arguments for extracting via help flag. i.e.

python faceswap.py extract -h

TRAIN

The training process will take the longest, especially on CPU. We specify the folders where the two faces are, and where we will save our training model. It will start hammering the training data once you run the command. I personally really like to go by the preview and quit the processing once I'm happy with the results.

python faceswap.py train -A ~/faceswap/data/trump -B ~/faceswap/data/cage -m ~/faceswap/models/ # or -p to show a preview python faceswap.py train -A ~/faceswap/data/trump -B ~/faceswap/data/cage -m ~/faceswap/models/ -p 

If you use the preview feature, select the preview window and press ENTER to save your processed data and quit gracefully. Without the preview enabled, you might have to forcefully quit by hitting Ctrl+C to cancel the command. Note that it will save the model once it's gone through about 100 iterations, which can take quite a while. So make sure you save before stopping the process.

You can see the full list of arguments for training via help flag. i.e.

python faceswap.py train -h

CONVERT

Now that we're happy with our trained model, we can convert our video. How does it work? Similarly to the extraction script, actually! The conversion script basically detects a face in a picture using the same algorithm, quickly crops the image to the right size, runs our bot on this cropped image of the face it has found, and then (crudely) pastes the processed face back into the picture.

Remember those initial pictures we had of Trump? Let's try swapping a face there. We will use that directory as our input directory, create a new folder where the output will be saved, and tell them which model to use.

python faceswap.py convert -i ~/faceswap/photo/trump/ -o ~/faceswap/output/ -m ~/faceswap/models/

It should now start swapping faces of all these pictures.

You can see the full list of arguments available for converting via help flag. i.e.

python faceswap.py convert -h

GUI

All of the above commands and options can be run from the GUI. This is launched with:

python faceswap.py gui

Video's

A video is just a series of pictures in the form of frames. Therefore you can gather the raw images from them for your dataset or combine your results into a video.

EFFMPEG

You can perform various video processes with the built in effmpeg tool. You can see the full list of arguments available by running:

python tools.py effmpeg -h

Extracting video frames with FFMPEG

Alternatively you can split a video into seperate frames using ffmpeg for instance. Below is an example command to process a video to seperate frames.

ffmpeg -i /path/to/my/video.mp4 /path/to/output/video-frame-%d.png

Generating a video

If you split a video, using ffmpeg for example, and used them as a target for swapping faces onto you can combine these frames again. The command below stitches the png frames back into a single video again.

ffmpeg -i video-frame-%0d.png -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4

Notes

This guide is far from complete. Functionality may change over time, and new dependencies are added and removed as time goes on.

If you are experiencing issues, please raise them in the faceswap-playground repository instead of the main repo.

相關文章
相關標籤/搜索