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

Class HumParEvaluator

PATH/core/solvers/utils/par_tester_dev.py:24–267  ·  view source on GitHub ↗

Evaluate human parsing metrics, specifically, for Human3.6M

Source from the content-addressed store, hash-verified

22from PIL import Image
23
24class HumParEvaluator(DatasetEvaluator):
25 """
26 Evaluate human parsing metrics, specifically, for Human3.6M
27 """
28
29 def __init__(
30 self,
31 dataset_name,
32 config,
33 distributed=True,
34 output_dir=None,
35 ):
36 """
37 Args:
38 dataset_name (str): name of the dataset to be evaluated.
39 distributed (bool): if True, will collect results from all ranks for evaluation.
40 Otherwise, will evaluate the results in the current process.
41 output_dir (str): an output directory to dump results.
42 num_classes, ignore_label: deprecated argument
43 """
44 self._logger = logging.getLogger(__name__)
45
46 self._dataset_name = dataset_name
47 self._distributed = distributed
48 self._output_dir = output_dir
49
50 self._cpu_device = torch.device("cpu")
51
52 self._class_names = config.dataset.kwargs.cfg.label_list #[1:] # 0 as background
53 self._num_classes = len(self._class_names)
54 assert self._num_classes == config.dataset.kwargs.cfg.num_classes, f"{self._num_classes} != {config.dataset.kwargs.cfg.num_classes}"
55 self._contiguous_id_to_dataset_id = {i: k for i, k in enumerate(
56 self._class_names)} # Dict that maps contiguous training ids to COCO category ids
57 self._ignore_label = config.dataset.kwargs.cfg.ignore_value
58
59 def reset(self):
60 self._conf_matrix = np.zeros((self._num_classes, self._num_classes), dtype=np.int64)
61 self._predictions = []
62
63 def generate_pseudo_labels(self, inputs, outputs, dataset=None, save_dir='./'):
64 assert dataset is not None
65 assert dataset.pseudo_labels_palette is not None, "palette follows the default property of the Human3.6M dataset."
66 # import pdb;
67 # pdb.set_trace()
68 palette = np.array(dataset.pseudo_labels_palette)
69 assert palette.shape[1] == 3
70 assert len(palette.shape) == 2
71 palette = palette.flatten().tolist()
72 palette = palette + [255] * (256 * 3 - len(palette))
73
74 for _idx, output in enumerate(outputs):
75 par_pred = output["sem_seg"]
76
77 try:
78 gt = np.array([inputs["height"][_idx].to(self._cpu_device), inputs["width"][_idx].to(self._cpu_device)]).astype(np.int)
79 except:
80 raise OSError("Height and width are not recorded during dataloading!")
81 # import pdb;

Callers 2

runMethod · 0.90
runMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected