示例#1
0
 def testAnchorGeneration(self, min_level, max_level, aspect_ratios,
                          expected_boxes):
   image_size = [64, 64]
   levels = range(min_level, max_level + 1)
   anchor_sizes = [2**(level + 1) for level in levels]
   strides = [2**level for level in levels]
   anchor_gen = anchor_generator.AnchorGenerator(
       anchor_sizes=anchor_sizes,
       scales=[1.],
       aspect_ratios=aspect_ratios,
       strides=strides)
   anchors = anchor_gen(image_size)
   anchors = [tf.reshape(anchor, [-1, 4]) for anchor in anchors]
   anchors = tf.concat(anchors, axis=0).numpy()
   self.assertAllClose(expected_boxes, anchors)
示例#2
0
 def testAnchorGenerationDict(self, min_level, max_level, aspect_ratios,
                              expected_boxes):
   image_size = [64, 64]
   levels = range(min_level, max_level + 1)
   anchor_sizes = dict((level, 2**(level + 1)) for level in levels)
   strides = dict((level, 2**level) for level in levels)
   anchor_gen = anchor_generator.AnchorGenerator(
       anchor_sizes=anchor_sizes,
       scales=[1.],
       aspect_ratios=aspect_ratios,
       strides=strides,
       clip_boxes=False)
   anchors = anchor_gen(image_size)
   for k in expected_boxes.keys():
     self.assertAllClose(expected_boxes[k], anchors[k].numpy())
示例#3
0
def build_anchor_generator(min_level, max_level, num_scales, aspect_ratios,
                           anchor_size):
    """Build anchor generator from levels."""
    anchor_sizes = collections.OrderedDict()
    strides = collections.OrderedDict()
    scales = []
    for scale in range(num_scales):
        scales.append(2**(scale / float(num_scales)))
    for level in range(min_level, max_level + 1):
        stride = 2**level
        strides[level] = stride
        anchor_sizes[level] = anchor_size * stride
    anchor_gen = anchor_generator.AnchorGenerator(anchor_sizes=anchor_sizes,
                                                  scales=scales,
                                                  aspect_ratios=aspect_ratios,
                                                  strides=strides)
    return anchor_gen