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 Keras Classifier.
  :return:
docstr_tok: ["Test","with","a","Keras","Classifier",".",":","return",":"]
code: def test_3_kr(self):
      """
      Test with a Keras Classifier.
      :return:
      """
      tf.compat.v1.disable_eager_execution()
  
      # Get MNIST
      (x_train, y_train), (x_test, y_test) = self.mnist
  
      # Create a model from scratch
      model = Sequential()
      model.add(
          Conv2D(
              filters=4,
              kernel_size=(5, 5),
              strides=1,
              activation="relu",
              input_shape=(28, 28, 1),
          )
      )
      model.add(MaxPooling2D(pool_size=(2, 2)))
      model.add(
          Conv2D(
              filters=10,
              kernel_size=(5, 5),
              strides=1,
              activation="relu",
              input_shape=(23, 23, 4),
          )
      )
      model.add(MaxPooling2D(pool_size=(2, 2)))
      model.add(Flatten())
      model.add(Dense(100, activation="relu"))
      model.add(Dense(10, activation="softmax"))
  
      model.compile(
          loss=categorical_crossentropy,
          optimizer=Adam(learning_rate=0.01),
          metrics=["accuracy"],
      )
  
      classifier = KerasClassifier(
          model=model, clip_values=(0, 1), use_logits=False
      )
  
      # 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, 28, 28, 1)
  
      # 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 5 for calling the TestDeepPartitionEnsemble obj's underlying member method code with example usage: obj.test_3_kr() without return types