MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / multilabel_classification_accuracy

Function multilabel_classification_accuracy

tools/preprocess/pose2d_utils.py:932–958  ·  view source on GitHub ↗

Get multi-label classification accuracy. Note: - batch size: N - label number: L Args: pred (np.ndarray[N, L, 2]): model predicted labels. gt (np.ndarray[N, L, 2]): ground-truth labels. mask (np.ndarray[N, 1] or np.ndarray[N, L] ): reliability of

(pred, gt, mask, thr=0.5)

Source from the content-addressed store, hash-verified

930
931
932def multilabel_classification_accuracy(pred, gt, mask, thr=0.5):
933 """Get multi-label classification accuracy.
934
935 Note:
936 - batch size: N
937 - label number: L
938
939 Args:
940 pred (np.ndarray[N, L, 2]): model predicted labels.
941 gt (np.ndarray[N, L, 2]): ground-truth labels.
942 mask (np.ndarray[N, 1] or np.ndarray[N, L] ): reliability of
943 ground-truth labels.
944
945 Returns:
946 float: multi-label classification accuracy.
947 """
948 # we only compute accuracy on the samples with ground-truth of all labels.
949 valid = (mask > 0).min(axis=1) if mask.ndim == 2 else (mask > 0)
950 pred, gt = pred[valid], gt[valid]
951
952 if pred.shape[0] == 0:
953 acc = 0.0 # when no sample is with gt labels, set acc to 0.
954 else:
955 # The classification of a sample is regarded as correct
956 # only if it's correct for all labels.
957 acc = (((pred - thr) * (gt - thr)) > 0).all(axis=1).mean()
958 return acc
959
960
961def get_transform(center, scale, res, rot=0):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected