Input Optimization

While other implementations (such as advertorch) exist, this one is meant to be as easy, accessible, informative and modular as training model. In fact, this implementation uses fastai’s Learner class, and inherits its functionality, such as the progress bar, the losses table, and even early stopping and lr scheduling. Useful for evasion and feature-collision attacks.


source

InputOptimizer

 InputOptimizer (model:fastai.torch_core.Module,
                 pert_cb:Type[__main__.PerturbationCallback],
                 loss:Callable=FlattenedLoss of CrossEntropyLoss(),
                 lr:float=None, targeted:bool=False, min_delta:float=0.01,
                 min_lr:float=1e-06, epoch_size:int=10, n_epochs:int=4)

Constructs adversarial examples: slightly perturbed inputs that fool classification models

Type Default Details
model Module
pert_cb typing.Type[main.PerturbationCallback]
loss typing.Callable FlattenedLoss of CrossEntropyLoss()
lr float None pass None to try pick lr based on other parameters
targeted bool False Whether the constructed inputs should be classified as the specified targets or not
min_delta float 0.01 Minimum loss delta for ReduceLROnPlateau and EarlyStoppingCallback
min_lr float 1e-06 Minimum lr for ReduceLROnPlateau
epoch_size int 10 Affects how often epoch-callbacks are called (e.g. Recorder`` andEarlyStoppingCallback`)
n_epochs int 4

source

PerturbationCallback

 PerturbationCallback (after_create=None, before_fit=None,
                       before_epoch=None, before_train=None,
                       before_batch=None, after_pred=None,
                       after_loss=None, before_backward=None,
                       after_cancel_backward=None, after_backward=None,
                       before_step=None, after_cancel_step=None,
                       after_step=None, after_cancel_batch=None,
                       after_batch=None, after_cancel_train=None,
                       after_train=None, before_validate=None,
                       after_cancel_validate=None, after_validate=None,
                       after_cancel_epoch=None, after_epoch=None,
                       after_cancel_fit=None, after_fit=None)

Manages the input perturbation for an InputOptimizer


source

InputOptimizer.perturb

 InputOptimizer.perturb (dsets)