class_docstr: A unittest class for testing the DefensiveDistillation transformer on image data.
class_docstr_tok: ["A","unittest","class","for","testing","the","DefensiveDistillation","transformer","on","image","data","."]
docstr: Second test with the PyTorchClassifier.
  :return:
docstr_tok: ["Second","test","with","the","PyTorchClassifier",".",":","return",":"]
code: def test_3_pytorch_classifier(self):
      """
      Second test with the PyTorchClassifier.
      :return:
      """
      self.x_train_mnist = np.reshape(
          self.x_train_mnist, (self.x_train_mnist.shape[0], 1, 28, 28)
      ).astype(np.float32)
  
      # Create the trained classifier
      trained_classifier = get_image_classifier_pt()
  
      # Create the modified classifier
      transformed_classifier = get_image_classifier_pt(load_init=False)
  
      # Create defensive distillation transformer
      transformer = DefensiveDistillation(
          classifier=trained_classifier,
          batch_size=BATCH_SIZE,
          nb_epochs=NB_EPOCHS,
      )
  
      # Perform the transformation
      transformed_classifier = transformer(
          x=self.x_train_mnist,
          transformed_classifier=transformed_classifier,
      )
  
      # Compare the 2 outputs
      preds1 = trained_classifier.predict(
          x=self.x_train_mnist, batch_size=BATCH_SIZE
      )
  
      preds2 = transformed_classifier.predict(
          x=self.x_train_mnist, batch_size=BATCH_SIZE
      )
  
      preds1 = np.argmax(preds1, axis=1)
      preds2 = np.argmax(preds2, axis=1)
      acc = np.sum(preds1 == preds2) / len(preds1)
  
      self.assertGreater(acc, 0.5)
  
      ce = cross_entropy(preds1, preds2)
  
      self.assertLess(ce, 10)
      self.assertGreaterEqual(ce, 0)
  
      self.x_train_mnist = np.reshape(
          self.x_train_mnist, (self.x_train_mnist.shape[0], 28, 28, 1)
      ).astype(np.float32)
  
file_path: adversarial-robustness-toolbox/tests/defences/test_defensive_distillation.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  from art.defences.transformer.evasion import DefensiveDistillation
  from tests.utils import master_seed, TestBase
  from tests.utils import get_image_classifier_tf, get_image_classifier_pt, get_image_classifier_kr
  from tests.utils import get_tabular_classifier_tf, get_tabular_classifier_kr, get_tabular_classifier_pt
label_desc: Use image node_id 4 for calling the TestDefensiveDistillation obj's underlying member method code with example usage: obj.test_3_pytorch_classifier() without return types