Skip to content

Commit

Permalink
Adjust order.
Browse files Browse the repository at this point in the history
  • Loading branch information
mzweilin committed Sep 28, 2023
1 parent d3f7869 commit 8db66dc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mart/attack/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ def forward(self, perturbation, input, target):
return perturbation, input, target


class PerturbationMask(Function):
def __init__(self, *args, key="perturbable_mask", **kwargs):
super().__init__(*args, **kwargs)
self.key = key

def forward(self, perturbation, input, target):
mask = target[self.key]
perturbation = perturbation * mask
return perturbation, input, target


# TODO: We may decompose Overlay into: perturbation-mask, input-re-mask, additive.
class Overlay(Function):
"""We assume an adversary overlays a patch to the input."""
Expand Down Expand Up @@ -163,6 +152,17 @@ def forward(self, perturbation, input, target):
return perturbation, input, target


class PerturbationMask(Function):
def __init__(self, *args, key="perturbable_mask", **kwargs):
super().__init__(*args, **kwargs)
self.key = key

def forward(self, perturbation, input, target):
mask = target[self.key]
perturbation = perturbation * mask
return perturbation, input, target


class PerturbationRectangleCrop(Function):
def __init__(self, *args, coords_key="patch_coords", **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 8db66dc

Please sign in to comment.