Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Deepfake Detection Vision Transformer #2: Face Extraction & Alignment with YuNet Detector (OpenCV)”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Here is the final result, a photo containing four tilted faces in different directions. The detector unit finds everything, complete with eye, nose, and mouth points. Then each face is rotated and cropped to be upright and neat. This is the first stage of every deepfake detection system. Let's get started. Hello, welcome to episode two of the deepfake detection series based on Vision Transformer. In real cases, photos or videos contain people, backgrounds, and other objects. Deepfake detectors work on faces, so the first step is to find faces. Then align them so that the position of the eyes and mouth is consistent. In videos, this step is performed for each frame. We use UNED, a lightweight built-in face detector from OpenCV. The UNED model is already in the model folder, its size is only 230 kilobytes.
Create a file named face_detection.py The detection function creates a face detector with the appropriate size and confidence threshold of 0.6. Each detected face is returned as 15 numbers. 4 numbers for the face box, 10 numbers for 5 landmark points, which are 2 eyes, nose, and 2 corners of the mouth, along with the confidence score. Next, the alignment function.
From the 2 eye points, we calculate the angle of tilt using the arctangent N, and the inter-eye distance to determine the scale. The affine rotation matrix rotates the face so that both eyes are horizontally aligned, enlarges or reduces it so that the eye distance is always the same, and then places the center of the eye at a fixed position. The result is that each face has a uniform position.
Now create a file named face_detection_test.py. To test it, we create a group photo, 4 faces from the dataset are randomly rotated up to 25 degrees, and placed in different positions on the gray canvas. Then we detect, green bounding boxes and red landmark points, and display the aligned face results for each face.
Run. The four faces are detected with scores around 0.93 to 0.94. In the top image, you can see the boxes and five landmark points on each face, and the bottom row shows the four faces that are upright and uniform after alignment. At the end, we test on 240 dataset samples, all of them are detected.
One important note for deepfake detection. Alignment rotates and resizes the image, and this process smooths out the high-frequency traces we saw in the previous episode. Our dataset is already aligned faces with original resolution, so for training we use it directly, while our detector unit is used to find faces in free photos, including in the web application at the end of the series.
Done. We have already used the detector unit to find faces and five landmarks, aligning faces based on eye position, and tested on photos containing several tilted faces. In the next episode, we enter the core of the series, understanding Vision Transformer, Starting from pack embedding, position tokens, up to self-attention. Currently working on a thesis, dissertation, or AI research in the field of deepfake detection and image forensics? Cerdas Inovasi Digital helps with deep learning implementation, from face detection, Vision Transformer, comparison with CNN, compression resilience testing, up to attention maps and web application, as well as opening deep learning courses with Pythor. Want to master the entire series? From face datasets up to deepfake checker applications? All 6 episodes, complete with step-by-step PDF guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or one-time payment of Rp999.000 for lifetime access. Want just one class? Buy single classes with lifetime access. Subscribe now on the premium page cerdasinovasidigital.com Contact our WhatsApp, or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode. Thank you for watching,
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →