shapiq_benchmark.setups.ImageClassifierSetup

class shapiq_benchmark.setups.ImageClassifierSetup(*, index=0, split='val', size='320px', model='vit_9_patches', n_superpixels=14, fill=None, mask_strategy=None, class_index=None, revision=None, normalize=True, device='cpu', batch_size=16)[source]

Bases: Setup

An ImageClassifier game for an Imagenette image.

The images come from shapiq_benchmark.datasets.load_imagenette(), which downloads the archive on first use.

Variables:
  • index – The position of the image in the split. Defaults to 0.

  • split – The Imagenette split, "val" (default) or "train".

  • size – The image size, "320px" (default) or "160px".

  • model – The builtin model: a vision transformer ("vit_9_patches", default), DINOv2 ("dinov2_16_patches", "dinov2_20_patches", "dinov2_25_patches"), or "resnet_18".

  • n_superpixels – The number of superpixels for "resnet_18". Defaults to 14.

  • fill – Remove players in image space with this fill (for "resnet_18", None means the mean color; a vision transformer given a fill removes its patches in image space; DINOv2 takes none).

  • mask_strategy – How a vision transformer removes players in token space, "mask" (None, the default) or "remove"; DINOv2 only drops tokens (see ImageClassifier).

  • class_index – The explained ImageNet class: None for the predicted class, "label" for the image’s true class, or a class index.

  • revision – The Hugging Face revision of a vision transformer (None for the default branch).

  • normalize – Whether to center the game. Defaults to True.

  • device – The torch device. A runtime field: it does not change the cache key.

  • batch_size – The number of masked images per forward pass (a runtime field).

Examples

>>> setup = ImageClassifierSetup(index=388, model="resnet_18", class_index="label")
>>> game = setup.build()
build()[source]

Load the image and the model and build the game.

Return type:

ImageClassifier

to_dict()

Return the setup as a JSON-serializable dictionary (the inverse of setup_from_dict()).

Return type:

dict[str, Any]

batch_size = 16
class_index = None
device = 'cpu'
fill = None
index = 0
property key

A stable identifier of the game this setup builds, used as its cache key.

It is a digest of the setup’s name, version, RECIPE_VERSION, and fields (runtime fields excluded), so it is the same across processes and machines.

mask_strategy = None
model = 'vit_9_patches'
n_superpixels = 14
name = 'image_classifier'

The registered name of the setup.

normalize = True
revision = None
size = '320px'
split = 'val'
version = 1

The version of build(), part of key.