class_docstr: This class implements a model-specific object detector using Faster-RCNN and TensorFlow.
class_docstr_tok: ["This","class","implements","a","model-specific","object","detector","using","Faster-RCNN","and","TensorFlow","."]
docstr: Initialization of an instance TensorFlowFasterRCNN.
  
  :param images: Input samples of shape (nb_samples, height, width, nb_channels).
  :param model: A TensorFlow Faster-RCNN model. The output that can be computed from the model includes a tuple
                of (predictions, losses, detections):
  
                  - predictions: a dictionary holding "raw" prediction tensors.
                  - losses: a dictionary mapping loss keys (`Loss/RPNLoss/localization_loss`,
                            `Loss/RPNLoss/objectness_loss`, `Loss/BoxClassifierLoss/localization_loss`,
                            `Loss/BoxClassifierLoss/classification_loss`) to scalar tensors representing
                            corresponding loss values.
                  - detections: a dictionary containing final detection results.
  :param filename: Filename of the detection model without filename extension.
  :param url: URL to download archive of detection model including filename extension.
  :param sess: Computation session.
  :param is_training: A boolean indicating whether the training version of the computation graph should be
                      constructed.
  :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
                      maximum values allowed for input image features. If floats are provided, these will be
                      used as the range of all features. If arrays are provided, each value will be considered
                      the bound for a feature, thus the shape of clip values needs to match the total number
                      of features.
  :param channels_first: Set channels first or last.
  :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
  :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
  :param preprocessing: Tuple of the form `(subtractor, divider)` of floats or `np.ndarray` of values to be
                        used for data preprocessing. The first value will be subtracted from the input. The
                        input will then be divided by the second one.
  :param attack_losses: Tuple of any combination of strings of the following loss components:
                        `first_stage_localization_loss`, `first_stage_objectness_loss`,
                        `second_stage_localization_loss`, `second_stage_classification_loss`.
