class_docstr: A unittest class for testing the Pixel Attack.
  
  This module tests the Pixel Attack.
  The Pixel Attack is a generalisation of One Pixel Attack.
  
  | One Pixel Attack Paper link:
      https://ieeexplore.ieee.org/abstract/document/8601309/citations#citations
      (arXiv link: https://arxiv.org/pdf/1710.08864.pdf)
  | Pixel Attack Paper link:
      https://arxiv.org/abs/1906.06026
class_docstr_tok: ["A","unittest","class","for","testing","the","Pixel","Attack",".","This","module","tests","the","Pixel","Attack",".","The","Pixel","Attack","is","a","generalisation","of","One","Pixel","Attack",".","|","One","Pixel","Attack","Paper","link",":","https",":","\/\/ieeexplore.ieee.org\/abstract\/document\/8601309\/citations","#","citations","(","arXiv","link",":","https",":","\/\/arxiv.org\/pdf\/1710.08864.pdf",")","|","Pixel","Attack","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1906.06026"]
docstr: Test with the Pixel Attack
  :return:
docstr_tok: ["Test","with","the","Pixel","Attack",":","return",":"]
code: def _test_attack(self, classifier, x_test, y_test, targeted):
      """
      Test with the Pixel Attack
      :return:
      """
      x_test_original = x_test.copy()
  
      if targeted:
          # Generate random target classes
          class_y_test = np.argmax(y_test, axis=1)
          nb_classes = np.unique(class_y_test).shape[0]
          targets = np.random.randint(nb_classes, size=self.n_test)
          for i in range(self.n_test):
              if class_y_test[i] == targets[i]:
                  targets[i] -= 1
      else:
          targets = y_test
  
      for th in [None, 128]:
          for es in [0, 1]:
              df = PixelAttack(
                  classifier,
                  th=th,
                  es=es,
                  max_iter=20,
                  targeted=targeted,
                  verbose=False,
              )
              x_test_adv = df.generate(x_test_original, targets)
  
              np.testing.assert_raises(
                  AssertionError,
                  np.testing.assert_array_equal,
                  x_test,
                  x_test_adv,
              )
              self.assertFalse((0.0 == x_test_adv).all())
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - x_test))),
          0.0,
          delta=0.00001,
      )
  
file_path: adversarial-robustness-toolbox/tests/attacks/test_pixel_attack.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  from art.attacks.evasion.pixel_threshold import PixelAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from tests.utils import TestBase
  from tests.utils import get_image_classifier_tf, get_image_classifier_pt
  from tests.attacks.utils import backend_test_classifier_type_check_fail
label_desc: Use image node_id 5 for calling the TestPixelAttack obj's underlying member method code with example usage: obj._test_attack(classifier, x_test, y_test, targeted) without return types