# How Does the num_jitters Parameter Affect Face Encoding Accuracy in face_recognition

> Discover how the num_jitters parameter in face_recognition boosts encoding accuracy. Learn how averaging multiple face samples enhances robustness against pose and lighting changes.

- Repository: [Adam Geitgey/face_recognition](https://github.com/ageitgey/face_recognition)
- Tags: deep-dive
- Published: 2026-03-06

---

**Increasing `num_jitters` improves face encoding robustness by averaging multiple jittered samples of the face image, trading linear increases in computation time for better accuracy under pose and lighting variations.**

The `num_jitters` parameter in the `ageitgey/face_recognition` library controls how many perturbed versions of a face image are sampled when generating the 128-dimensional encoding. Located in [`face_recognition/api.py`](https://github.com/ageitgey/face_recognition/blob/main/face_recognition/api.py), this argument directly influences the reliability of face matching by determining whether the descriptor is computed from a single alignment or averaged across multiple jittered variations.

## What Is num_jitters in face_recognition?

The `num_jitters` parameter appears in the `face_encodings()` function defined in [`face_recognition/api.py`](https://github.com/ageitgey/face_recognition/blob/main/face_recognition/api.py) (lines 203-214). When you call this function, it delegates the actual descriptor computation to dlib's `face_encoder.compute_face_descriptor` method, passing the `num_jitters` value directly to the underlying C++ implementation.

Internally, dlib uses this integer to determine how many times to randomly perturb the face image—applying small random translations, rotations, and scaling—before computing the descriptor for each variation and averaging the results.

## How num_jitters Affects Encoding Accuracy

### num_jitters = 1 (Default Behavior)

When `num_jitters=1` (the default), dlib computes the face descriptor using only the original face alignment without any perturbations. This provides the fastest encoding speed but makes the resulting vector more sensitive to minor variations in pose, lighting, and alignment quality.

### num_jitters > 1 (Jittered Sampling)

Setting `num_jitters` to values greater than 1 (commonly 2–10) enables jittered sampling. For each integer increment, dlib generates an additional randomly perturbed copy of the face image, computes its descriptor, and averages all generated descriptors into the final 128-dimensional vector.

This averaging process smooths out noise and makes the encoding more robust to:
- Slight head pose variations
- Lighting changes
- Minor alignment errors

### Performance Trade-offs

The relationship between `num_jitters` and computation time is linear. Each additional jitter requires computing a full face descriptor, so `num_jitters=10` takes approximately ten times longer than `num_jitters=1`.

Recommended values for different scenarios:
- **Real-time applications**: `num_jitters=1` (fastest)
- **Balanced accuracy/speed**: `num_jitters=2` or `3`
- **High-accuracy batch processing**: `num_jitters=5` to `10`

## Practical Code Examples

The following example demonstrates how different `num_jitters` values affect encoding generation in `face_recognition`:

```python
import face_recognition
import time

# Load image and detect face locations

image = face_recognition.load_image_file("person.jpg")
face_locations = face_recognition.face_locations(image)

# Default encoding (fastest, single sample)

start = time.time()
encoding_default = face_recognition.face_encodings(
    image, 
    face_locations, 
    num_jitters=1
)[0]
print(f"Default (1 jitter): {time.time() - start:.3f}s")

# Moderate jittering (better robustness)

start = time.time()
encoding_jitter2 = face_recognition.face_encodings(
    image, 
    face_locations, 
    num_jitters=2
)[0]
print(f"Jitter=2: {time.time() - start:.3f}s")

# High jittering (maximum robustness, slowest)

start = time.time()
encoding_jitter10 = face_recognition.face_encodings(
    image, 
    face_locations, 
    num_jitters=10
)[0]
print(f"Jitter=10: {time.time() - start:.3f}s")

# Compare against a reference image

reference = face_recognition.load_image_file("reference.jpg")
reference_enc = face_recognition.face_encodings(reference)[0]

results = face_recognition.compare_faces(
    [reference_enc], 
    [encoding_default, encoding_jitter2, encoding_jitter10]
)
print(f"Match with default: {results[0]}")
print(f"Match with jitter=2: {results[1]}")
print(f"Match with jitter=10: {results[2]}")

```

Typical output shows that higher `num_jitters` values reduce false negatives on challenging images while increasing computation time proportionally.

## Summary

- The `num_jitters` parameter in [`face_recognition/api.py`](https://github.com/ageitgey/face_recognition/blob/main/face_recognition/api.py) controls how many perturbed face samples dlib averages when computing the 128-dimensional face descriptor.
- **Default value (1)** provides the fastest encoding but is most sensitive to pose and lighting variations.
- **Values > 1** improve robustness by averaging multiple jittered samples, making encodings more stable across minor alignment errors.
- **Performance scales linearly**: each increment of `num_jitters` multiplies encoding time by approximately the same factor.
- For most applications, **2–5 jitters** offers the optimal balance between accuracy and speed.

## Frequently Asked Questions

### What is the default value of num_jitters?

The default value is **1**, meaning the face encoding is computed from a single face alignment without any jittering. This provides maximum speed but minimal robustness to variations in pose, lighting, or alignment.

### How does num_jitters impact processing speed?

Processing time increases **linearly** with the `num_jitters` value. Setting `num_jitters=10` takes approximately ten times longer to compute than `num_jitters=1` because each jitter requires computing a full face descriptor from a randomly perturbed image.

### What num_jitters value should I use for production?

For **real-time applications** such as video streams or live cameras, use `num_jitters=1`. For **batch processing** or **high-accuracy requirements** such as security systems or photo organization, use `num_jitters=2` to `5`. Values above 10 rarely provide meaningful accuracy gains relative to the computational cost.

### Does num_jitters affect face detection or only encoding?

The `num_jitters` parameter affects **only the encoding phase**, not face detection. Face location detection occurs before `face_encodings` is called via `face_locations` or `face_landmarks`. The `num_jitters` parameter is applied only when computing the 128-dimensional descriptor from the already-detected face region.