docstr_tok: ["Initialization","of","an","instance","TensorFlowFasterRCNN",".",":","param","images",":","Input","samples","of","shape","(","nb_samples",",","height",",","width",",","nb_channels",")",".",":","param","model",":","A","TensorFlow","Faster-RCNN","model",".","The","output","that","can","be","computed","from","the","model","includes","a","tuple","of","(","predictions",",","losses",",","detections",")",":","-","predictions",":","a","dictionary","holding","``","raw","''","prediction","tensors",".","-","losses",":","a","dictionary","mapping","loss","keys","(","`","Loss\/RPNLoss\/localization_loss","`",",","`","Loss\/RPNLoss\/objectness_loss","`",",","`","Loss\/BoxClassifierLoss\/localization_loss","`",",","`","Loss\/BoxClassifierLoss\/classification_loss","`",")","to","scalar","tensors","representing","corresponding","loss","values",".","-","detections",":","a","dictionary","containing","final","detection","results",".",":","param","filename",":","Filename","of","the","detection","model","without","filename","extension",".",":","param","url",":","URL","to","download","archive","of","detection","model","including","filename","extension",".",":","param","sess",":","Computation","session",".",":","param","is_training",":","A","boolean","indicating","whether","the","training","version","of","the","computation","graph","should","be","constructed",".",":","param","clip_values",":","Tuple","of","the","form","`","(","min",",","max",")","`","of","floats","or","`","np.ndarray","`","representing","the","minimum","and","maximum","values","allowed","for","input","image","features",".","If","floats","are","provided",",","these","will","be","used","as","the","range","of","all","features",".","If","arrays","are","provided",",","each","value","will","be","considered","the","bound","for","a","feature",",","thus","the","shape","of","clip","values","needs","to","match","the","total","number","of","features",".",":","param","channels_first",":","Set","channels","first","or","last",".",":","param","preprocessing_defences",":","Preprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","postprocessing_defences",":","Postprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","preprocessing",":","Tuple","of","the","form","`","(","subtractor",",","divider",")","`","of","floats","or","`","np.ndarray","`","of","values","to","be","used","for","data","preprocessing",".","The","first","value","will","be","subtracted","from","the","input",".","The","input","will","then","be","divided","by","the","second","one",".",":","param","attack_losses",":","Tuple","of","any","combination","of","strings","of","the","following","loss","components",":","`","first_stage_localization_loss","`",",","`","first_stage_objectness_loss","`",",","`","second_stage_localization_loss","`",",","`","second_stage_classification_loss","`","."]
code: def __init__(
      self,
      images: "tf.Tensor",
      model: Optional["FasterRCNNMetaArch"] = None,
      filename: Optional[str] = None,
      url: Optional[str] = None,
      sess: Optional["Session"] = None,
      is_training: bool = False,
      clip_values: Optional["CLIP_VALUES_TYPE"] = None,
      channels_first: bool = False,
      preprocessing_defences: Union[
          "Preprocessor", List["Preprocessor"], None
      ] = None,
      postprocessing_defences: Union[
          "Postprocessor", List["Postprocessor"], None
      ] = None,
      preprocessing: "PREPROCESSING_TYPE" = (0.0, 1.0),
      attack_losses: Tuple[str, ...] = (
          "Loss/RPNLoss/localization_loss",
          "Loss/RPNLoss/objectness_loss",
          "Loss/BoxClassifierLoss/localization_loss",
          "Loss/BoxClassifierLoss/classification_loss",
      ),
  ):
      """
      Initialization of an instance TensorFlowFasterRCNN.
  
      :param images: Input samples of shape (nb_samples, height, width, nb_channels).
      :param model: A TensorFlow Faster-RCNN model. The output that can be computed from the model includes a tuple
                    of (predictions, losses, detections):
  
                      - predictions: a dictionary holding "raw" prediction tensors.
                      - losses: a dictionary mapping loss keys (`Loss/RPNLoss/localization_loss`,
                                `Loss/RPNLoss/objectness_loss`, `Loss/BoxClassifierLoss/localization_loss`,
                                `Loss/BoxClassifierLoss/classification_loss`) to scalar tensors representing
                                corresponding loss values.
                      - detections: a dictionary containing final detection results.
      :param filename: Filename of the detection model without filename extension.
      :param url: URL to download archive of detection model including filename extension.
      :param sess: Computation session.
      :param is_training: A boolean indicating whether the training version of the computation graph should be
                          constructed.
      :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
                          maximum values allowed for input image features. If floats are provided, these will be
                          used as the range of all features. If arrays are provided, each value will be considered
                          the bound for a feature, thus the shape of clip values needs to match the total number
                          of features.
      :param channels_first: Set channels first or last.
      :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
      :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
      :param preprocessing: Tuple of the form `(subtractor, divider)` of floats or `np.ndarray` of values to be
                            used for data preprocessing. The first value will be subtracted from the input. The
                            input will then be divided by the second one.
      :param attack_losses: Tuple of any combination of strings of the following loss components:
                            `first_stage_localization_loss`, `first_stage_objectness_loss`,
                            `second_stage_localization_loss`, `second_stage_classification_loss`.
      """
      import tensorflow.compat.v1 as tf
  
      # Super initialization
      super().__init__(
          model=model,
          clip_values=clip_values,
          channels_first=channels_first,
          preprocessing_defences=preprocessing_defences,
          postprocessing_defences=postprocessing_defences,
          preprocessing=preprocessing,
      )
  
      # Check clip values
      if self.clip_values is not None:
          if not np.all(self.clip_values[0] == 0):
              raise ValueError(
                  "This classifier requires normalized input images with clip_vales=(0, 1)."
              )
          if not np.all(self.clip_values[1] == 1):  # pragma: no cover
              raise ValueError(
                  "This classifier requires normalized input images with clip_vales=(0, 1)."
              )
  
      # Check preprocessing and postprocessing defences
      if self.preprocessing_defences is not None:
          raise ValueError(
              "This estimator does not support `preprocessing_defences`."
          )
      if self.postprocessing_defences is not None:
          raise ValueError(
              "This estimator does not support `postprocessing_defences`."
          )
  
      # Create placeholders for groundtruth boxes
      self._groundtruth_boxes_list: List["tf.Tensor"]
      self._groundtruth_boxes_list = [
          tf.placeholder(
              dtype=tf.float32,
              shape=(None, 4),
              name=f"groundtruth_boxes_{i}",
          )
          for i in range(images.shape[0])
      ]
  
      # Create placeholders for groundtruth classes
      self._groundtruth_classes_list: List["tf.Tensor"]
      self._groundtruth_classes_list = [
          tf.placeholder(
              dtype=tf.int32,
              shape=(None,),
              name=f"groundtruth_classes_{i}",
          )
          for i in range(images.shape[0])
      ]
  
      # Create placeholders for groundtruth weights
      self._groundtruth_weights_list: List["tf.Tensor"]
      self._groundtruth_weights_list = [
          tf.placeholder(
              dtype=tf.float32,
              shape=(None,),
              name=f"groundtruth_weights_{i}",
          )
          for i in range(images.shape[0])
      ]
  
      # Load model
      if model is None:
          # If model is None, then we need to have parameters filename and url to download, extract and load the
          # object detection model
          if filename is None or url is None:
              filename, url = (
                  "faster_rcnn_inception_v2_coco_2017_11_08",
                  "http://download.tensorflow.org/models/object_detection/"
                  "faster_rcnn_inception_v2_coco_2017_11_08.tar.gz",
              )
  
          (
              self._model,
              self._predictions,
              self._losses,
              self._detections,
          ) = self._load_model(
              images=images,
              filename=filename,
              url=url,
              obj_detection_model=None,
              is_training=is_training,
              groundtruth_boxes_list=self._groundtruth_boxes_list,
              groundtruth_classes_list=self._groundtruth_classes_list,
              groundtruth_weights_list=self._groundtruth_weights_list,
          )
  
      else:
          (
              self._model,
              self._predictions,
              self._losses,
              self._detections,
          ) = self._load_model(
              images=images,
              filename=None,
              url=None,
              obj_detection_model=model,
              is_training=is_training,
              groundtruth_boxes_list=self._groundtruth_boxes_list,
              groundtruth_classes_list=self._groundtruth_classes_list,
              groundtruth_weights_list=self._groundtruth_weights_list,
          )
  
      # Save new attributes
      self._input_shape = images.shape.as_list()[1:]
      self.is_training: bool = is_training
      self.images: Optional["tf.Tensor"] = images
      self.attack_losses: Tuple[str, ...] = attack_losses
  
      # Assign session
      if sess is None:
          logger.warning(
              "A session cannot be None, create a new session."
          )
          self._sess = tf.Session()
      else:  # pragma: no cover
          self._sess = sess
  
      # Initialize variables
      self._sess.run(tf.global_variables_initializer())
      self._sess.run(tf.local_variables_initializer())
  
imports: import logging
  from typing import List, Dict, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from art.estimators.object_detection.object_detector import ObjectDetectorMixin
  from art.estimators.tensorflow import TensorFlowEstimator
  from art.utils import get_file
  from art import config
label_desc: Use image node_id 1 to create a new TensorFlowFasterRCNN object from inherited base classes: ObjectDetectorMixin, TensorFlowEstimator with example: obj = TensorFlowFasterRCNN(images, model, filename, url, sess, is_training, clip_values, channels_first, preprocessing_defences, postprocessing_defences, preprocessing, attack_losses)