-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updating scenario configs for eval 3 (#1123) * handling merge conflict * bump version 0.13.3 --> 0.13.4 * log that random patch location is being used Co-authored-by: Yusong Tan <ytan@mitre.org> * small updates for Eval 3 (#1126) * small updates for Eval 3 * updated kwargs and moved assert -> valueerror * lint Co-authored-by: David Slater <david.slater@twosixlabs.com> Co-authored-by: Yusong Tan <ytan@mitre.org> Co-authored-by: yusong-tan <59029053+yusong-tan@users.noreply.github.com> Co-authored-by: David Slater <david.slater@twosixlabs.com>
- Loading branch information
1 parent
c249287
commit 8eb10ac
Showing
61 changed files
with
1,148 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
|
||
# Semantic Version | ||
__version__ = "0.13.3" | ||
__version__ = "0.13.4" | ||
|
||
|
||
# Submodule imports | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from art.attacks.evasion import RobustDPatch | ||
import numpy as np | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RobustDPatch(RobustDPatch): | ||
""" | ||
Generate and apply patch | ||
""" | ||
|
||
def __init__(self, estimator, **kwargs): | ||
# allows for random patch location | ||
if "patch_location" not in kwargs: | ||
self.random_location = True | ||
else: | ||
self.random_location = False | ||
super().__init__(estimator=estimator, **kwargs) | ||
|
||
def generate(self, x, y=None, **generate_kwargs): | ||
if self.random_location: | ||
logger.info("Selecting random coordinates for patch_location.") | ||
self.patch_location = ( | ||
np.random.randint(int(x.shape[-3] - self.patch_shape[0])), | ||
np.random.randint(int(x.shape[-2] - self.patch_shape[1])), | ||
) | ||
super().generate(x, y=y, **generate_kwargs) | ||
return super().apply_patch(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from art.attacks.evasion import ProjectedGradientDescent | ||
import numpy as np | ||
|
||
|
||
class FrameBorderPatch(ProjectedGradientDescent): | ||
""" | ||
Apply Masked PGD to video inputs, where only the | ||
video frame is allowed to be perturbed. | ||
Each video is assumed to have shape (NFHWC). | ||
""" | ||
|
||
def __init__(self, estimator, **kwargs): | ||
super().__init__(estimator=estimator, **kwargs) | ||
|
||
def generate(self, x, y=None, patch_ratio=None, **kwargs): | ||
if patch_ratio is None: | ||
raise ValueError("generate_kwargs did not define 'patch_ratio'") | ||
if x.ndim != 5: | ||
raise ValueError("This attack is designed for videos (5-dim)") | ||
width = x.shape[3] | ||
height = x.shape[2] | ||
|
||
t1 = ( | ||
2 * (width + height) | ||
+ (4 * (width + height) ** 2 - 16 * (patch_ratio * width * height)) ** 0.5 | ||
) / 8 | ||
t2 = ( | ||
2 * (width + height) | ||
- (4 * (width + height) ** 2 - 16 * (patch_ratio * width * height)) ** 0.5 | ||
) / 8 | ||
thickness = int(min(t1, t2)) | ||
|
||
if (width - 2 * thickness) * (height - 2 * thickness) < ( | ||
1 - patch_ratio | ||
) * width * height: | ||
raise ValueError("patch_ratio does not match height and width") | ||
|
||
mask = np.ones(shape=x.shape[1:], dtype=np.float32) | ||
|
||
mask[:, thickness : height - thickness, thickness : width - thickness, :] = 0.0 | ||
|
||
return super().generate(x, y=y, mask=mask, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.