MAKING DEEP-FAKES

Original article was published on Deep Learning on Medium


A STEP BY STEP APPROACH

Generating Deep-Fakes by using Google Collaboratory

First Step
In the first step what you really need to do is to make a Gmail account, after that open google drive, because we will be using collab so a lot of the work will be done via google drive.

Second step
Open google, and enter “First-order motion model for image animation collab”, and click the first given link or the link below.
https://colab.research.google.com/github/AliaksandrSiarohin/first-order-model/blob/master/demo.ipynb

Third Step
Make a small sample video of yourself for uploading on your google drive. You can say anything in that video, plus make sure your face is visible.

Fourth Step
Copy the given description and paste it on top of the collab cell.

After that Run it.

After running the above command it will ask you for an authorization code.

Click the link and it will give you a code, copy and paste the code in the box.
This is basically to connect you collab to google drive.

Fifth Step

Type ls see the output. You will see two directories one gdrive and the other sample data.

After that type cd gdrive/My\ Drive, tun this command

then create a directory called deepfake or deep-fake in that My drive.

Now type cd deepfake or cd deep-fake depending upon the name you chose above. Then run it you will a full path of the deepfake directory.

6th Step
Now clone the repository given by typing.
!git clone https://github.com/AliaksandrSiarohin/first-order-model
See the image below, you will find it in the first-order-model collab.

After the above step type
cd first-order-model
Then run it.

After this type the following command
!git clone https://github.com/1adrianb/face-alignment

Then type this command
cd face-alignment/

After going into the face-alignment directory, type

!pip install -r requirements.txt
run it then.

After typing the above code move back to the first-order-model directory by typing
cd ..
you will get this output

After doing all of the above things, go to your mp4 video which you uploaded and move it to first-order-model folder in google drive.

Now move the mp4 file to the first-order-model.

After moving the mp4 video, type ls to check that the video got moved in that folder.

After typing the ls command and looking at the content of the directory.
Type cd face-alignment/

After typing this type this command
!python setup.py install
then run it.

Check that the installation is complete by looking at the end of the code

after completing this type this command, cd ..

and go back to the first-order-model directory.

After coming back to this directory type in the following command
!python crop-video.py –inp zain.mp4

You have to type the name of your video which you moved to the first-order-model directory in your google drive.

Now copy the command given at the end of the result of the command given above.
it will look something like this, do remember to type the exclamation mark before the command to run it.

Now run this command.

After running the above command you will see something like this

After doing all the above stuff, type ls to check for the cropped video.

ls

Now click the link below which would be available in your collab environment.

You will see something like this

Now here what you need to do is to move the pictures to your drive by moving them, and also move the file “vox-adv-cpk.pth.tar” to you drive. Remember these are the pictures who you want to make a deep fake.

You need to copy these files to a new folder by the name “files” in the first-order-model directory.

For that, you need to create the folder inside that directory by pressing the make a copy option by right-clicking the image you want to copy.

After copying these files especially the “vox-adv-cpk.pth.tar” and the images you selected. All these files will be available in your google drive folder. After that, you need to move these files by selecting them and clicking the Move to option.

Move all these selected files to the first-order-model directory and after that make a folder with the name “files” in that directory.

Click the arrow at the extreme right of the first-order-model heading.

I have already created the files folder in the directory, you can create that too. As you will see a folder icon below this tab and it will then ask you to type its name which you can right as “files”.

After copying all your files to this folder. You can rename them like for example if one file name is “copy of got-04.png” change it to “got-04.png”. Remove the “copy of” name from each copied file in the files folder.

Do this for the main vox-adv-cpk.pth.tar file too.

After all this, its time to make a deep fake.

Finally, we will use the command given below but there is still one more thing left to do, you need to make a few changes in the given command below.

!python demo.py  --config config/dataset_name.yaml --driving_video path/to/driving --source_image path/to/source --checkpoint path/to/checkpoint --relative --adapt_scale

You can get this command from

https://github.com/AliaksandrSiarohin/first-order-model

Firstly, change the “–config config/dataset_name.yaml –driving_video”, to

–config/vox-adv-256.yaml –driving_video

after that, you need to change another argument which is after “–driving_ video” change the “path/to/driving” to “crop.mp4″

change this
--driving_video path/to/driving --source_image
to this
--driving_video crop.mp4 --source_image

Now the third thing you need to change in this command is the argument after “–source_image” which is “path/to/source” to the file you want to make a deep fake off, like the images from got or any other character.

Change this 
--source_image path/to/source --checkpoint
to this
--source_image got-01.png --checkpoint

The name that we have typed “got-01.png” is the name of the source image, which you want to make a deep fake of.

Lastly, we need to change the argument after “–checkpoint” to “files/vox-adv-cpk.pth.tar”

Chnage this
--checkpoint path/to/checkpoint --relative
to this
--checkpoint files/vox-adv-cpk.pth.tar --relative

After the three changes the entire code becomes something like this,

python demo.py  --config config/vox-adv-256.yaml --driving_video crop.mp4 --source_image got-01.png --checkpoint files/vox-adv-cpk.pth.tar --relative --adapt_scale

Do type the exclamation mark with the command to make it work. Otherwise, it will throw an error.

!python demo.py  --config config/vox-adv-256.yaml --driving_video crop.mp4 --source_image got-01.png --checkpoint files/vox-adv-cpk.pth.tar --relative --adapt_scale

Now run this command by making the changes described above and make your own deep fakes. The deep fake will be stored as results.mp4 in the first-order-model directory.

If you want to make deep fakes of some other characters do remember to add pictures in png format in the files folder inside the first-order-model directory, after that keep changing the above command with the name of the file.

!python demo.py  --config config/vox-adv-256.yaml --driving_video crop.mp4 --source_image got-01.png --checkpoint files/vox-adv-cpk.pth.tar --relative --adapt_scale

Do remember, for better quality, it will be good if you have a 256 by 256-pixel image.

For more questions do contact me without any hesitation.