def get_predictions(self, score_threshold=0.1, iou_threshold=0.6, max_boxes=20): """Postprocess outputs of the network. Returns: boxes: a float tensor with shape [batch_size, N, 4]. scores: a float tensor with shape [batch_size, N]. num_boxes: an int tensor with shape [batch_size], it represents the number of detections on an image. where N = max_boxes. """ # 良心活:输入的图像有rescale操作,得到的预测结果也有对应的还原操作 with tf.name_scope('postprocessing'): boxes = batch_decode(self.box_encodings, self.anchors) # if the images were padded we need to rescale predicted boxes: boxes = boxes / self.box_scaler boxes = tf.clip_by_value(boxes, 0.0, 1.0) # it has shape [batch_size, num_anchors, 4] scores = tf.nn.softmax(self.class_predictions_with_background, axis=2)[:, :, 1] # it has shape [batch_size, num_anchors] # 执行NMS操作来去除重复的检测框 with tf.device('/cpu:0'), tf.name_scope('nms'): boxes, scores, num_detections = batch_non_max_suppression( boxes, scores, score_threshold, iou_threshold, max_boxes) # 返回的字典包括:检测框、检测框对应的分数、以及检测框的总数目 return {'boxes': boxes, 'scores': scores, 'num_boxes': num_detections}
def get_predictions(self, score_threshold=0.1, iou_threshold=0.6, max_boxes=20): """Postprocess outputs of the network. Returns: boxes: a float tensor with shape [batch_size, N, 4]. scores: a float tensor with shape [batch_size, N]. num_boxes: an int tensor with shape [batch_size], it represents the number of detections on an image. where N = max_boxes. """ with tf.name_scope('postprocessing'): boxes = batch_decode(self.box_encodings, self.anchors) # it has shape [batch_size, num_anchors, 4] scores = tf.nn.softmax(self.class_predictions_with_background, axis=2)[:, :, 1] # it has shape [batch_size, num_anchors] with tf.device('/cpu:0'), tf.name_scope('nms'): boxes, scores, num_detections = batch_non_max_suppression( boxes, scores, score_threshold, iou_threshold, max_boxes) return {'boxes': boxes, 'scores': scores, 'num_boxes': num_detections}