Skip to content

Usage

All examples assume the project environment is synced with uv sync --dev. Use -v/--verbose for debug logging or -q/--quiet to limit logging to errors. Log output goes to stderr so it does not mix with command results.

Build a face index

uv run doppelsort scan ./targets --db-path ./faces.db --overwrite
uv run doppelsort scan ./targets_a ./targets_b --db-path ./faces.db

The scan command indexes every detected face in each supported image (.png, .jpg, .jpeg, .bmp, or .webp). It searches each target directory recursively while skipping hidden files and directories and symlinked directories. Perceptual hashes honor EXIF orientation, and zero-byte files are reported as failures without invoking DeepFace.

Each image gets a SHA-256 content_hash and, when near-duplicate checking is enabled, a lightweight perceptual hash. Files with identical content hashes are skipped before DeepFace extraction, including copies already present in the index when appending. Set --near-duplicate-threshold to a small Hamming distance (for example 6) to skip visually similar images as well.

Hashing and file metadata are precomputed with --workers threads while DeepFace inference remains serial. DeepFace reuses its loaded model within the scan process.

Scan output

After each run the scan prints the number of indexed faces and, when applicable, counts of skipped duplicate and near-duplicate images, images with no detected face, and images that failed during extraction. Per-image extraction failures are logged at WARNING.

--json replaces the human summary with one JSON object containing the same counts plus an errors array of per-file failure messages.

Append or overwrite

Scans append by default and preserve existing face and image rows. Pass --overwrite explicitly to clear the index before scanning. When scanning multiple directories, each directory is committed after it completes, so earlier directories remain saved if a later one fails.

The index stores compact float32 embeddings as SQLite BLOB data, with image and face metadata.

Compare two portraits

uv run doppelsort compare ./source.jpg ./target.jpg
uv run doppelsort compare ./source.jpg ./target.jpg --by-distance
uv run doppelsort compare ./source.jpg ./target.jpg --json

Text output matches the match style:

1. /path/to/target.jpg | distance=12.34% | similarity=87.66% | match=yes

Both commands L2-normalize face embeddings and compare them with cosine similarity. Displayed values are similarity = cosine_similarity and distance = 1 - similarity, scaled to 0-100 for text output. This shared scoring method keeps compare and SQLite-backed match results consistent.

  • similarity: higher is better.
  • distance: lower is better.

For images containing more than one detected face, compare, match, and the indexing path use the largest detected face (by bounding-box area) as the subject. Scan indexes every detected face so a gallery can contain multiple people.

The match field is a decision based on a cosine-distance threshold. The default threshold is chosen per model from DeepFace's published values (for example 0.68 for ArcFace); override it with --threshold. These are normalized scores and threshold decisions, not calibrated probabilities or identity-confidence estimates.

--by-similarity is the default sort order; --by-distance sorts from lowest distance upward. --json emits an array of result objects with is_match as a boolean.

Match against an index

uv run doppelsort match ./source.jpg --db-path ./faces.db --top-n 10
uv run doppelsort match ./source.jpg --db-path ./faces.db --by-distance --json

This extracts the source image's face embedding, loads indexed face embeddings from SQLite, and returns at most --top-n candidates (default: 5). The required --db-path must point to an existing index created with scan.

Text results contain the image path, distance, similarity, and match decision for each indexed face. JSON results also include the face record's id, bbox, and is_match boolean. Use --threshold to override the per-model cosine distance threshold.

Matching loads all embeddings into one NumPy matrix and scores them with a single vectorized operation before selecting the top rows. match refuses an index built with a different model or embedding dimension.

Inspect and maintain the index

uv run doppelsort db info ./faces.db
uv run doppelsort db optimize ./faces.db

db info reports summary statistics:

  • rows: total face entries.
  • unique_images: distinct image paths with face rows.
  • unique_embeddings: distinct embedding vectors.
  • duplicate_groups: content-hash-and-embedding groups containing repeated face rows (falls back to image path for legacy indexes).
  • duplicate_rows: excess rows across those groups, i.e. the rows db optimize would remove.
  • model_name and embedding_dim: the model recorded with the index.
  • unique_content_hashes and duplicate_content_hashes: content-hash counts.
  • first_seen and last_seen: earliest and latest insertion timestamps.

duplicate_groups counts groups while duplicate_rows counts excess rows; both use the same grouping key as db optimize. One image can produce multiple face embeddings, so unique_images and unique_embeddings can differ.

db optimize removes duplicate face rows and keeps the lowest-ID row for each embedding grouped by content_hash when available, or by image_path for older databases. Rows with a NULL content hash fall back to their image_path, so unrelated legacy rows are not merged. It reports both the number of duplicate groups and the number of removed rows.

Notes

  • Scan, compare, and match print a CPU warning when TensorFlow reports no GPU.
  • The database uses SQLite WAL mode and adds missing image/hash metadata columns when opening an older index for scanning.