class_docstr: This class tests the deep partition ensemble classifier.
class_docstr_tok: ["This","class","tests","the","deep","partition","ensemble","classifier","."]
docstr: Test with a PyTorch Classifier.
  :return:
docstr_tok: ["Test","with","a","PyTorch","Classifier",".",":","return",":"]
code: def test_2_pt(self):
      """
      Test with a PyTorch Classifier.
      :return:
      """
  
      # Get MNIST
      (x_train, y_train), (x_test, y_test) = self.mnist
  
      x_train = np.transpose(x_train, (0, 3, 1, 2)).astype(np.float32)
      x_test = np.transpose(x_test, (0, 3, 1, 2)).astype(np.float32)
  
      # Create a model from scratch
      class PyTorchModel(nn.Module):
          def __init__(self):
              super(PyTorchModel, self).__init__()
              self.conv_1 = nn.Conv2d(
                  in_channels=1, out_channels=4, kernel_size=5, stride=1
              )
              self.conv_2 = nn.Conv2d(
                  in_channels=4,
                  out_channels=10,
                  kernel_size=5,
                  stride=1,
              )
              self.fc_1 = nn.Linear(
                  in_features=4 * 4 * 10, out_features=100
              )
              self.fc_2 = nn.Linear(in_features=100, out_features=10)
  
          def forward(self, x):
              x = F.relu(self.conv_1(x))
              x = F.max_pool2d(x, 2, 2)
              x = F.relu(self.conv_2(x))
              x = F.max_pool2d(x, 2, 2)
              x = x.view(-1, 4 * 4 * 10)
              x = F.relu(self.fc_1(x))
              x = self.fc_2(x)
              return x
  
      # Step 2a: Define the loss function and the optimizer
      model = PyTorchModel()
      criterion = nn.CrossEntropyLoss()
      optimizer = optim.Adam(model.parameters(), lr=0.01)
  
      # Step 3: Create the ART classifier
  
      classifier = PyTorchClassifier(
          model=model,
          clip_values=(0, 1),
          loss=criterion,
          optimizer=optimizer,
          input_shape=(1, 28, 28),
          nb_classes=10,
      )
  
      # Initialize DPA Classifier
      dpa = DeepPartitionEnsemble(
          classifiers=classifier,
          ensemble_size=ENSEMBLE_SIZE,
          channels_first=classifier.channels_first,
          clip_values=classifier.clip_values,
          preprocessing_defences=classifier.preprocessing_defences,
          postprocessing_defences=classifier.postprocessing_defences,
          preprocessing=classifier.preprocessing,
      )
  
      # Check basic functionality of DPA Classifier
      # check predict
      y_test_dpa = dpa.predict(x=x_test)
      self.assertEqual(y_test_dpa.shape, y_test.shape)
      self.assertTrue(
          (
              np.sum(y_test_dpa, axis=1)
              <= ENSEMBLE_SIZE * np.ones((NB_TEST,))
          ).all()
      )
  
      # loss gradient
      grad = dpa.loss_gradient(x=x_test, y=y_test, sampling=True)
      assert grad.shape == (10, 1, 28, 28)
  
      # fit
      dpa.fit(x=x_train, y=y_train)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import unittest
  import numpy
  import tensorflow
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D
  from tensorflow.keras.losses import categorical_crossentropy
  from tensorflow.keras.optimizers.legacy import Adam
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from art.utils import load_dataset
  from art.estimators.classification.deep_partition_ensemble import DeepPartitionEnsemble
  from art.estimators.classification import TensorFlowV2Classifier, PyTorchClassifier, KerasClassifier
  from tests.utils import master_seed
label_desc: Use image node_id 4 for calling the TestDeepPartitionEnsemble obj's underlying member method code with example usage: obj.test_2_pt() and returns: x