Safety Metrics¶
-
class
perceptron.benchmarks.
AdditiveNoiseMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Base class for metric that tests models against additive noise.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, epsilons=10000)[source]¶ Adds uniform or Gaussian noise to the image, gradually increasing the standard deviation until the image is misclassified.
Parameters: - adv : numpy.ndarray or
Adversarial
The original, unperturbed input as a numpy.ndarray or an
Adversarial
instance.- annotation : int
The reference label of the original input. Must be passed if a is a numpy.ndarray, must not be passed if a is an
Adversarial
instance.- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- epsilons : int or Iterable[float]
Either Iterable of standard deviations of the Gaussian blur or number of standard deviations between 0 and 1 that should be tried.
- adv : numpy.ndarray or
-
-
class
perceptron.benchmarks.
AdditiveGaussianNoiseMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against Gaussian noise.
-
class
perceptron.benchmarks.
AdditiveUniformNoiseMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against uniform noise.
-
class
perceptron.benchmarks.
BlendedUniformNoiseMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Blends the image with a uniform noise image until it is misclassified.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, epsilons=10000, max_directions=1000)[source]¶ Metric that tests models against blended uniform noise.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- epsilons : int or Iterable[float]
Either Iterable of standard deviations of the blended noise or number of standard deviations between 0 and 1 that should be tried.
- max_directions : int
Maximum number of random images to try.
-
-
class
perceptron.benchmarks.
GaussianBlurMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against Gaussian blurs.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, epsilons=10000)[source]¶ Blurs the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- epsilons : int or Iterable[float]
Either Iterable of standard deviations of the Gaussian blur or number of standard deviations between 0 and 1 that should be tried.
-
-
class
perceptron.benchmarks.
BrightnessMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against brightness variations.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, verify=False, epsilons=1000)[source]¶ Change the brightness of the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input. Must be passed if a is a numpy.ndarray.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- verify : bool
If True, return verifiable bound.
- epsilons : int or Iterable[float]
Either Iterable of contrast levels or number of brightness factors between 1 and 0 that should be tried. Epsilons are one minus the brightness factor. Epsilons are not used if verify = True.
-
-
class
perceptron.benchmarks.
ContrastReductionMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against brightness variations.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, threshold=1.0, epsilons=1000)[source]¶ Reduces the contrast of the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- threshold : float
Upper bound for contrast factor
- epsilons : int or Iterable[float]
Either Iterable of contrast levels or number of contrast levels between 1 and 0 that should be tried. Epsilons are one minus the contrast level.
-
-
class
perceptron.benchmarks.
MotionBlurMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Motion blurs the image until it is misclassified.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, motion_angle=0, epsilons=10000)[source]¶ Blurs the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- motion_angle : float
Motion angle in degree between 0 and 180.
- epsilons : int or Iterable[float]
Either Iterable of kernel size that should be tried.
-
-
class
perceptron.benchmarks.
RotationMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against rotations.
-
__call__
(self, adv, ang_range=None, annotation=None, unpack=True, abort_early=True, verify=False, epsilons=1000)[source]¶ Rotate the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- ang_range : (float, float)
Range of angles for rotation metric.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- verify : bool
if True, return verifiable bound.
- epsilons : int or Iterable[float]
Either Iterable of rotation angles or number of angles between 1 and 0 that should be tried. Epsilons are one minus the contrast level. Epsilons are not used if verify = True.
-
-
class
perceptron.benchmarks.
SaltAndPepperNoiseMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Add salt and pepper noise.
-
__call__
(self, adv, annotation=None, unpack=True, abort_early=True, epsilons=10000, repetitions=10)[source]¶ Add salt and pepper noise.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- epsilons : int or Iterable[float]
Either Iterable of standard deviations of the salt and pepper or number of standard deviations between 0 and 1 that should be tried.
- repetitions : int
Specifies how often the attack will be repeated.
-
-
class
perceptron.benchmarks.
SpatialMetric
(model=None, criterion=None, distance=<class 'perceptron.utils.distances.MeanSquaredDistance'>, threshold=None)[source]¶ Metric that tests models against spatial transformations.
-
__call__
(self, adv, annotation=None, do_rotations=True, do_translations=True, x_shift_limits=(-5, 5), y_shift_limits=(-5, 5), angular_limits=None, unpack=True, abort_early=True, verify=False, epsilons=1000)[source]¶ Spatial transforms the image until it is misclassified.
Parameters: - adv : numpy.ndarray
The original, unperturbed input as a numpy.ndarray.
- annotation : int
The reference label of the original input.
- do_rotations : bool
If False no rotations will be applied to the image (default True).
- do_translations : bool
If False no translations will be applied to the image (default True).
- x_shift_limits : (int, int)
Limits for horizontal translations in pixels (default (-5, 5)).
- y_shift_limits : (int, int)
Limits for vertical translations in pixels (default (-5, 5)).
- angular_limits : (int, int)
Limits for rotations in degrees (default None).
- unpack : bool
If true, returns the adversarial input, otherwise returns the Adversarial object.
- abort_early : bool
If true, returns when got first adversarial, otherwise returns when all the iterations are finished.
- verify : bool
if True, return verifiable bound
- epsilons : int or Iterable[float]
Either Iterable of contrast levels or number of contrast levels between 1 and 0 that should be tried. Epsilons are one minus the contrast level.
-