Deepfake Detection using Deep Learning Code Walkthrough (Part 1)

Abhijit Jadhav
2 min readMay 12, 2022

Deepfakes are indistinguishable human synthesized images created using deep learning algorithms. In simple terms, we can say that deepfakes are morphed videos that are mostly created for a bad cause.

The deepfakes are created using different deeplearning-based tools like Faceswap, Faceit, etc.

FaceSwap deepfake

The main purpose of creating deepfakes

  • may be to spread fake news are create hoaxes around the audience
  • it also may be to pretend like someone else and do a financial fraud.
  • It may be used to slander the reputation of the famous personality like celebrity or politician by creating there unusual videos and publishing it over the internet.

Today we will be looking at the code I have developed to detect the deepfakes using CNN for feature extraction and LSTM temporal analysis. You can find the source code here.

We will be dividing the code into three parts.

  • In the first part, we take look at the Pre-processing stage of the model. In this stage, we will load the dataset, Split the video into frames, crop the face from each frame, and save the face-cropped video.
Preprocessing stage
  • After doing the preprocessing its time now to train the deep learning model. In this stage we will the preprocessed video and labels from a CSV file, Create a PyTorch model using transfer learning with RestNext50 and LSTM, Split the data into train and test data, Train the model, Test the model, save the model in the .pt file.
Training Workflow
  • Now our model is trained and ready now its time to do prediction in the prediction stage. We will load the saved PyTorch model, and predict the output based on trained weights.
Prediction Workflow

At the end of the Code walkthrough series, you will be able to train your own deepfake model and predict the result.

We have also developed the Django application to demonstrate the real-time usage of the model for prediction.

Hope you are excited about the code walkthrough series, as I am too. Stay tuned for further posts.

--

--

Abhijit Jadhav

Full Stack Java Developer and AI Enthusiast loves to build scalable application with latest tech stack