class_docstr: Implementation of the ShapeShifter attack. This is a robust physical adversarial attack on Faster R-CNN object
  detector and is developed in TensorFlow.
  
  | Paper link: https://arxiv.org/abs/1804.05810
class_docstr_tok: ["Implementation","of","the","ShapeShifter","attack",".","This","is","a","robust","physical","adversarial","attack","on","Faster","R-CNN","object","detector","and","is","developed","in","TensorFlow",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1804.05810"]
docstr: Create the partial loss tensor of this attack from box losses.
  
  :return: Attack partial loss tensor.
docstr_tok: ["Create","the","partial","loss","tensor","of","this","attack","from","box","losses",".",":","return",":","Attack","partial","loss","tensor","."]
code: def _create_box_loss(self) -> "Tensor":
      """
      Create the partial loss tensor of this attack from box losses.
  
      :return: Attack partial loss tensor.
      """
      import tensorflow as tf
  
      # Get default graph
      default_graph = tf.get_default_graph()
  
      # Compute box losses
      target_class_phd = tf.placeholder(
          dtype=tf.int32, shape=[], name="target_class_phd"
      )
      victim_class_phd = tf.placeholder(
          dtype=tf.int32, shape=[], name="victim_class_phd"
      )
      box_iou_threshold = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_iou_threshold"
      )
  
      # Ignore background class
      class_predictions_with_background = self.estimator.predictions[
          "class_predictions_with_background"
      ]
      class_predictions_with_background = (
          class_predictions_with_background[:, 1:]
      )
  
      # Convert to 1-hot
      # pylint: disable=E1120
      target_class_one_hot = tf.one_hot(
          [target_class_phd - 1],
          class_predictions_with_background.shape[-1],
      )
      victim_class_one_hot = tf.one_hot(
          [victim_class_phd - 1],
          class_predictions_with_background.shape[-1],
      )
  
      box_iou_tensor = default_graph.get_tensor_by_name(
          "Loss/BoxClassifierLoss/Compare/IOU/Select:0"
      )
      box_iou_tensor = tf.reshape(box_iou_tensor, (-1,))
      box_target = tf.cast(
          box_iou_tensor >= box_iou_threshold, dtype=tf.float32
      )  # pylint: disable=E1123
  
      # Compute box target loss
      box_target_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_target_weight"
      )
  
      box_target_logit = class_predictions_with_background[
          :, target_class_phd - 1
      ]
      box_target_loss = box_target_logit * box_target
      box_target_loss = -1 * tf.reduce_sum(box_target_loss)
      weight_box_target_loss = tf.multiply(
          x=box_target_loss,
          y=box_target_weight,
          name="weight_box_target_loss",
      )
  
      # Compute box victim loss
      box_victim_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_victim_weight"
      )
  
      box_victim_logit = class_predictions_with_background[
          :, victim_class_phd - 1
      ]
      box_victim_loss = box_victim_logit * box_target
      box_victim_loss = tf.reduce_sum(box_victim_loss)
      weight_box_victim_loss = tf.multiply(
          x=box_victim_loss,
          y=box_victim_weight,
          name="weight_box_victim_loss",
      )
  
      # Compute box target CW loss
      box_target_cw_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_target_cw_weight"
      )
      box_target_cw_confidence = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_target_cw_confidence"
      )
  
      box_nontarget_logit = tf.reduce_max(
          class_predictions_with_background * (1 - target_class_one_hot)
          - 10000 * target_class_one_hot,
          axis=-1,
      )
      box_target_cw_loss = tf.nn.relu(
          box_nontarget_logit
          - box_target_logit
          + box_target_cw_confidence
      )
      box_target_cw_loss = box_target_cw_loss * box_target
      box_target_cw_loss = tf.reduce_sum(box_target_cw_loss)
      weight_box_target_cw_loss = tf.multiply(
          x=box_target_cw_loss,
          y=box_target_cw_weight,
          name="weight_box_target_cw_loss",
      )
  
      # Compute box victim CW loss
      box_victim_cw_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_victim_cw_weight"
      )
      box_victim_cw_confidence = tf.placeholder(
          dtype=tf.float32, shape=[], name="box_victim_cw_confidence"
      )
  
      box_nonvictim_logit = tf.reduce_max(
          class_predictions_with_background * (1 - victim_class_one_hot)
          - 10000 * victim_class_one_hot,
          axis=-1,
      )
      box_victim_cw_loss = tf.nn.relu(
          box_victim_logit
          - box_nonvictim_logit
          + box_victim_cw_confidence
      )
      box_victim_cw_loss = box_victim_cw_loss * box_target
      box_victim_cw_loss = tf.reduce_sum(box_victim_cw_loss)
      weight_box_victim_cw_loss = tf.multiply(
          x=box_victim_cw_loss,
          y=box_victim_cw_weight,
          name="weight_box_victim_cw_loss",
      )
  
      # Compute partial loss
      partial_loss = tf.add_n(
          [
              weight_box_target_loss,
              weight_box_victim_loss,
              weight_box_target_cw_loss,
              weight_box_victim_cw_loss,
          ],
          name="partial_box_loss",
      )
  
      return partial_loss
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/shapeshifter.py
imports: import logging
  from typing import List, Dict, Optional, Tuple, TYPE_CHECKING
  import numpy
  from art.attacks.attack import EvasionAttack
  from art.estimators.object_detection.tensorflow_faster_rcnn import TensorFlowFasterRCNN
label_desc: Use image node_id 8 for calling the ShapeShifter obj's underlying member method code with example usage: obj._create_box_loss() and returns: partial_loss