advsecurenet.attacks.base package


advsecurenet.attacks.base.adversarial_attack module

class advsecurenet.attacks.base.adversarial_attack.AdversarialAttack(config: AttackConfig)

Bases: ABC

Abstract class for adversarial attacks.

abstract attack(model: BaseModel, x: Tensor, y: Tensor, *args, **kwargs) Tensor | Tuple[Tensor, bool]

Performs the attack on the specified model and input.

Parameters:
  • model (BaseModel) – The model to attack.

  • x (torch.tensor) – The original input tensor. Expected shape is (batch_size, channels, height, width).

  • y (torch.tensor) – The true labels for the input tensor. Expected shape is (batch_size,).

Returns:

The adversarial example tensor. Optional[bool]: True if the attack was successful, False otherwise. This is specially used in LOTS attack.

Return type:

torch.tensor