Deepfake Detection with Python

In this article, I will take you through Deepfake Detection with Python and Machine Learning. I recently wrote an article on what is Deepfake and how it is dangerous. If you don’t know what is Deepfake then I will suggest you have a quick look at my previous article here, before getting your hands dirty with the task of Deepfake detection with Python and Machine Learning.

Deepfake Detection with Python

There have been many reports of fake videos of popular celebrities or politicians. These fake videos are difficult to detect with the naked eye and are becoming a major problem in society.

Also, Read – Machine Learning Full Course for free.

It has been experienced so far that the Deepfake videos go easily viral at platforms like Facebook, twitter, youtube, etc. As these platforms work to fix this issue, Facebook is making a big investment ($ 10 million) to fix this issue, and other platforms like Twitter and Google are also working on fixing this issue.

Deepfake detection is therefore not an easy task. In this article, we will see how to identify the fakes from the real ones. It includes decomposing videos into a frame, detecting faces from real and fake videos, cropping faces and analyzing them.

Deepfake Detection in Action

Now let’s see how we can detection Deepfake content by using Python and Machine Learning. I will get started with this task by importing the necessary libraries:

Now, let’s say we have two types of videos one real and one fake we want to detect which is the fake one amongst the two, probably this is what we need to do in the task of Deepfake detection.

Now, I will create a function to process both the videos:

Calling The function:

extract_multiple_videos(fake_video_name, fake_image_path_for_frame) extract_multiple_videos(real_video_name, real_image_path_for_frame)

Now after running the function we will be able the read the videos and process them for our task of Deepfake detection. Now let’s see how we can identify the Deepfakes by comparing both the videos:

In the code above, we comparing the extracted images from the original video and the corresponding image from fake videos. In the last section of the code, I checked if both the two images have any differences.

Output:

Deepfake detection

So this is how we can detect the Deepfakes by comparing the original and fake files. I hope you liked this article on Deepfake Detection with Python and Machine Learning. Feel free to ask your valuable questions in the comments section below.

Follow Us:

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply