attribench.functional.train_adversarial_patches

attribench.functional.train_adversarial_patches(model, dataset, num_patches, batch_size, path, labels=None, device=None)[source]

Train adversarial patches for a given model and dataset. If path is not None, the patches are saved to disk. Otherwise, they are returned as a list.

Parameters:
modelnn.Module

The model for which the patches should be trained.

datasetDataset

Torch Dataset to use for training the patches.

num_patchesint

The number of patches to train.

batch_sizeint

The batch size to use for training.

pathOptional[str]

The path to which the patches should be saved. If None, the patches are returned as a list. Default: None.

labelsOptional[Tuple[int]], optional

Tuple of labels to use for the patches. If None, the labels are assumed to be range(num_patches). Default: None.

deviceOptional[torch.device], optional

Device to use, by default None.

Returns:
List[torch.Tensor] | None

If path is None, a list of patches. Otherwise, None.

Return type:

Optional[List[Tensor]]