class_docstr: A unittest class for testing the ZOO attack.
class_docstr_tok: ["A","unittest","class","for","testing","the","ZOO","attack","."]
docstr: Second test with the KerasClassifier.
  :return:
docstr_tok: ["Second","test","with","the","KerasClassifier",".",":","return",":"]
code: def test_5_keras_mnist(self):
      """
      Second test with the KerasClassifier.
      :return:
      """
      x_test_original = self.x_test_mnist.copy()
  
      # Build KerasClassifier
      krc = get_image_classifier_kr()
  
      # Targeted attack
      # zoo = ZooAttack(classifier=krc, targeted=True, batch_size=5, verbose=False)
      # params = {'y': random_targets(self.y_test, krc.nb_classes)}
      # x_test_adv = zoo.generate(self.x_test, **params)
      #
      # self.assertFalse((self.x_test == x_test_adv).all())
      # self.assertLessEqual(np.amax(x_test_adv), 1.0)
      # self.assertGreaterEqual(np.amin(x_test_adv), 0.0)
      # target = np.argmax(params['y'], axis=1)
      # y_pred_adv = np.argmax(krc.predict(x_test_adv), axis=1)
      # logger.debug('ZOO target: %s', target)
      # logger.debug('ZOO actual: %s', y_pred_adv)
      # logger.info('ZOO success rate on MNIST: %.2f', (sum(target == y_pred_adv) / float(len(target))))
  
      # Untargeted attack
      # zoo = ZooAttack(classifier=krc, targeted=False, max_iter=20, verbose=False)
      zoo = ZooAttack(
          classifier=krc,
          targeted=False,
          batch_size=5,
          max_iter=10,
          binary_search_steps=3,
          verbose=False,
      )
      # x_test_adv = zoo.generate(x_test)
      params = {"y": random_targets(self.y_test_mnist, krc.nb_classes)}
      x_test_mnist_adv = zoo.generate(self.x_test_mnist, **params)
  
      # x_test_adv_true = [0.00000000e+00, 2.50167388e-04, 1.50529508e-04, 4.69674182e-04,
      #                    0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
      #                    1.67321396e-05, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
      #                    0.00000000e+00, 2.08451956e-06, 0.00000000e+00, 0.00000000e+00,
      #                    2.53360748e-01, 9.60119188e-01, 9.85227525e-01, 2.53600776e-01,
      #                    0.00000000e+00, 0.00000000e+00, 5.23251540e-04, 0.00000000e+00,
      #                    0.00000000e+00, 0.00000000e+00, 1.08632184e-05, 0.00000000e+00]
      #
      # for i in range(14):
      #     self.assertAlmostEqual(x_test_adv_true[i], x_test_adv[0, 14, i, 0])
  
      # self.assertFalse((x_test == x_test_adv).all())
      self.assertLessEqual(np.amax(x_test_mnist_adv), 1.0)
      self.assertGreaterEqual(np.amin(x_test_mnist_adv), 0.0)
      y_pred_adv = np.argmax(krc.predict(x_test_mnist_adv), axis=1)
      y_pred = np.argmax(krc.predict(self.x_test_mnist), axis=1)
      logger.debug("ZOO actual: %s", y_pred_adv)
      logger.info(
          "ZOO success rate on MNIST: %.2f",
          (sum(y_pred != y_pred_adv) / float(len(y_pred))),
      )
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - self.x_test_mnist))),
          0.0,
          delta=0.00001,
      )
  
      # Clean-up
      k.clear_session()
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import keras.backend
  import numpy
  from art.attacks.evasion.zoo import ZooAttack
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import random_targets
  from tests.utils import TestBase, get_image_classifier_kr, get_image_classifier_pt
  from tests.utils import get_image_classifier_tf, master_seed
  from tests.attacks.utils import backend_test_classifier_type_check_fail
label_desc: Use image node_id 4 for calling the TestZooAttack obj's underlying member method code with example usage: obj.test_5_keras_mnist() without return types