docstr: Tests about the anchors generated by the FasterRCNN
docstr_tok: ["Tests","about","the","anchors","generated","by","the","FasterRCNN"]
code: def testAnchors(self):
      """
      Tests about the anchors generated by the FasterRCNN
      """
      results = self._run_network()
  
      # Check we get anchors clipped to the image.
      self.assertAllEqual(
          clip_boxes(results["all_anchors"], self.image_size),
          results["all_anchors"],
      )
  
      feature_map = np.random.randint(
          low=0, high=255, size=(1, 32, 32, 1)
      )
      config = self.config
      config.model.anchors.base_size = 16
      config.model.anchors.scales = [0.5, 1, 2]
      config.model.anchors.ratios = [0.5, 1, 2]
      config.model.anchors.stride = 1  # image is 32 x 32
  
      anchors = self._gen_anchors(config, feature_map.shape)
  
      # Check the amount of anchors generated is correct:
      # 9216 = 32^2 * config.anchor.scales * config.anchor.ratios = 1024 * 9
      self.assertEqual(anchors.shape, (9216, 4))
  
      anchor_widths = anchors[:, 2] - anchors[:, 0]
      anchor_heights = anchors[:, 3] - anchors[:, 1]
  
      # Since we are using equal scales and ratios, the set of unique heights
      # and widths must be the same.
      self.assertAllEqual(
          np.unique(anchor_widths), np.unique(anchor_heights)
      )
  
      anchor_areas = anchor_widths * anchor_heights
  
      # We have 9 possible anchors areas, minus 3 repeated ones. 6 unique.
      self.assertAllEqual(np.unique(anchor_areas).shape[0], 6)
  
      # Check the anchors cover all the image.
      # TODO: Check with values calculated from config.
      self.assertEqual(np.min(anchors[:, 0]), -22)
      self.assertEqual(np.max(anchors[:, 0]), 29)
  
      self.assertEqual(np.min(anchors[:, 1]), -22)
      self.assertEqual(np.max(anchors[:, 1]), 29)
  
      self.assertEqual(np.min(anchors[:, 2]), 2)
      self.assertEqual(np.max(anchors[:, 2]), 53)
  
      self.assertEqual(np.min(anchors[:, 3]), 2)
      self.assertEqual(np.max(anchors[:, 3]), 53)
  
      stride = config.model.anchors.stride
      # Check values are sequential.
      self._assert_sequential_values(anchors[:, 0], stride)
      self._assert_sequential_values(anchors[:, 1], stride)
      self._assert_sequential_values(anchors[:, 2], stride)
      self._assert_sequential_values(anchors[:, 3], stride)
  
file_path: luminoth/luminoth/models/fasterrcnn/fasterrcnn_test.py
imports: import numpy
  import tensorflow
  from easydict import EasyDict
  from luminoth.models.fasterrcnn import FasterRCNN
  from luminoth.utils.bbox_transform import clip_boxes
label_desc: Use image node_id 6 for calling the FasterRCNNNetworkTest obj's underlying member method code with example usage: obj.testAnchors() without return types