class_docstr: Implementation of Sleeper Agent Attack
  
  | Paper link: https://arxiv.org/pdf/2106.08970.pdf
class_docstr_tok: ["Implementation","of","Sleeper","Agent","Attack","|","Paper","link",":","https",":","\/\/arxiv.org\/pdf\/2106.08970.pdf"]
docstr: Applies retraining to substitute model
  
  :param poisoned_samples: poisoned array.
  :param x_train: clean training data.
  :param y_train: labels for training data.
  :param x_test: clean test data.
  :param y_test: labels for test data.
docstr_tok: ["Applies","retraining","to","substitute","model",":","param","poisoned_samples",":","poisoned","array",".",":","param","x_train",":","clean","training","data",".",":","param","y_train",":","labels","for","training","data",".",":","param","x_test",":","clean","test","data",".",":","param","y_test",":","labels","for","test","data","."]
code: def _model_retraining(
      self,
      poisoned_samples: np.ndarray,
      x_train: np.ndarray,
      y_train: np.ndarray,
      x_test: np.ndarray,
      y_test: np.ndarray,
  ):
      """
      Applies retraining to substitute model
  
      :param poisoned_samples: poisoned array.
      :param x_train: clean training data.
      :param y_train: labels for training data.
      :param x_test: clean test data.
      :param y_test: labels for test data.
      """
      if isinstance(
          self.substitute_classifier.preprocessing,
          (
              StandardisationMeanStdPyTorch,
              StandardisationMeanStdTensorFlow,
          ),
      ):
          x_train_un = np.copy(x_train)
          x_train_un[
              self.indices_target[self.indices_poison]
          ] = poisoned_samples
          x_train_un = (
              x_train_un * self.substitute_classifier.preprocessing.std
          )
          x_train_un += self.substitute_classifier.preprocessing.mean
  
      if isinstance(self.substitute_classifier, PyTorchClassifier):
          check_train = self.substitute_classifier.model.training
          model_pt = self._create_model(
              x_train_un,
              y_train,
              x_test,
              y_test,
              batch_size=self.retrain_batch_size,
              epochs=self.model_retraining_epoch,
          )
          self.substitute_classifier = model_pt
          self.substitute_classifier.model.training = check_train
  
      elif isinstance(
          self.substitute_classifier, TensorFlowV2Classifier
      ):
          check_train = self.substitute_classifier.model.trainable
          model_tf = self._create_model(
              x_train_un,
              y_train,
              x_test,
              y_test,
              batch_size=self.retrain_batch_size,
              epochs=self.model_retraining_epoch,
          )
  
          self.substitute_classifier = model_tf
          self.substitute_classifier.model.trainable = check_train
  
      else:
          raise NotImplementedError(
              "SleeperAgentAttack is currently implemented only for PyTorch and TensorFlowV2."
          )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Tuple, TYPE_CHECKING, List, Union
  import random
  import numpy
  from tqdm.auto import trange
  from art.attacks.poisoning.gradient_matching_attack import GradientMatchingAttack
  from art.estimators.classification.pytorch import PyTorchClassifier
  from art.estimators.classification import TensorFlowV2Classifier
  from art.preprocessing.standardisation_mean_std.pytorch import StandardisationMeanStdPyTorch
  from art.preprocessing.standardisation_mean_std.tensorflow import StandardisationMeanStdTensorFlow
label_desc: Use image node_id 5 for calling the SleeperAgentAttack obj's underlying member method code with example usage: obj._model_retraining(poisoned_samples, x_train, y_train, x_test, y_test) without return types