def __call__(self, input_or_adv, label=None, unpack=True,
                 max_pixels=1000):

        """Perturbs just a single pixel and sets it to the min or max.

        Parameters
        ----------
        input_or_adv : `numpy.ndarray` or :class:`Adversarial`
            The original, correctly classified image. If image is a
            numpy array, label must be passed as well. If image is
            an :class:`Adversarial` instance, label must not be passed.
        label : int
            The reference label of the original image. Must be passed
            if image is a numpy array, must not be passed if image is
            an :class:`Adversarial` instance.
        unpack : bool
            If true, returns the adversarial image, otherwise returns
            the Adversarial object.
        max_pixels : int
            Maximum number of pixels to try.

        """

        a = input_or_adv
        del input_or_adv
        del label
        del unpack

        channel_axis = a.channel_axis(batch=False)
        image = a.original_image
        axes = [i for i in range(image.ndim) if i != channel_axis]
        assert len(axes) == 2
        h = image.shape[axes[0]]
        w = image.shape[axes[1]]

        min_, max_ = a.bounds()

        pixels = nprng.permutation(h * w)
        pixels = pixels[:max_pixels]
        for i, pixel in enumerate(pixels):
            x = pixel % w
            y = pixel // w

            location = [x, y]
            location.insert(channel_axis, slice(None))
            location = tuple(location)

            for value in [min_, max_]:
                perturbed = image.copy()
                perturbed[location] = value

                _, is_adv = a.predictions(perturbed)
                if is_adv:
                    return
def __call__ ( self , input_or_adv , label = None , unpack = True , max_pixels = 1000 ) : a = input_or_adv del input_or_adv del label del unpack channel_axis = a . channel_axis ( batch = False ) image = a . original_image axes = [ i for i in range ( image . ndim ) if i != channel_axis ] assert len ( axes ) == 2 h = image . shape [ axes [ 0 ] ] w = image . shape [ axes [ 1 ] ] min_ , max_ = a . bounds ( ) pixels = nprng . permutation ( h * w ) pixels = pixels [ : max_pixels ] for i , pixel in enumerate ( pixels ) : x = pixel % w y = pixel // w location = [ x , y ] location . insert ( channel_axis , slice ( None ) ) location = tuple ( location ) for value in [ min_ , max_ ] : perturbed = image . copy ( ) perturbed [ location ] = value _ , is_adv = a . predictions ( perturbed ) if is_adv : return
Perturbs just a single pixel and sets it to the min or max.

        Parameters
        ----------
        input_or_adv : `numpy.ndarray` or :class:`Adversarial`
            The original, correctly classified image. If image is a
            numpy array, label must be passed as well. If image is
            an :class:`Adversarial` instance, label must not be passed.
        label : int
            The reference label of the original image. Must be passed
            if image is a numpy array, must not be passed if image is
            an :class:`Adversarial` instance.
        unpack : bool
            If true, returns the adversarial image, otherwise returns
            the Adversarial object.
        max_pixels : int
            Maximum number of pixels to try.