class_docstr: Faster RCNN Network module
  
  Builds the Faster RCNN network architecture using different submodules.
  Calculates the total loss of the model based on the different losses by
  each of the submodules.
  
  It is also responsible for building the anchor reference which is used in
  graph for generating the dynamic anchors.
class_docstr_tok: ["Faster","RCNN","Network","module","Builds","the","Faster","RCNN","network","architecture","using","different","submodules",".","Calculates","the","total","loss","of","the","model","based","on","the","different","losses","by","each","of","the","submodules",".","It","is","also","responsible","for","building","the","anchor","reference","which","is","used","in","graph","for","generating","the","dynamic","anchors","."]
docstr: Generate anchor for an image.
  
  Using the feature map, the output of the pretrained network for an
  image, and the anchor_reference generated using the anchor config
  values. We generate a list of anchors.
  
  Anchors are just fixed bounding boxes of different ratios and sizes
  that are uniformly generated throught the image.
  
  Args:
      feature_map_shape: Shape of the convolutional feature map used as
          input for the RPN. Should be (batch, height, width, depth).
  
  Returns:
      all_anchors: A flattened Tensor with all the anchors of shape
          `(num_anchors_per_points * feature_width * feature_height, 4)`
          using the (x1, y1, x2, y2) convention.
docstr_tok: ["Generate","anchor","for","an","image",".","Using","the","feature","map",",","the","output","of","the","pretrained","network","for","an","image",",","and","the","anchor_reference","generated","using","the","anchor","config","values",".","We","generate","a","list","of","anchors",".","Anchors","are","just","fixed","bounding","boxes","of","different","ratios","and","sizes","that","are","uniformly","generated","throught","the","image",".","Args",":","feature_map_shape",":","Shape","of","the","convolutional","feature","map","used","as","input","for","the","RPN",".","Should","be","(","batch",",","height",",","width",",","depth",")",".","Returns",":","all_anchors",":","A","flattened","Tensor","with","all","the","anchors","of","shape","`","(","num_anchors_per_points","*","feature_width","*","feature_height",",","4",")","`","using","the","(","x1",",","y1",",","x2",",","y2",")","convention","."]
code: def _generate_anchors(self, feature_map_shape):
      """Generate anchor for an image.
  
      Using the feature map, the output of the pretrained network for an
      image, and the anchor_reference generated using the anchor config
      values. We generate a list of anchors.
  
      Anchors are just fixed bounding boxes of different ratios and sizes
      that are uniformly generated throught the image.
  
      Args:
          feature_map_shape: Shape of the convolutional feature map used as
              input for the RPN. Should be (batch, height, width, depth).
  
      Returns:
          all_anchors: A flattened Tensor with all the anchors of shape
              `(num_anchors_per_points * feature_width * feature_height, 4)`
              using the (x1, y1, x2, y2) convention.
      """
      with tf.variable_scope("generate_anchors"):
          grid_width = feature_map_shape[2]  # width
          grid_height = feature_map_shape[1]  # height
          shift_x = tf.range(grid_width) * self._anchor_stride
          shift_y = tf.range(grid_height) * self._anchor_stride
          shift_x, shift_y = tf.meshgrid(shift_x, shift_y)
  
          shift_x = tf.reshape(shift_x, [-1])
          shift_y = tf.reshape(shift_y, [-1])
  
          shifts = tf.stack(
              [shift_x, shift_y, shift_x, shift_y], axis=0
          )
  
          shifts = tf.transpose(shifts)
          # Shifts now is a (H x W, 4) Tensor
  
          # Expand dims to use broadcasting sum.
          all_anchors = np.expand_dims(
              self._anchor_reference, axis=0
          ) + tf.expand_dims(shifts, axis=1)
  
          # Flatten
          all_anchors = tf.reshape(all_anchors, (-1, 4))
          return all_anchors
  
file_path: luminoth/luminoth/models/fasterrcnn/fasterrcnn.py
imports: import numpy
  import sonnet
  import tensorflow
  from luminoth.models.fasterrcnn.rcnn import RCNN
  from luminoth.models.fasterrcnn.rpn import RPN
  from luminoth.models.base import TruncatedBaseNetwork
  from luminoth.utils.anchors import generate_anchors_reference
  from luminoth.utils.vars import VAR_LOG_LEVELS, variable_summaries
label_desc: Use image node_id 4 for calling the FasterRCNN obj's underlying member method code with example usage: obj._generate_anchors(feature_map_shape) and returns: all_anchors