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)
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())