Spaces:
Sleeping
Sleeping
File size: 1,508 Bytes
957e2dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import torch
from src.attacks.offline.offline import OfflineAttack
from src.pipelines.pipeline import Pipeline
from src.loss.adversarial import AdversarialLoss
from src.utils.writer import Writer
################################################################################
# "Null" attack (apply no perturbations to inputs)
################################################################################
class NullAttack(OfflineAttack):
"""
Simple baseline attack in which inputs are passed to model unaltered.
"""
def __init__(self,
pipeline: Pipeline,
adv_loss: AdversarialLoss,
batch_size: int = 1,
rand_evals: int = 0,
writer: Writer = None,
**kwargs
):
super().__init__(
pipeline=pipeline,
adv_loss=adv_loss,
batch_size=batch_size,
rand_evals=rand_evals,
writer=writer
)
def _evaluate_batch(self,
x: torch.Tensor,
y: torch.Tensor,
**kwargs
):
"""
Apply no perturbations to inputs.
"""
# compute adversarial inputs
x_adv = x.clone().detach()
# log attack results
self._log_step(
x=x,
x_adv=x_adv,
y=y
)
return x_adv
|