class_docstr: A unittest class for testing the ElasticNet attack.
class_docstr_tok: ["A","unittest","class","for","testing","the","ElasticNet","attack","."]
docstr: Third test with the PyTorchClassifier.
  :return:
docstr_tok: ["Third","test","with","the","PyTorchClassifier",".",":","return",":"]
code: def test_6_pytorch_mnist(self):
      """
      Third test with the PyTorchClassifier.
      :return:
      """
      x_test = np.reshape(
          self.x_test_mnist, (self.x_test_mnist.shape[0], 1, 28, 28)
      ).astype(np.float32)
      x_test_original = x_test.copy()
  
      # Build PyTorchClassifier
      ptc = get_image_classifier_pt(from_logits=False)
  
      # First attack
      ead = ElasticNet(
          classifier=ptc, targeted=True, max_iter=2, verbose=False
      )
      params = {"y": random_targets(self.y_test_mnist, ptc.nb_classes)}
      x_test_adv = ead.generate(x_test, **params)
      expected_x_test_adv = np.asarray(
          [
              0.01758931,
              0.0,
              0.0,
              0.0,
              0.0,
              0.0,
              0.0,
              0.0,
              0.00698278,
              0.0,
              0.11318438,
              0.36223832,
              0.54720753,
              0.93125045,
              1.0,
              0.9999359,
              0.8638486,
              0.6354147,
              0.5600332,
              0.24081531,
              0.25882354,
              0.00899846,
              0.0,
              0.0,
              0.0,
              0.0,
              0.0,
              0.0,
          ]
      )
      np.testing.assert_array_almost_equal(
          x_test_adv[2, 0, :, 14], expected_x_test_adv, decimal=6
      )
      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(ptc.predict(x_test_adv), axis=1)
      self.assertTrue((target == y_pred_adv).any())
  
      # Second attack
      ead = ElasticNet(
          classifier=ptc, targeted=False, max_iter=2, verbose=False
      )
      params = {"y": random_targets(self.y_test_mnist, ptc.nb_classes)}
      x_test_adv = ead.generate(x_test, **params)
      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(ptc.predict(x_test_adv), axis=1)
      self.assertTrue((target != y_pred_adv).any())
      np.testing.assert_array_equal(
          y_pred_adv, np.asarray([7, 1, 1, 4, 4, 1, 4, 4, 4, 4])
      )
  
      # 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,
      )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import keras.backend
  import numpy
  from art.attacks.evasion.elastic_net import ElasticNet
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassGradientsMixin
  from art.estimators.classification.keras import KerasClassifier
  from art.utils import random_targets, to_categorical
  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 TestElasticNet obj's underlying member method code with example usage: obj.test_6_pytorch_mnist() without return types