For face detection, the key metrics are Precision and Recall. Precision tells us how many detected faces are actually faces, so it helps avoid false alarms. Recall tells us how many real faces the model finds, so it helps avoid missing faces. Both matter because missing a face or wrongly detecting a face can cause problems in real life, like security or photo tagging.
Face detection with deep learning in Computer Vision - Model Metrics & Evaluation
| Predicted Face | Predicted No Face |
|----------------|-------------------|
| True Positive | False Positive |
| False Negative | True Negative |
Example:
TP = 90 (faces correctly detected)
FP = 10 (wrongly detected faces)
FN = 15 (faces missed)
TN = 885 (correctly ignored non-faces)
Total samples = 90 + 10 + 15 + 885 = 1000
If the model tries to find every face (high recall), it might detect some things that are not faces (lower precision). For example, in a security camera, missing a face (low recall) is bad because you want to catch everyone. But if it detects too many false faces (low precision), it wastes time checking wrong alerts.
On the other hand, if the model is very strict and only detects faces it is sure about (high precision), it might miss some faces (low recall). This might be okay for photo apps where false faces annoy users, but not for safety systems.
Good: Precision and Recall both above 90%. This means most detected faces are real, and most real faces are found.
Bad: Precision below 70% means many false alarms. Recall below 70% means many faces missed. For example, 50% recall means half the faces are not detected, which is usually unacceptable.
- Accuracy paradox: If most images have no faces, a model that always says "no face" can have high accuracy but is useless.
- Data leakage: Testing on images very similar to training can give too optimistic metrics.
- Overfitting: Very high training metrics but poor test metrics mean the model learned noise, not real face patterns.
Your face detection model has 98% accuracy but only 12% recall on faces. Is it good for production? Why or why not?
Answer: No, it is not good. The high accuracy is misleading because most images might not have faces. The very low recall means the model misses almost all faces, which defeats the purpose of face detection.
Practice
Solution
Step 1: Understand face detection
Face detection means finding where faces are in an image, not who they belong to.Step 2: Differentiate from face recognition
Face recognition identifies who the face belongs to, which is different from detection.Final Answer:
To find and locate faces in images or videos -> Option AQuick Check:
Face detection = Find faces [OK]
- Confusing detection with recognition
- Thinking detection creates new images
- Assuming detection removes faces
Solution
Step 1: Recall OpenCV syntax for Haar Cascade
OpenCV uses cv2.CascadeClassifier to load Haar Cascade XML files.Step 2: Check each option's method name
Only cv2.CascadeClassifier is correct; others are invalid or do not exist.Final Answer:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') -> Option DQuick Check:
Use CascadeClassifier to load Haar cascades [OK]
- Using wrong method names like loadCascade or Cascade
- Confusing face detector with face recognizer
- Missing the .xml file extension
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread('group_photo.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
print(len(faces))Solution
Step 1: Understand detectMultiScale output
detectMultiScale returns a list of rectangles for each detected face.Step 2: Count detected faces in the image
Since the image has two faces, len(faces) will be 2.Final Answer:
2 -> Option AQuick Check:
Faces detected = 2 [OK]
- Assuming detectMultiScale returns a boolean
- Confusing number of faces with confidence scores
- Forgetting to convert image to grayscale
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread('photo.jpg')
faces = face_cascade.detectMultiScale(img)
print(len(faces))Solution
Step 1: Check input type for detectMultiScale
detectMultiScale expects a grayscale image, not a color image.Step 2: Identify missing grayscale conversion
The code misses converting img to grayscale before detection.Final Answer:
The image should be converted to grayscale before detection -> Option CQuick Check:
detectMultiScale needs grayscale input [OK]
- Passing color images directly to detectMultiScale
- Assuming detectMultiScale works on any image format
- Confusing print(len(faces)) with print(faces)
Solution
Step 1: Understand scaleFactor effect
Lower scaleFactor means the detector checks more scales, helping find smaller faces.Step 2: Compare with other options
Increasing minNeighbors reduces false positives but may miss faces; color images and skipping preprocessing reduce accuracy.Final Answer:
Decrease scaleFactor to detect smaller faces more precisely -> Option BQuick Check:
Lower scaleFactor = better small face detection [OK]
- Increasing minNeighbors too much misses faces
- Using color images instead of grayscale
- Skipping image preprocessing steps
Ready to prove it?
Pass the test and this pattern moves unknown
