def __compute_AP(self,c_scores,c_tp,c_fp,c_num_gbboxes):
aps_voc07 = {}
aps_voc12 = {}
for c in c_scores.keys():
num_gbboxes = c_num_gbboxes[c]
tp = c_tp[c]
fp = c_fp[c]
scores = c_scores[c]
#reshape data
num_gbboxes = math_ops.to_int64(num_gbboxes)
scores = math_ops.to_float(scores)
stype = tf.bool
tp = tf.cast(tp, stype)
fp = tf.cast(fp, stype)
# Reshape TP and FP tensors and clean away 0 class values.(difficult bboxes)
scores = tf.reshape(scores, [-1])
tp = tf.reshape(tp, [-1])
fp = tf.reshape(fp, [-1])
# Remove TP and FP both false.
mask = tf.logical_or(tp, fp)
rm_threshold = 1e-4
mask = tf.logical_and(mask, tf.greater(scores, rm_threshold))
scores = tf.boolean_mask(scores, mask)
tp = tf.boolean_mask(tp, mask)
fp = tf.boolean_mask(fp, mask)
num_gbboxes = tf.reduce_sum(num_gbboxes)
num_detections = tf.size(scores, out_type=tf.int32)
# Precison and recall values.
prec, rec = tfe.precision_recall(num_gbboxes, num_detections, tp, fp, scores)
v = tfe.average_precision_voc07(prec, rec)
aps_voc07[c] = v
# Average precision VOC12.
v = tfe.average_precision_voc12(prec, rec)
aps_voc12[c] = v
return aps_voc07, aps_voc12
评论列表
文章目录