attribench.functional.metrics.impact_coverage
- attribench.functional.metrics.impact_coverage(model, samples_dataset, batch_size, method_dict, patch_folder, device=device(type='cpu'))[source]
Computes the Impact Coverage metric for a given dataset, model, and set of attribution methods.
Impact Coverage is computed by applying an adversarial patch to the input. This patch causes the model to change its prediction. The Impact Coverage metric is the intersection over union (IoU) of the patch with the top n attributions of the input, where n is the number of features masked by the patch. The idea is that, as the patch causes the model to change its prediction, the corresponding region in the image should be highly relevant to the model’s prediction.
Impact Coverage requires a folder containing adversarial patches. The patches should be named as follows: patch_<target>.pt, where <target> is the target class of the patch. The target class is the class that the model will predict when the patch is applied to the input.
To generate adversarial patches, the
train_adversarial_patches()function orTrainAdversarialPatchesclass can be used.- Parameters:
- modelnn.Module
Model to compute Impact Coverage for.
- samples_datasetDataset
Dataset to compute Impact Coverage for.
- batch_sizeint
Batch size to use when computing Impact Coverage.
- method_dictDict[str, AttributionMethod]
Dictionary mapping method names to attribution methods.
- patch_folderstr
Path to folder containing adversarial patches.
- devicetorch.device, optional
Device to use for computing Impact Coverage. Default: torch.device(“cpu”)
- Returns:
- ImpactCoverageResult
Result of the Impact Coverage metric.
- Return type: