code: def _test_backend_mnist(
      self, classifier, x_train, y_train, x_test, y_test
  ):
      x_test_original = x_test.copy()
  
      # Test PGD with np.inf norm
      attack = ProjectedGradientDescent(
          classifier, eps=1.0, eps_step=0.1, verbose=False
      )
      x_train_adv = attack.generate(x_train)
      x_test_adv = attack.generate(x_test)
  
      self.assertFalse((x_train == x_train_adv).all())
      self.assertFalse((x_test == x_test_adv).all())
  
      train_y_pred = get_labels_np_array(
          classifier.predict(x_train_adv)
      )
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
  
      self.assertFalse((y_train == train_y_pred).all())
      self.assertFalse((y_test == test_y_pred).all())
  
      acc = (
          np.sum(
              np.argmax(train_y_pred, axis=1)
              == np.argmax(y_train, axis=1)
          )
          / y_train.shape[0]
      )
      logger.info(
          "Accuracy on adversarial train examples: %.2f%%", acc * 100
      )
  
      acc = (
          np.sum(
              np.argmax(test_y_pred, axis=1)
              == np.argmax(y_test, axis=1)
          )
          / y_test.shape[0]
      )
      logger.info(
          "Accuracy on adversarial test examples: %.2f%%", acc * 100
      )
  
      # Test PGD with 3 random initialisations
      attack = ProjectedGradientDescent(
          classifier, num_random_init=3, verbose=False
      )
      x_train_adv = attack.generate(x_train)
      x_test_adv = attack.generate(x_test)
  
      self.assertFalse((x_train == x_train_adv).all())
      self.assertFalse((x_test == x_test_adv).all())
  
      train_y_pred = get_labels_np_array(
          classifier.predict(x_train_adv)
      )
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
  
      self.assertFalse((y_train == train_y_pred).all())
      self.assertFalse((y_test == test_y_pred).all())
  
      acc = (
          np.sum(
              np.argmax(train_y_pred, axis=1)
              == np.argmax(y_train, axis=1)
          )
          / y_train.shape[0]
      )
      logger.info(
          "Accuracy on adversarial train examples with 3 random initialisations: %.2f%%",
          acc * 100,
      )
  
      acc = (
          np.sum(
              np.argmax(test_y_pred, axis=1)
              == np.argmax(y_test, axis=1)
          )
          / y_test.shape[0]
      )
      logger.info(
          "Accuracy on adversarial test examples with 3 random initialisations: %.2f%%",
          acc * 100,
      )
  
      # 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,
      )
  
      # Test the masking
      attack = ProjectedGradientDescent(
          classifier, num_random_init=1, verbose=False
      )
      mask = np.random.binomial(n=1, p=0.5, size=np.prod(x_test.shape))
      mask = mask.reshape(x_test.shape).astype(np.float32)
  
      x_test_adv = attack.generate(x_test, mask=mask)
      mask_diff = (1 - mask) * (x_test_adv - x_test)
      self.assertAlmostEqual(
          float(np.max(np.abs(mask_diff))), 0.0, delta=0.00001
      )
  
      # Test eps of array type 1
      attack = ProjectedGradientDescent(
          classifier, eps=1.0, eps_step=0.1, verbose=False
      )
  
      eps = np.ones(shape=x_test.shape) * 1.0
      eps_step = np.ones_like(eps) * 0.1
  
      attack_params = {"eps_step": eps_step, "eps": eps}
      attack.set_params(**attack_params)
  
      x_test_adv = attack.generate(x_test)
      self.assertFalse((x_test == x_test_adv).all())
  
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == test_y_pred).all())
  
      # Test eps of array type 2
      eps = np.ones(shape=x_test.shape[1:]) * 1.0
      eps_step = np.ones_like(eps) * 0.1
  
      attack_params = {"eps_step": eps_step, "eps": eps}
      attack.set_params(**attack_params)
  
      x_test_adv = attack.generate(x_test)
      self.assertFalse((x_test == x_test_adv).all())
  
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == test_y_pred).all())
  
      # Test eps of array type 3
      eps = np.ones(shape=x_test.shape[2:]) * 1.0
      eps_step = np.ones_like(eps) * 0.1
  
      attack_params = {"eps_step": eps_step, "eps": eps}
      attack.set_params(**attack_params)
  
      x_test_adv = attack.generate(x_test)
      self.assertFalse((x_test == x_test_adv).all())
  
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == test_y_pred).all())
  
      # Test eps of array type 4
      eps = np.ones(shape=x_test.shape[3:]) * 1.0
      eps_step = np.ones_like(eps) * 0.1
  
      attack_params = {"eps_step": eps_step, "eps": eps}
      attack.set_params(**attack_params)
  
      x_test_adv = attack.generate(x_test)
      self.assertFalse((x_test == x_test_adv).all())
  
      test_y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == test_y_pred).all())
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  import tensorflow
  from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent import ProjectedGradientDescent
  from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent_numpy import ProjectedGradientDescentNumpy, ProjectedGradientDescentCommon
  from art.estimators.classification import KerasClassifier
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin
  from art.utils import get_labels_np_array, random_targets
  from tests.attacks.utils import backend_test_classifier_type_check_fail
  from tests.utils import TestBase, get_image_classifier_kr, get_image_classifier_pt, get_image_classifier_tf, get_tabular_classifier_kr, get_tabular_classifier_pt, get_tabular_classifier_tf, master_seed
label_desc: Use image node_id 6 for calling the TestPGD obj's underlying member method code with example usage: obj._test_backend_mnist(classifier, x_train, y_train, x_test, y_test) without return types