From 3c5bc18aa74c1f09caeae7635dfcb8d59a6d44f6 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 11 Jan 2024 16:59:27 +0100 Subject: [PATCH 1/4] Update cocoeval.py Parametrize summarize? --- PythonAPI/pycocotools/cocoeval.py | 68 ++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/PythonAPI/pycocotools/cocoeval.py b/PythonAPI/pycocotools/cocoeval.py index 89c251e..bce4d6b 100644 --- a/PythonAPI/pycocotools/cocoeval.py +++ b/PythonAPI/pycocotools/cocoeval.py @@ -455,33 +455,53 @@ def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ): mean_s = np.mean(s[s>-1]) print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s)) return mean_s + def _summarizeDets(): - stats = np.zeros((12,)) - stats[0] = _summarize(1) - stats[1] = _summarize(1, iouThr=.5, maxDets=self.params.maxDets[2]) - stats[2] = _summarize(1, iouThr=.75, maxDets=self.params.maxDets[2]) - stats[3] = _summarize(1, areaRng='small', maxDets=self.params.maxDets[2]) - stats[4] = _summarize(1, areaRng='medium', maxDets=self.params.maxDets[2]) - stats[5] = _summarize(1, areaRng='large', maxDets=self.params.maxDets[2]) - stats[6] = _summarize(0, maxDets=self.params.maxDets[0]) - stats[7] = _summarize(0, maxDets=self.params.maxDets[1]) - stats[8] = _summarize(0, maxDets=self.params.maxDets[2]) - stats[9] = _summarize(0, areaRng='small', maxDets=self.params.maxDets[2]) - stats[10] = _summarize(0, areaRng='medium', maxDets=self.params.maxDets[2]) - stats[11] = _summarize(0, areaRng='large', maxDets=self.params.maxDets[2]) + # Calculate the size of stats based on area ranges, IoU thresholds, and max detections + num_area_ranges = len(self.params.areaRngLbl) # Number of area ranges + num_iou_thrs = 3 # Typically, IoU thresholds at 0.5, 0.75, and 0.5:0.95 (mean AP) + num_dets = len(self.params.maxDets) # Number of max detection thresholds + + # Total number of stats to calculate + total_stats = num_iou_thrs * num_area_ranges + num_dets + + # Initialize the stats array + stats = np.zeros((total_stats,)) + + # Calculate stats + stats_index = 0 + for iouThr in [None, 0.5, 0.75]: + for areaLbl in self.params.areaRngLbl: + stats[stats_index] = _summarize(1, iouThr=iouThr, areaRng=areaLbl, maxDets=self.params.maxDets[-1]) + stats_index += 1 + + # Include additional stats for different maxDet values + for maxDet in self.params.maxDets: + stats[stats_index] = _summarize(0, maxDets=maxDet) + stats_index += 1 + return stats + + return stats + def _summarizeKps(): - stats = np.zeros((10,)) - stats[0] = _summarize(1, maxDets=20) - stats[1] = _summarize(1, maxDets=20, iouThr=.5) - stats[2] = _summarize(1, maxDets=20, iouThr=.75) - stats[3] = _summarize(1, maxDets=20, areaRng='medium') - stats[4] = _summarize(1, maxDets=20, areaRng='large') - stats[5] = _summarize(0, maxDets=20) - stats[6] = _summarize(0, maxDets=20, iouThr=.5) - stats[7] = _summarize(0, maxDets=20, iouThr=.75) - stats[8] = _summarize(0, maxDets=20, areaRng='medium') - stats[9] = _summarize(0, maxDets=20, areaRng='large') + # Calculate the size of stats based on area ranges and IoU thresholds + num_area_ranges = len(self.params.areaRngLbl) # Number of area ranges + num_iou_thrs = 3 # IoU thresholds at 0.5, 0.75, and mean AP + + # Total number of stats to calculate + total_stats = num_iou_thrs * num_area_ranges + + # Initialize the stats array + stats = np.zeros((total_stats,)) + + # Calculate stats + stats_index = 0 + for iouThr in [None, 0.5, 0.75]: + for areaLbl in self.params.areaRngLbl: + stats[stats_index] = _summarize(1, iouThr=iouThr, areaRng=areaLbl, maxDets=20) + stats_index += 1 + return stats if not self.eval: raise Exception('Please run accumulate() first') From ac0db0185634606bc97eb1489324e5a957d8663d Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 11 Jan 2024 17:36:29 +0100 Subject: [PATCH 2/4] fix --- PythonAPI/pycocotools/cocoeval.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/PythonAPI/pycocotools/cocoeval.py b/PythonAPI/pycocotools/cocoeval.py index bce4d6b..dec6ab6 100644 --- a/PythonAPI/pycocotools/cocoeval.py +++ b/PythonAPI/pycocotools/cocoeval.py @@ -482,8 +482,6 @@ def _summarizeDets(): return stats - return stats - def _summarizeKps(): # Calculate the size of stats based on area ranges and IoU thresholds num_area_ranges = len(self.params.areaRngLbl) # Number of area ranges From a432fb8a64e3146204298ae3cf0f734aac3fa995 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 11 Jan 2024 18:16:54 +0100 Subject: [PATCH 3/4] fix AR --- PythonAPI/pycocotools/cocoeval.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/PythonAPI/pycocotools/cocoeval.py b/PythonAPI/pycocotools/cocoeval.py index dec6ab6..2629fea 100644 --- a/PythonAPI/pycocotools/cocoeval.py +++ b/PythonAPI/pycocotools/cocoeval.py @@ -456,29 +456,30 @@ def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ): print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s)) return mean_s - def _summarizeDets(): + def _summarizeDets(): # Calculate the size of stats based on area ranges, IoU thresholds, and max detections num_area_ranges = len(self.params.areaRngLbl) # Number of area ranges - num_iou_thrs = 3 # Typically, IoU thresholds at 0.5, 0.75, and 0.5:0.95 (mean AP) + num_iou_thrs = 3 # IoU thresholds at 0.5, 0.75, and 0.5:0.95 (mean AP) num_dets = len(self.params.maxDets) # Number of max detection thresholds - # Total number of stats to calculate - total_stats = num_iou_thrs * num_area_ranges + num_dets + # Total number of stats to calculate for AP and AR + total_stats = num_iou_thrs * num_area_ranges + num_dets * num_area_ranges # Initialize the stats array stats = np.zeros((total_stats,)) - # Calculate stats + # Calculate AP stats stats_index = 0 for iouThr in [None, 0.5, 0.75]: for areaLbl in self.params.areaRngLbl: stats[stats_index] = _summarize(1, iouThr=iouThr, areaRng=areaLbl, maxDets=self.params.maxDets[-1]) stats_index += 1 - # Include additional stats for different maxDet values + # Calculate AR stats for different maxDet values for maxDet in self.params.maxDets: - stats[stats_index] = _summarize(0, maxDets=maxDet) - stats_index += 1 + for areaLbl in self.params.areaRngLbl: + stats[stats_index] = _summarize(0, areaRng=areaLbl, maxDets=maxDet) + stats_index += 1 return stats From 4fdb16d6d07e7a73f4e24a611325f25751279ae7 Mon Sep 17 00:00:00 2001 From: Johnny Date: Fri, 19 Jan 2024 08:12:42 +0100 Subject: [PATCH 4/4] Update cocoeval.py --- PythonAPI/pycocotools/cocoeval.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PythonAPI/pycocotools/cocoeval.py b/PythonAPI/pycocotools/cocoeval.py index 2629fea..04ff3fa 100644 --- a/PythonAPI/pycocotools/cocoeval.py +++ b/PythonAPI/pycocotools/cocoeval.py @@ -4,7 +4,7 @@ import datetime import time from collections import defaultdict -from . import mask as maskUtils +from pycocotools import mask as maskUtils import copy class COCOeval: @@ -456,7 +456,7 @@ def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ): print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s)) return mean_s - def _summarizeDets(): + def _summarizeDets(): # Calculate the size of stats based on area ranges, IoU thresholds, and max detections num_area_ranges = len(self.params.areaRngLbl) # Number of area ranges num_iou_thrs = 3 # IoU thresholds at 0.5, 0.75, and 0.5:0.95 (mean AP)