File size: 14,022 Bytes
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf9b81
 
 
 
a59ff87
 
 
 
 
 
 
 
 
eaf9b81
 
a59ff87
 
eaf9b81
 
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c881b4
a59ff87
7c881b4
a59ff87
 
 
 
 
 
 
 
 
 
 
7c881b4
 
 
 
 
 
 
 
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c881b4
 
a59ff87
7c881b4
 
 
 
 
 
 
a59ff87
 
 
 
 
7c881b4
 
 
 
 
a59ff87
 
 
 
 
 
 
 
7c881b4
 
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf9b81
 
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330828e
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf9b81
a59ff87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
---

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`.

<details>
<summary><strong>👉 Click here to expand code for CLIP, SigLIP-2, DINOv2!</strong></summary>

```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}")

```

</details>


-----

## 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.