--- pretty_name: Thatcher Effect Face Quartets FFHQ and SFHQ license: other task_categories: - image-feature-extraction tags: - computer-vision - thatcher-effect - face-perception - vision-transformer - ffhq - sfhq configs: - config_name: ffhq_passportify_gazefix data_files: - split: train path: data/ffhq/passportify_gazefix/*.parquet - config_name: ffhq_passportify data_files: - split: train path: data/ffhq/passportify/*.parquet - config_name: ffhq_gazefix data_files: - split: train path: data/ffhq/gazefix/*.parquet - config_name: ffhq_original data_files: - split: train path: data/ffhq/original/*.parquet - config_name: sfhq_passportify_gazefix data_files: - split: train path: data/sfhq/passportify_gazefix/*.parquet - config_name: sfhq_passportify data_files: - split: train path: data/sfhq/passportify/*.parquet - config_name: sfhq_gazefix data_files: - split: train path: data/sfhq/gazefix/*.parquet - config_name: sfhq_original data_files: - split: train path: data/sfhq/original/*.parquet --- # Thatcher Effect Faces: FFHQ + SFHQ A [Thatcher Effect](https://en.wikipedia.org/wiki/Thatcher_effect) dataset for computer vision models. ![Thatcher Effect on FFHQ](demo_images/ffhq_thatcher_ex.png) ## Format and variants Contains matched `upright Normal/Thatcher` + `upside-down Normal/Thatcher` quartets for researching orientation-dependent face representations.\ Four image roots are provided: original, gaze-corrected, frontal-view corrected (`passportify`), and frontal-view plus gaze-corrected.\ One row per identity/condition with four embedded, lossless PNG images: `normal_u`, `normal_i`, `thatcher_u`, `thatcher_i`. - **Roots:** `original`, `gazefix`, `passportify`, `passportify_gazefix`. - **Face conditions:** `both` (eyes and mouth), `eo` (eyes only), `mo` (mouth only), `ll` (left-half mirror), `rr` (right-half mirror). - **Mirror conditions:** `ll` and `rr` occur only in gaze-corrected roots. ![Additional Thatcher variants](demo_images/additional-variants.png) ----- ## Three-model Thatcher-effect quickstart The example compares OpenAI CLIP ViT-L/14, SigLIP-2-Large and DINOv2-Large.\ Samples only the Full Thatcher `both` condition.\ For per-feature-condition results, see the included `getting_started.py`.
👉 Click here to expand code for CLIP, SigLIP-2, DINOv2! ```python # CLIP vs SigLIP 2 Large vs DINOv2 Large on FFHQ and SFHQ. # Install: pip install -U torch transformers datasets pillow from itertools import islice from io import BytesIO from math import acos, pi from pathlib import Path from statistics import fmean, stdev import torch import torch.nn.functional as F from datasets import Image as HFImage, load_dataset from PIL import Image from transformers import AutoImageProcessor, AutoProcessor, CLIPModel, Dinov2Model, SiglipVisionModel REPO = "zer0int/Thatcher_Effect_Faces" # HF ID by default; also accepts a local export folder. N = 49 # 49 = Full-Thatcher ('both') quartets from each dataset's original root. DEVICE = "cuda" if torch.cuda.is_available() else "cpu" MODELS = [ ("CLIP ViT-L/14", "openai/clip-vit-large-patch14", "clip"), ("SigLIP 2 Large", "google/siglip2-large-patch16-256", "siglip2"), ("DINOv2 Large", "facebook/dinov2-large", "dino"), ] class SiglipImageOnly(SiglipVisionModel): # ignore unused text tower and contrastive logits that are unexpected # when loading the vision tower from a joint SigLIP checkpoint. _keys_to_ignore_on_load_unexpected = set( SiglipVisionModel._keys_to_ignore_on_load_unexpected or () ) | {r"^text_model\.", r"^logit_scale$", r"^logit_bias$"} def decode_rgb(image_value): if isinstance(image_value, Image.Image): return image_value.convert("RGB") if isinstance(image_value, dict): if image_value.get("bytes") is not None: with Image.open(BytesIO(image_value["bytes"])) as image: return image.convert("RGB") if image_value.get("path") and Path(image_value["path"]).is_file(): with Image.open(image_value["path"]) as image: return image.convert("RGB") raise TypeError(f"Unsupported image format: {type(image_value).__name__}") def summarize(upright, inverted): """Summarize paired faces, keeping model distances distinct from human accuracy.""" excesses = [i - u for u, i in zip(upright, inverted)] n = len(excesses) if not n: raise ValueError("Cannot summarize an empty set of Thatcher quartets") # angular distance / 180 degrees as a genuine bounded percentage. # report the *paired* upright-minus-inverted angular distance in pp. angular_excess_pp = fmean( 100.0 / pi * (acos(max(-1., min(1., u))) - acos(max(-1., min(1., i)))) for u, i in zip(upright, inverted) ) # % of face quartets where inversion makes normal and Thatcher MORE similar. favorable_pct = 100.0 * sum(e > 0 for e in excesses) / n # face-to-face consistency spread = stdev(excesses) if n > 1 else 0.0 d_faces = fmean(excesses) / spread if spread > 0 else float("nan") return fmean(upright), fmean(inverted), fmean(excesses), angular_excess_pp, favorable_pct, d_faces, n rows_by_source = {} for source in ("ffhq", "sfhq"): if Path(REPO).is_dir(): shards = sorted((Path(REPO) / "data" / source / "original").glob("*.parquet")) if not shards: raise FileNotFoundError(f"No {source} Parquet files in {REPO}") ds = load_dataset("parquet", data_files={"train": [str(p) for p in shards]}, split="train", streaming=False) else: ds = load_dataset(REPO, f"{source}_original", split="train", streaming=False) # .decode(False) is for IterableDataset, not a cached Dataset. # Disable automatic image decoding using the Dataset.cast_column API. for column in ("normal_u", "normal_i", "thatcher_u", "thatcher_i"): if isinstance(ds.features[column], HFImage): ds = ds.cast_column(column, HFImage(decode=False)) rows_by_source[source] = list(islice((r for r in ds if r["face_variant"] == "both"), N)) if not rows_by_source[source]: raise RuntimeError(f"Empty dataset config: {source}_original") scores = {source: {} for source in rows_by_source} for label, checkpoint, family in MODELS: # SigLIP's vision-only class bypasses the upstream text-config processor_cls = AutoProcessor if family == "clip" else AutoImageProcessor model_cls = {"clip": CLIPModel, "siglip2": SiglipImageOnly, "dino": Dinov2Model}[family] processor = processor_cls.from_pretrained(checkpoint) model = model_cls.from_pretrained(checkpoint).to(DEVICE).eval().float() for source, rows in rows_by_source.items(): upright, inverted = [], [] for row in rows: images = [decode_rgb(row[k]) for k in ("normal_u", "normal_i", "thatcher_u", "thatcher_i")] batch = {k: v.to(DEVICE) for k, v in processor(images=images, return_tensors="pt").items()} with torch.inference_mode(): if family == "dino": z = model(**batch).last_hidden_state[:, 0, :] elif family == "siglip2": z = model(**batch).pooler_output else: z = model.get_image_features(**batch) if not isinstance(z, torch.Tensor): z = (getattr(z, "image_embeds", None) if getattr(z, "image_embeds", None) is not None else z.pooler_output) z = F.normalize(z.float(), dim=-1) upright.append((z[0] * z[2]).sum().item()) inverted.append((z[1] * z[3]).sum().item()) scores[source][label] = summarize(upright, inverted) del model if DEVICE == "cuda": torch.cuda.empty_cache() for source in ("ffhq", "sfhq"): print(f"\n{source.upper()} — original root, full Thatcher, {len(rows_by_source[source])} quartets") print(f"{'Model':20} {'N':>3} {'upright':>9} {'inverted':>9} {'cos excess':>10} {'ang pp':>8} {'% faces':>8} {'d_faces':>8}") for label, _, _ in MODELS: u, i, excess, ang_pp, favorable, d_faces, n = scores[source][label] print(f"{label:20} {n:3d} {u:9.4f} {i:9.4f} {excess:+10.4f} {ang_pp:+8.2f} {favorable:8.1f} {d_faces:8.2f}") ```
----- ## Thatcher Effect — Human vs. AI > **Standardized Thatcher effects** > > | Observer / Model | Dataset | N | Standardized effect | > |---|---|---:|---:| > | **Human participants** † | Behavioral study | 36 | **2.98** | > | **CLIP ViT-L/14** | FFHQ | 49 | **1.94** | > | **CLIP ViT-L/14** | SFHQ | 49 | **2.30** | > | SigLIP 2 Large | FFHQ | 49 | 1.22 | > | SigLIP 2 Large | SFHQ | 49 | 1.43 | > | DINOv2 Large | FFHQ | 49 | 0.84 | > | DINOv2 Large | SFHQ | 49 | 1.13 | > > Larger values indicate a stronger mean effect relative to variability > within the respective sample. > > † de Haas & Schwarzkopf (2018), *Journal of Vision*: > [Feature–location effects in the Thatcher illusion](https://doi.org/10.1167/18.4.16) ## Detailed Results ### FFHQ — Full Thatcher, 49 Quartets | Model | N | Upright cos | Inverted cos | Cos excess | Ang pp | % faces | d_faces | |---|---:|---:|---:|---:|---:|---:|---:| | CLIP ViT-L/14 | 49 | **0.8643** | 0.9807 | **+0.1164** | **+10.40** | 100.0 | **1.94** | | SigLIP 2 Large | 49 | 0.9609 | 0.9949 | +0.0340 | +5.26 | 98.0 | 1.22 | | DINOv2 Large | 49 | 0.9563 | 0.9845 | +0.0281 | +3.41 | 85.7 | 0.84 | ### SFHQ — Full Thatcher, 49 Quartets | Model | N | Upright cos | Inverted cos | Cos excess | Ang pp | % faces | d_faces | |---|---:|---:|---:|---:|---:|---:|---:| | CLIP ViT-L/14 | 49 | **0.8402** | 0.9712 | **+0.1311** | **+10.52** | 100.0 | **2.30** | | SigLIP 2 Large | 49 | 0.9480 | 0.9946 | +0.0466 | +6.56 | 100.0 | 1.43 | | DINOv2 Large | 49 | 0.9391 | 0.9872 | +0.0481 | +5.41 | 91.8 | 1.13 | ### Human Visual Discrimination **Measurement:** 200-ms masked match-to-sample visual discrimination. | Model | N | Upright accuracy | Inverted accuracy | Discrimination excess (pp) | d_z | |---|---:|---:|---:|---:|---:| | Human | 36 | 96.65% | 64.62% | **+32.03** | **2.98** | ### Measurement Notes - **Cosine similarity:** Agreement between normal and Thatcherized image embeddings. - **Cos excess:** Inverted cosine minus upright cosine. - **Ang pp:** Mean extra angular separation, as percentage points of the 180° range. - **% faces:** Fraction of identities with positive cosine excess, expressed as a percentage. - **Human excess:** Upright minus inverted discrimination accuracy, in percentage points. **General standardized paired effect:** `d = mean(Δ) / SD(Δ)`, where `Δ` is the orientation-dependent Thatcher difference for each observation (positive for the expected effect). For humans, observations are participants (`d_z`); for models, they are face identities (`d_faces`). Different models' cosine distributions are **not calibrated across models**.\ For illustrative purposes; human accuracy and model cosine differences measure distinct quantities and are not directly comparable. ---------- ## Dataset details | Source | Root | Feature condition | Quartets | Images | |---|---|---|---:|---:| | ffhq | gazefix | both | 49 | 196 | | ffhq | gazefix | eo | 49 | 196 | | ffhq | gazefix | ll | 49 | 196 | | ffhq | gazefix | mo | 49 | 196 | | ffhq | gazefix | rr | 49 | 196 | | ffhq | original | both | 49 | 196 | | ffhq | original | eo | 49 | 196 | | ffhq | original | mo | 49 | 196 | | ffhq | passportify | both | 49 | 196 | | ffhq | passportify | eo | 49 | 196 | | ffhq | passportify | mo | 49 | 196 | | ffhq | passportify_gazefix | both | 49 | 196 | | ffhq | passportify_gazefix | eo | 49 | 196 | | ffhq | passportify_gazefix | ll | 49 | 196 | | ffhq | passportify_gazefix | mo | 49 | 196 | | ffhq | passportify_gazefix | rr | 49 | 196 | | sfhq | gazefix | both | 49 | 196 | | sfhq | gazefix | eo | 49 | 196 | | sfhq | gazefix | ll | 49 | 196 | | sfhq | gazefix | mo | 49 | 196 | | sfhq | gazefix | rr | 49 | 196 | | sfhq | original | both | 49 | 196 | | sfhq | original | eo | 49 | 196 | | sfhq | original | mo | 49 | 196 | | sfhq | passportify | both | 49 | 196 | | sfhq | passportify | eo | 49 | 196 | | sfhq | passportify | mo | 49 | 196 | | sfhq | passportify_gazefix | both | 49 | 196 | | sfhq | passportify_gazefix | eo | 49 | 196 | | sfhq | passportify_gazefix | ll | 49 | 196 | | sfhq | passportify_gazefix | mo | 49 | 196 | | sfhq | passportify_gazefix | rr | 49 | 196 | ## FFHQ: provenance and full original NVIDIA metadata **FFHQ (Flickr-Faces-HQ) was assembled by NVIDIA Corporation**, associated with Tero Karras, Samuli Laine and Timo Aila, *A Style-Based Generator Architecture for Generative Adversarial Networks*, CVPR 2019. Official NVIDIA FFHQ project and metadata: https://github.com/NVlabs/ffhq-dataset. NVIDIA's FFHQ dataset materials are under **CC BY-NC-SA 4.0**. Each underlying Flickr image has its **own individual license and photographer**, as recorded in NVIDIA's original `ffhq-dataset-v2.json` (see github). ## SFHQ: source **Synthetic Faces High Quality (SFHQ)**, David Beniaguev (2022). Official source: https://github.com/SelfishGene/SFHQ-dataset. Dataset DOI: https://doi.org/10.34740/kaggle/dsv/4737549. ## Original Thatcher illusion Peter Gage Thompson, *Margaret Thatcher: A New Illusion*, *Perception* 9(4), 483–484 (1980), https://doi.org/10.1068/p090483.