def test_select_from_ten_identical_boxes(self): corners = tf.constant(10 * [[0, 0, 1, 1]], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant(10 * [.9])) iou_thresh = .5 max_output_size = 3 exp_nms = [[0, 0, 1, 1]] nms = box_list_ops.non_max_suppression(boxes, iou_thresh, max_output_size) with self.test_session() as sess: nms_output = sess.run(nms.get()) self.assertAllClose(nms_output, exp_nms)
def test_select_at_most_thirty_boxes_from_three_clusters(self): corners = tf.constant( [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant([.9, .75, .6, .95, .5, .3])) iou_thresh = .5 max_output_size = 30 exp_nms = [[0, 10, 1, 11], [0, 0, 1, 1], [0, 100, 1, 101]] nms = box_list_ops.non_max_suppression(boxes, iou_thresh, max_output_size) with self.test_session() as sess: nms_output = sess.run(nms.get()) self.assertAllClose(nms_output, exp_nms)
def test_with_invalid_scores_field(self): corners = tf.constant( [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9], [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]], tf.float32) boxes = box_list.BoxList(corners) boxes.add_field('scores', tf.constant([.9, .75, .6, .95, .5])) iou_thresh = .5 max_output_size = 3 nms = box_list_ops.non_max_suppression(boxes, iou_thresh, max_output_size) with self.test_session() as sess: with self.assertRaisesWithPredicateMatch( errors.InvalidArgumentError, 'scores has incompatible shape'): sess.run(nms.get())