1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| class AnnotatorEvaluator: """ 标注员评估器 """ def __init__(self, ground_truth_path): self.ground_truth = load_json(ground_truth_path) self.scores = {} def evaluate(self, annotator, predictions): """ 评估标注员 """ iou_scores = [] for pred, gt in zip(predictions, self.ground_truth): iou = self.calculate_iou(pred['bbox'], gt['bbox']) iou_scores.append(iou) class_accuracy = self.calculate_class_accuracy(predictions, self.ground_truth) temporal_accuracy = self.calculate_temporal_accuracy(predictions, self.ground_truth) score = { 'mean_iou': np.mean(iou_scores), 'class_accuracy': class_accuracy, 'temporal_accuracy': temporal_accuracy } self.scores[annotator] = score return score def calculate_iou(self, bbox1, bbox2): """ 计算IoU """ x1, y1, w1, h1 = bbox1 x2, y2, w2, h2 = bbox2 xi1 = max(x1, x2) yi1 = max(y1, y2) xi2 = min(x1+w1, x2+w2) yi2 = min(y1+h1, y2+h2) inter_w = max(0, xi2 - xi1) inter_h = max(0, yi2 - yi1) intersection = inter_w * inter_h union_w = (w1 + w2) - inter_w union_h = (h1 + h2) - inter_h union = union_w * union_h iou = intersection / union return iou
|