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 RPN losses.
  
  :return: Attack partial loss tensor.
docstr_tok: ["Create","the","partial","loss","tensor","of","this","attack","from","RPN","losses",".",":","return",":","Attack","partial","loss","tensor","."]
code: def _create_rpn_loss(self) -> "Tensor":
      """
      Create the partial loss tensor of this attack from RPN losses.
  
      :return: Attack partial loss tensor.
      """
      import tensorflow as tf
  
      # Get default graph
      default_graph = tf.get_default_graph()
  
      # Compute RPN losses
      rpn_iou_threshold = tf.placeholder(
          dtype=tf.float32, shape=[], name="rpn_iou_threshold"
      )
  
      # RPN background
      rpn_objectness_predictions_with_background = (
          self.estimator.predictions[
              "rpn_objectness_predictions_with_background"
          ]
      )
      rpn_objectness_predictions_with_background = tf.reshape(
          rpn_objectness_predictions_with_background,
          (-1, rpn_objectness_predictions_with_background.shape[-1]),
      )
      rpn_iou_tensor = default_graph.get_tensor_by_name(
          "Loss/RPNLoss/Compare/IOU/Select:0"
      )
      rpn_iou_tensor = tf.reshape(rpn_iou_tensor, (-1,))
      rpn_target = tf.cast(
          rpn_iou_tensor >= rpn_iou_threshold, dtype=tf.float32
      )  # pylint: disable=E1123,E1120
  
      # Compute RPN background loss
      rpn_background_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="rpn_background_weight"
      )
  
      rpn_background_logit = rpn_objectness_predictions_with_background[
          :, 0
      ]
      rpn_background_loss = rpn_background_logit * rpn_target
      rpn_background_loss = -1 * tf.reduce_sum(rpn_background_loss)
      weight_rpn_background_loss = tf.multiply(
          x=rpn_background_loss,
          y=rpn_background_weight,
          name="weight_rpn_background_loss",
      )
  
      # Compute RPN foreground loss
      rpn_foreground_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="rpn_foreground_weight"
      )
  
      rpn_foreground_logit = rpn_objectness_predictions_with_background[
          :, 1
      ]
      rpn_foreground_loss = rpn_foreground_logit * rpn_target
      rpn_foreground_loss = tf.reduce_sum(rpn_foreground_loss)
      weight_rpn_foreground_loss = tf.multiply(
          x=rpn_foreground_loss,
          y=rpn_foreground_weight,
          name="weight_rpn_foreground_loss",
      )
  
      # Compute RPN CW loss
      rpn_cw_weight = tf.placeholder(
          dtype=tf.float32, shape=[], name="rpn_cw_weight"
      )
      rpn_cw_confidence = tf.placeholder(
          dtype=tf.float32, shape=[], name="rpn_cw_confidence"
      )
  
      rpn_cw_loss = tf.nn.relu(
          rpn_foreground_logit
          - rpn_background_logit
          + rpn_cw_confidence
      )
      rpn_cw_loss = rpn_cw_loss * rpn_target
      rpn_cw_loss = tf.reduce_sum(rpn_cw_loss)
      weight_rpn_cw_loss = tf.multiply(
          x=rpn_cw_loss, y=rpn_cw_weight, name="weight_rpn_cw_loss"
      )
  
      # Compute partial loss
      partial_loss = tf.add_n(
          [
              weight_rpn_background_loss,
              weight_rpn_foreground_loss,
              weight_rpn_cw_loss,
          ],
          name="partial_rpn_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 9 for calling the ShapeShifter obj's underlying member method code with example usage: obj._create_rpn_loss() and returns: partial_loss