lookcheck
Is your image model looking at the right thing?
In the early 1900s a horse called Clever Hans seemed to do arithmetic. He was really reading tiny cues in his trainer's face. Image models do the same thing. A pneumonia detector learned to recognise which hospital an X-ray came from, and leaned on that instead of the lungs (Zech et al., 2018). A skin-cancer classifier scored ink markings that doctors draw around suspicious moles (Winkler et al., 2019). An image classifier recognised "horse" from a photographer's copyright watermark (Lapuschkin et al., 2019). Accuracy was high every time, and for the wrong reason.
lookcheck finds these shortcuts in any image classifier, in one line:
import lookcheck as lc
report = lc.scan(model, images, labels, class_names=classes, masks=masks)
print(report)
report.plot()
It only needs a function that turns images into class scores, so it works with PyTorch, Keras, JAX, ONNX or a model behind an API, with no gradients and no access to the model's insides.
Install
pip install lookcheck # numpy, pandas, scipy, pillow
pip install "lookcheck[plot]" # adds matplotlib for report.plot()
What it found in three real networks
examples/watermark_cnn.py trains three small CNNs on images of circles,
squares and triangles. One was trained on honest data. In the second, 90% of the training squares carry a
small red mark in the corner, like a watermark. In the third, most training circles sit on a blue background.
The networks are never told about these shortcuts. This is what lookcheck says about the watermark network:
lookcheck: 600 images, 3 classes (circle, square, triangle), model accuracy 89.3%
(44,400 images passed through the model)
1. Fixed spots (8x8 grid, each cell covered in every image):
[SHORTCUT] square: covering the bottom-right corner cuts its confidence by 27% on average (mostly off the object), +28% more than for other classes (adjusted p=0.000999; 3 cells)
2. Object vs background:
accuracy: original 89.3%, object only 63.7%, background only 59.2%, random hole (control) 84.7%
[SHORTCUT] square: with the object erased, its background alone is still called square 88% of the time (82% to 91%), vs at most 8% for any other class's background
[SHORTCUT] square: other objects pasted onto a square background are called square 45% of the time (vs 0% with no background)
...
Verdict: the model is cheating: 'square' depends on the bottom-right corner; background gives away 'square'. Look at report.plot() before trusting it.
The heat maps show how much confidence each class loses when each grid cell is covered. Only "square" reacts, and only to the corner. The bottom row shows the square images most affected: the red mark sits exactly there.
| Network | What lookcheck reported |
|---|---|
| Honest (accuracy 93.7%) | no fixed spot, no background shortcut |
| Watermark (89.3%) | "square" depends on the bottom-right corner; its background gives the label away |
| Blue background (70.0%) | "circle" backgrounds are called circle 86% of the time with the circle erased (at most 12% for other backgrounds); other objects pasted on a circle background become "circle" 74% of the time (vs 6%) |
The background network also shows weaker pulls toward square and triangle (24% vs 11%, 49% vs 30%). These are the other side of the same shortcut: a background that is not blue tells it "not a circle".
The three tests
1. Fixed spots (works without masks). Every image is covered one grid cell at a time, at the same place. An object moves around from photo to photo, so covering one fixed cell hurts some images and not others. A watermark, a hospital tag, a ruler or a timestamp sits in the same place every time. A cell is flagged when:
- covering it costs one class clearly more confidence than the other classes (so "objects tend to be in the middle" cancels out), tested with a label-permutation test and the max-t correction over every class and cell, which keeps the chance of any false alarm at 1%;
- it is consistent: among the three cells that matter most in at least half of that class's images;
- with masks, it lies mostly off the object.
2. Object vs background (needs masks or boxes). The object is erased, the background is erased, and the object is pasted onto backgrounds from other classes. Two controls keep this honest:
- every class's erased background is compared with the background of each other class separately (an intersection-union test), so a shortcut in one class cannot make another class look guilty;
- a hole of the same shape cut in a random place shows how much accuracy drops from the hole alone;
- pasted objects are compared with the same objects on no background (exact paired test).
3. Texture and colour (profile only). The image is cut into tiles that are shuffled, and colour is removed. High accuracy on shuffled tiles means local texture or colour is enough. A drop in grayscale can also just mean the model never saw gray images, so this test describes the model rather than accusing it.
Every accuracy has a 95% Wilson interval, and every flag needs both statistical significance and a meaningful
size (at least 5 points of confidence or 10 points of accuracy). All thresholds are arguments of scan().
No false alarms on honest models. On 30 synthetic datasets and an honest model that never uses spots or
backgrounds, lookcheck raised no fixed-spot alarm and no background alarm
(benchmarks/false_alarms.py). The honest CNN above was not flagged either.
Use it with your model
import lookcheck as lc
# PyTorch / torchvision / timm: images go in as (N, H, W, 3) floats in [0, 1]
predict = lc.from_torch(my_model, size=224) # ImageNet normalisation by default
# Keras
predict = lc.from_keras(my_keras_model, scale=255) # if it was trained on 0-255 pixels
# anything else: any function images -> (N, n_classes) probabilities or logits
predict = lambda batch: my_api.classify(batch)
report = lc.scan(predict, images, labels, class_names=classes, boxes=boxes)
report.spots # one row per class and grid cell: drop, contrast, consistency, p-values
report.objects # one row per class: erased-object and background-swap results
report.texture # shuffled-tile and grayscale accuracy
report.examples("square") # the images most affected by the flagged spot
images can be an array (0-1 or 0-255), a list of PIL images, or file paths. Labels can be integers or class
names. Boxes are (x0, y0, x1, y1) in pixels. Without masks or boxes, tests 1 and 3 still run.
Cost. Test 1 sends images x (grid² + 1) pictures through the model: 600 images on an 8x8 grid is about
39,000 forward passes, which took under a minute for the small CNNs here on two CPU cores. Use
max_images= and grid= to trade detail for speed.
Limitations
- Covering a region changes the picture itself. The random-hole control and the class contrast are there to
separate "the model needs this spot" from "the model dislikes holes", but a model that reacts very
differently to the fill colour can still confuse test 2. Try
fill="blur"as a second opinion. - Test 1 sees spots that stay in the same place. A shortcut that moves with the object (a ruler next to the lesion) needs test 2 with good masks.
- The checks so far use synthetic images with planted shortcuts, where the truth is known. Automatic object masks from a text-prompted segmenter and case studies on public medical and wildlife models are next.
Background
- Lapuschkin et al. (2019), Unmasking Clever Hans predictors and assessing what machines really learn. Nature Communications.
- Zech et al. (2018), Variable generalization performance of a deep learning model to detect pneumonia in chest radiographs. PLOS Medicine.
- Winkler et al. (2019), Association between surgical skin markings in dermoscopic images and diagnostic performance of a deep learning convolutional neural network for melanoma recognition. JAMA Dermatology.
- Xiao et al. (2021), Noise or Signal: The Role of Image Backgrounds in Object Recognition. ICLR.
- Geirhos et al. (2020), Shortcut learning in deep neural networks. Nature Machine Intelligence.
Related tools
From the same "statistics that lie" toolkit: cheatcheck (the same question for text datasets), nacheck, simpsonscan, chartaudit, pandas-mergeguard and gapnet.
License
MIT
Metadata
Release files for lookcheck 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lookcheck-0.1.0.tar.gz | 35.8 kB | With provenance | Details for lookcheck-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lookcheck-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lookcheck-0.1.0-py3-none-any.whl |
Total release size: 58.6 kB
Release files / lookcheck-0.1.0.tar.gz
| Download URL | lookcheck-0.1.0.tar.gz |
|---|---|
| Size | 35.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c79648f876893708ea8546c965ec0018f89356a4c949e9b21c0e80be0de543fc
|
|
BLAKE2b-256 checksum How to use checksums |
2dfb9a69c0f99d9dff264fc30d9acc93beea485988f634280d71b69ac87fb78d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / lookcheck-0.1.0-py3-none-any.whl
| Download URL | lookcheck-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6aa93c90b0c7b47422ac3e80e92c49aa5288f6405c6f83a8db5f9a09a11c84ba
|
|
BLAKE2b-256 checksum How to use checksums |
be9c0f70cdf4581c4968c252912f6e6202829b4286cbd5d9a1a71bcacfc1b9b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logSecurity for lookcheck 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lookcheck-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.