MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / evaluate

Method evaluate

PATH/core/solvers/utils/pos_tester_dev.py:414–533  ·  view source on GitHub ↗

Evaluate PCKh for MPII dataset. Adapted from https://github.com/leoxiaobin/deep-high-resolution-net.pytorch Copyright (c) Microsoft, under the MIT License. Note: - batch_size: N - num_keypoints: K - heatmap height: H - heatmap w

(self, res_folder=None, metric='PCKh', **kwargs)

Source from the content-addressed store, hash-verified

412 # note: sync if multi-gpu
413
414 def evaluate(self, res_folder=None, metric='PCKh', **kwargs):
415 """Evaluate PCKh for MPII dataset. Adapted from
416 https://github.com/leoxiaobin/deep-high-resolution-net.pytorch
417 Copyright (c) Microsoft, under the MIT License.
418 Note:
419 - batch_size: N
420 - num_keypoints: K
421 - heatmap height: H
422 - heatmap width: W
423 Args:
424 results (list[dict]): Testing results containing the following
425 items:
426 - preds (np.ndarray[N,K,3]): The first two dimensions are \
427 coordinates, score is the third dimension of the array.
428 - boxes (np.ndarray[N,6]): [center[0], center[1], scale[0], \
429 scale[1],area, score]
430 - image_paths (list[str]): For example, ['/val2017/000000\
431 397133.jpg']
432 - heatmap (np.ndarray[N, K, H, W]): model output heatmap.
433 res_folder (str, optional): The folder to save the testing
434 results. Default: None.
435 metric (str | list[str]): Metrics to be performed.
436 Defaults: 'PCKh'.
437 Returns:
438 dict: PCKh for each joint
439 """
440
441 metrics = metric if isinstance(metric, list) else [metric]
442 allowed_metrics = ['PCKh']
443 for metric in metrics:
444 if metric not in allowed_metrics:
445 raise KeyError(f'metric {metric} is not supported')
446
447 kpts = []
448 for result in self.results:
449 preds = result['preds']
450 bbox_ids = result['bbox_ids']
451 batch_size = len(bbox_ids)
452 for i in range(batch_size):
453 kpts.append({'keypoints': preds[i], 'bbox_id': bbox_ids[i]})
454 kpts = self._sort_and_unique_bboxes(kpts)
455
456 preds = np.stack([kpt['keypoints'] for kpt in kpts])
457
458 # convert 0-based index to 1-based index,
459 # and get the first two dimensions.
460 preds = preds[..., :2] + 1.0
461
462 if res_folder:
463 pred_file = os.path.join(res_folder, 'pred.mat')
464 savemat(pred_file, mdict={'preds': preds})
465
466 SC_BIAS = 0.6
467 threshold = 0.5
468
469 gt_file = os.path.join(os.path.dirname(self.annot_root), 'mpii_gt_val.mat')
470 gt_dict = loadmat(gt_file)
471 dataset_joints = gt_dict['dataset_joints']

Callers

nothing calls this directly

Calls 2

stackMethod · 0.80

Tested by

no test coverage detected