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: Select indices of poisoned samples
  
  :x_trigger: Samples to be used for trigger.
  :return tensor with applied trigger patches.
docstr_tok: ["Select","indices","of","poisoned","samples",":","x_trigger",":","Samples","to","be","used","for","trigger",".",":","return","tensor","with","applied","trigger","patches","."]
code: def _apply_trigger_patch(self, x_trigger: np.ndarray) -> np.ndarray:
      """
      Select indices of poisoned samples
  
      :x_trigger: Samples to be used for trigger.
      :return tensor with applied trigger patches.
      """
      patch_size = self.patch.shape[1]
      if self.patching_strategy == "fixed":
          if self.estimator.channels_first:
              x_trigger[:, :, -patch_size:, -patch_size:] = self.patch
          else:
              x_trigger[:, -patch_size:, -patch_size:, :] = self.patch
      else:
          for x in x_trigger:
              if self.estimator.channels_first:
                  x_cord = random.randrange(
                      0, x.shape[1] - self.patch.shape[1] + 1
                  )
                  y_cord = random.randrange(
                      0, x.shape[2] - self.patch.shape[2] + 1
                  )
                  x[
                      :,
                      x_cord : x_cord + patch_size,
                      y_cord : y_cord + patch_size,
                  ] = self.patch
              else:
                  x_cord = random.randrange(
                      0, x.shape[0] - self.patch.shape[0] + 1
                  )
                  y_cord = random.randrange(
                      0, x.shape[1] - self.patch.shape[1] + 1
                  )
                  x[
                      x_cord : x_cord + patch_size,
                      y_cord : y_cord + patch_size,
                      :,
                  ] = self.patch
  
      return x_trigger
  
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 8 for calling the SleeperAgentAttack obj's underlying member method code with example usage: obj._apply_trigger_patch(x_trigger) and returns: x_trigger