Esempio n. 1
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((str(level), 2**(level + 1)) for level in levels)
     strides = dict((str(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())
Esempio n. 2
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)
Esempio n. 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[str(level)] = stride
        anchor_sizes[str(level)] = anchor_size * stride
    anchor_gen = anchor_generator.AnchorGenerator(anchor_sizes=anchor_sizes,
                                                  scales=scales,
                                                  aspect_ratios=aspect_ratios,
                                                  strides=strides)
    return anchor_gen