Shortcuts

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)[source]

Proposals recall evaluation metric.

The speed of calculating recall is faster than COCO Detection metric.

Parameters
  • 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.

Examples

>>> 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[source]

Add the intermediate results to self._results.

Parameters
  • 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])[source]

Calculate recall.

Parameters
  • 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.

Returns

Shape (len(proposal_nums), len(iou_thrs)), the recall results.

Return type

numpy.ndarry

compute_metric(results: list)dict[source]

Compute the ProposalRecall metric.

Parameters

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.

Returns

The computed metric. The keys are the names of the proposal numbers, and the values are corresponding results.

Return type

dict

process_proposals(predictions: List[dict], groundtruths: List[dict])Tuple[List, List, int][source]

Process the proposals(bboxes) in predictions and groundtruths.

Parameters
Returns

  • 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.

Return type

tuple (proposal_preds, proposal_gts, num_gts)

Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.