PCKAccuracy¶
- class mmeval.metrics.PCKAccuracy(thr: float = 0.2, norm_item: Union[str, Sequence[str]] = 'bbox', **kwargs)[source]¶
PCK accuracy evaluation metric, which is widely used in pose estimation.
Calculate the pose accuracy of Percentage of Correct Keypoints (PCK) for each individual keypoint and the averaged accuracy across all keypoints. PCK metric measures the accuracy of the localization of the body joints. The distances between predicted positions and the ground-truth ones are typically normalized by the person bounding box size. The threshold (thr) of the normalized distance is commonly set as 0.05, 0.1 or 0.2 etc.
Note
length of dataset: N
num_keypoints: K
number of keypoint dimensions: D (typically D = 2)
- Parameters
thr (float) – Threshold of PCK calculation. Defaults to 0.2.
norm_item (str | Sequence[str]) – The item used for normalization. Valid items include ‘bbox’, ‘head’, ‘torso’, which correspond to ‘PCK’, ‘PCKh’ and ‘tPCK’ respectively. Defaults to
'bbox'
.**kwargs – Keyword parameters passed to
BaseMetric
.
Examples
>>> from mmeval import PCKAccuracy >>> import numpy as np >>> num_keypoints = 15 >>> keypoints = np.random.random((1, num_keypoints, 2)) * 10 >>> predictions = [{'coords': keypoints}] >>> keypoints_visible = np.ones((1, num_keypoints)).astype(bool) >>> bbox_size = np.random.random((1, 2)) * 10 >>> groundtruths = [{ ... 'coords': keypoints, ... 'mask': keypoints_visible, ... 'bbox_size': bbox_size, ... }] >>> pck_metric = PCKAccuracy(thr=0.5, norm_item='bbox') >>> pck_metric(predictions, groundtruths) OrderedDict([('PCK@0.5', 1.0)])
- add(predictions: List[Dict], groundtruths: List[Dict]) → None[source]¶
Process one batch of predictions and groundtruths and add the intermediate results to self._results.
- Parameters
predictions (Sequence[dict]) –
Predictions from the model. Each prediction dict has the following keys:
coords (np.ndarray, [1, K, D]): predicted keypoints coordinates
groundtruths (Sequence[dict]) –
The ground truth labels. Each groundtruth dict has the following keys:
coords (np.ndarray, [1, K, D]): ground truth keypoints coordinates
mask (np.ndarray, [1, K]): ground truth keypoints_visible
bbox_size (np.ndarray, optional, [1, 2]): ground truth bbox size
head_size (np.ndarray, optional, [1, 2]): ground truth head size
torso_size (np.ndarray, optional, [1, 2]): ground truth torso size
- compute_metric(results: list) → Dict[str, float][source]¶
Compute the metrics from processed results.
- Parameters
results (list) – The processed results of each batch.
- Returns
The computed metrics. The keys are the names of the metrics, and the values are the corresponding results.
- Return type
Dict[str, float]