For face detection using deep neural networks, the key metrics are Precision and Recall. Precision tells us how many detected faces are actually faces, so it measures false alarms. Recall tells us how many real faces the model finds, so it measures missed faces. Both matter because we want to find as many faces as possible (high recall) without wrongly marking non-faces as faces (high precision). The F1 score balances these two. Also, the Average Precision (AP) over different confidence thresholds is often used to summarize performance.
DNN-based face detection in Computer Vision - Model Metrics & Evaluation
| Predicted Face | Predicted No Face |
|---------------|-------------------|
| True Face (TP) 90 10 (FN) |
| False Face (FP) 15 885 (TN) |
Total samples = 1000
Precision = TP / (TP + FP) = 90 / (90 + 15) = 0.857
Recall = TP / (TP + FN) = 90 / (90 + 10) = 0.9
F1 Score = 2 * (0.857 * 0.9) / (0.857 + 0.9) ≈ 0.878
If the model is tuned to be very strict, it will only detect faces when very sure. This means high precision (few false alarms) but low recall (misses many faces). This is good if false alarms are costly, like in security checks.
If the model is tuned to detect as many faces as possible, it will catch almost all faces (high recall) but also mark some non-faces as faces (low precision). This is useful in photo apps where missing a face is worse than a few false detections.
Choosing the right balance depends on the application needs.
- Good: Precision and Recall both above 0.85, F1 score near 0.9 or higher. This means most faces are found and few false alarms.
- Bad: Precision or Recall below 0.5 means many false alarms or many missed faces. For example, Precision 0.4 means more than half detected faces are wrong.
- Very high accuracy alone can be misleading if the dataset has many non-face images (class imbalance).
- Accuracy paradox: If most images have no faces, a model that always predicts no face can have high accuracy but is useless.
- Data leakage: Testing on images very similar to training images inflates metrics falsely.
- Overfitting: Very high training metrics but low test metrics means the model memorizes training faces but fails on new ones.
- Ignoring IoU thresholds: Face detection usually requires bounding boxes to overlap enough with ground truth. Metrics must consider this overlap.
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 may not have faces. The very low recall means the model misses 88% of faces, which defeats the purpose of face detection.
Practice
Solution
Step 1: Understand the goal of face detection
Face detection means finding where faces are in pictures or videos.Step 2: Recognize what DNN-based models do
DNN models learn patterns to automatically locate faces without manual rules.Final Answer:
To find faces in images automatically -> Option BQuick Check:
Face detection = find faces [OK]
- Confusing detection with image editing
- Thinking it changes image colors
- Mixing detection with compression
Solution
Step 1: Identify the function for loading DNN models
OpenCV's DNN module uses cv2.dnn.readNet() to load models from files.Step 2: Differentiate from other functions
cv2.imread() loads images, cv2.resize() changes size, cv2.cvtColor() changes color space.Final Answer:
cv2.dnn.readNet() -> Option AQuick Check:
Load DNN model = cv2.dnn.readNet() [OK]
- Using cv2.imread() to load models
- Confusing image functions with model loading
- Trying to resize models with cv2.resize()
detections?
net = cv2.dnn.readNet('model.caffemodel', 'deploy.prototxt')
blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300), (104, 177, 123))
net.setInput(blob)
detections = net.forward()Solution
Step 1: Understand net.forward() output
net.forward() returns a NumPy array containing detection results with scores and box info.Step 2: Differentiate output types
It is not a list, integer, or string but a multi-dimensional array with detection details.Final Answer:
A NumPy array with detection data -> Option DQuick Check:
net.forward() output = NumPy array [OK]
- Thinking output is a list or count
- Expecting a string description
- Confusing output with input image
blob = cv2.dnn.blobFromImage(image, 1.0, (224, 224), (104, 177, 123)) net.setInput(blob) detections = net.forward()What should you fix?
Solution
Step 1: Check model input size requirements
Many DNN face detectors expect input size (300, 300). Using (224, 224) causes mismatch and no detection.Step 2: Correct the input size in blobFromImage
Changing to (300, 300) matches model and enables detection.Final Answer:
Change input size to (300, 300) to match model requirements -> Option AQuick Check:
Input size must match model = (300, 300) [OK]
- Using wrong input size for the model
- Calling net.forward() before setInput()
- Removing mean subtraction incorrectly
Solution
Step 1: Understand multi-scale detection challenge
Faces appear at different sizes; detecting all requires checking multiple scales.Step 2: Use image pyramid technique
Image pyramid resizes image multiple times to detect faces at various sizes, improving accuracy.Final Answer:
Use image pyramid to detect faces at multiple scales -> Option CQuick Check:
Multi-scale detection = image pyramid [OK]
- Thinking higher learning rate fixes scale issues
- Reducing image size loses small faces
- Skipping mean subtraction harms accuracy
Ready to prove it?
Pass the test and this pattern moves unknown
