ProposalRecall¶
- class mmeval.metrics.ProposalRecall(iou_thrs: Optional[Union[float, Sequence[float]]] = None, proposal_nums: Union[int, Sequence[int]] = (1, 10, 100, 1000), use_legacy_coordinate: bool = False, nproc: int = 4, print_results: bool = True, **kwargs)[源代码]¶
Proposals recall evaluation metric.
The speed of calculating recall is faster than COCO Detection metric.
- 参数
iou_thrs (float | List[float], optional) – IoU thresholds. If not specified, IoUs from 0.5 to 0.95 will be used. Defaults to None.
proposal_nums (Sequence[int]) – Numbers of proposals to be evaluated. Defaults to (1, 10, 100, 1000).
use_legacy_coordinate (bool) – Whether to use coordinate system in mmdet v1.x. which means width, height should be calculated as ‘x2 - x1 + 1` and ‘y2 - y1 + 1’ respectively. Defaults to False.
nproc (int) – Processes used for computing TP and FP. If nproc is less than or equal to 1, multiprocessing will not be used. Defaults to 4.
print_results (bool) – Whether to print the results. Defaults to True.
**kwargs – Keyword parameters passed to
BaseMetric
.
实际案例
>>> import numpy as np >>> from mmeval import ProposalRecall >>> >>> proposal_recall = ProposalRecall() >>> def _gen_bboxes(num_bboxes, img_w=256, img_h=256): ... # random generate bounding boxes in 'xyxy' formart. ... x = np.random.rand(num_bboxes, ) * img_w ... y = np.random.rand(num_bboxes, ) * img_h ... w = np.random.rand(num_bboxes, ) * (img_w - x) ... h = np.random.rand(num_bboxes, ) * (img_h - y) ... return np.stack([x, y, x + w, y + h], axis=1) >>> >>> prediction = { ... 'bboxes': _gen_bboxes(10), ... 'scores': np.random.rand(10, ), ... } >>> groundtruth = { ... 'bboxes': _gen_bboxes(10), ... } >>> proposal_recall(predictions=[prediction, ], groundtruths=[groundtruth, ]) {'AR@1': ..., 'AR@10': ..., 'AR@100': ..., 'AR@1000': ...}
- add(predictions: Sequence[Dict], groundtruths: Sequence[Dict]) → None[源代码]¶
Add the intermediate results to
self._results
.- 参数
predictions (Sequence[dict]) –
A sequence of dict. Each dict representing a detection result for an image, with the following keys:
bboxes (numpy.ndarray): Shape (N, 4), the predicted bounding bboxes of this image, in ‘xyxy’ foramrt.
scores (numpy.ndarray): Shape (N, 1), the predicted scores of bounding boxes.
groundtruths (Sequence[dict]) –
A sequence of dict. Each dict represents a groundtruths for an image, with the following keys:
bboxes (numpy.ndarray): Shape (M, 4), the ground truth bounding bboxes of this image, in ‘xyxy’ foramrt.
- calculate_recall(predictions: List[dict], groundtruths: List[dict], pool: Optional[multiprocessing.pool.Pool])[源代码]¶
Calculate recall.
- 参数
predictions (List[dict]) – A list of dict. Each dict is the detection result of an image. Same as
ProposalRecall.add
.groundtruths (List[dict]) – A list of dict. Each dict is the ground truth of an image. Same as
ProposalRecall.add
.pool (Optional[Pool]) – A instance of
multiprocessing.Pool
. If None, do not use multiprocessing.
- 返回
Shape (len(proposal_nums), len(iou_thrs)), the recall results.
- 返回类型
numpy.ndarry
- compute_metric(results: list) → dict[源代码]¶
Compute the ProposalRecall metric.
- 参数
results (List[tuple]) – A list of tuple. Each tuple is the prediction and ground truth of an image. This list has already been synced across all ranks.
- 返回
The computed metric. The keys are the names of the proposal numbers, and the values are corresponding results.
- 返回类型
dict
- process_proposals(predictions: List[dict], groundtruths: List[dict]) → Tuple[List, List, int][源代码]¶
Process the proposals(bboxes) in predictions and groundtruths.
- 参数
predictions (List[dict]) – A list of dict. Each dict is the detection result of an image. Same as
ProposalRecall.add
.groundtruths (list[dict]) – Same as
ProposalRecall.add
.
- 返回
proposal_preds (List[numpy.ndarray]): The sorted proposals of the prediction.
proposal_gts (List[numpy.ndarray]): The proposals of the groundtruths.
num_gts (int): The total groundtruth numbers.
- 返回类型
tuple (proposal_preds, proposal_gts, num_gts)