dgs.models.metric.metric.compute_cmc

dgs.models.metric.metric.compute_cmc(distmat: torch.Tensor, query_pids: torch.Tensor, gallery_pids: torch.Tensor, ranks: list[int]) dict[int, float][source]

Compute the cumulative matching characteristics metric. It is expected that the distmat has lower values when the predictions are close.

Cumulative Matching Characteristics

For further information see: https://cysu.github.io/open-reid/notes/evaluation_metrics.html.

Single-gallery-shot means that each gallery identity has only one instance in the query. The single-gallery-shot CMC top-k accuracy is defined as

\[\begin{split}Acc_k = \begin{cases} 1 & \text{if top-}k\text{ ranked gallery samples contain the query identity} \\ 0 & \text{otherwise} \end{cases}\end{split}\]

This represents a shifted step function. The final CMC curve is computed by averaging the shifted step functions over all the queries.

The multi-gallery-shot accuracy is not implemented.

Notes

Goal of person ReID: For each image in the query, find similar persons within the gallery set.

Notes

This method does not remove “invalid” data. E.g., in market1501 iff gallery samples have the same pid and camid as the query.

param distmat:

(Float)Tensor of shape [n_query x n_gallery] containing the distances between every item from gallery and query.

param query_pids:

(Long)Tensor of shape [n_query (x 1)] containing the query IDs.

param gallery_pids:

(Long)Tensor of shape [n_gallery (x 1)], containing the gallery IDs.

param ranks:

List of integers containing the k values used for the evaluation.

returns:

A list containing the float cmc accuracies for each of the k.