Shortcuts

KeypointNME

class mmeval.metrics.KeypointNME(norm_mode: str, norm_item: Optional[str] = None, keypoint_indices: Optional[Sequence[int]] = None, **kwargs)[source]

NME evaluation metric.

Calculate the normalized mean error (NME) of keypoints.

Note

  • length of dataset: N

  • num_keypoints: K

  • number of keypoint dimensions: D (typically D = 2)

Parameters
  • norm_mode (str) –

    The normalization mode, which should be one of the following options:

    • 'use_norm_item': Should specify the argument norm_item, which represents the item in the datainfo that will be used as the normalization factor.

    • 'keypoint_distance': Should specify the argument keypoint_indices that are used to calculate the keypoint distance as the normalization factor.

  • norm_item (str, optional) – The item used as the normalization factor. For example, ‘box_size’ in ‘AFLWDataset’. Only valid when norm_mode is use_norm_item. Defaults to None.

  • keypoint_indices (Sequence[int], optional) – The keypoint indices used to calculate the keypoint distance as the normalization factor. Only valid when norm_mode is keypoint_distance. If set as None, will use the default keypoint_indices in DEFAULT_KEYPOINT_INDICES for specific datasets, else use the given keypoint_indices of the dataset. Defaults to None.

  • **kwargs – Keyword parameters passed to BaseMetric.

Examples

>>> from mmeval.metrics import KeypointNME
>>> import numpy as np
>>> aflw_dataset_meta = {
...     'dataset_name': 'aflw',
...     'num_keypoints': 19,
...     'sigmas': np.array([]),
... }
>>> nme_metric = KeypointNME(
...     norm_mode='use_norm_item',
...     norm_item=norm_item,
...     dataset_meta=aflw_dataset_meta)
>>> batch_size = 2
>>> predictions = [{
...     'coords': np.zeros((1, 19, 2))
... } for _ in range(batch_size)]
>>> groundtruths = [{
...     'coords': np.zeros((1, 19, 2)) + 0.5,
...     'mask': np.ones((1, 19)).astype(bool),
...     'box_size': np.ones((1, 1)) * i * 20
... } for i in range(batch_size)]
>>> norm_item = 'box_size'
>>> nme_metric(predictions, groundtruths)
OrderedDict([('NME', 0.03535533892480951)])
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 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

    There are some optional keys as well:

    • bboxes: it is necessary when self.norm_item is ‘bbox_size’

    • self.norm_item: it is necessary when self.norm_item is neither None nor ‘bbox_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]

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.