NMS 非极大值抑制 import tensorflow as tf import numpy as np rects=np.asarray([[1,2,3,4],[1,3,3,4], [1,3,4,4],[1,1,4,4],[1,1,3,4]],dtype=np.float32) scores=np.asarray([0.4,0.5,0.72,0.9,0.45], dtype=np.float32) with tf.Session() as sess: nms = tf.image.non_max_suppression(rects, scores, max_output_size=5, iou_threshold=0.5) print(sess.run(nms)) selected_boxes = sess.run(tf.gather(rects, nms)) print(selected_boxes) return [3 2 0] [[1. 1. 4. 4.] [1. 3. 4. 4.] [1. 2. 3. 4.]] 解释 # 返回极大值抑制后的indices tf.image.non_max_suppression() # 根据返回的序列,得到最后返回的结果 tf.gather(rects, nms)