Evaluate semantic segmentation metrics.
| 367 | |
| 368 | |
| 369 | class MPIIPoseEvaluator(DatasetEvaluator): |
| 370 | """ |
| 371 | Evaluate semantic segmentation metrics. |
| 372 | """ |
| 373 | |
| 374 | def __init__( |
| 375 | self, |
| 376 | dataset_name, |
| 377 | config, |
| 378 | distributed=True, |
| 379 | output_dir=None, |
| 380 | ): |
| 381 | """ |
| 382 | Args: |
| 383 | dataset_name (str): name of the dataset to be evaluated. |
| 384 | distributed (bool): if True, will collect results from all ranks for evaluation. |
| 385 | Otherwise, will evaluate the results in the current process. |
| 386 | output_dir (str): an output directory to dump results. |
| 387 | num_classes, ignore_label: deprecated argument |
| 388 | """ |
| 389 | self._logger = logging.getLogger(__name__) |
| 390 | self._cpu_device = torch.device("cpu") |
| 391 | self.annot_root = config.dataset.kwargs.ann_file |
| 392 | |
| 393 | # for pseudo_label |
| 394 | self.pseudo_labels_results = [] |
| 395 | |
| 396 | def reset(self): |
| 397 | self.results = [] |
| 398 | |
| 399 | def process(self, inputs, outputs): |
| 400 | """ |
| 401 | Args: |
| 402 | inputs: the inputs to a model. |
| 403 | It is a list of dicts. Each dict corresponds to an image and |
| 404 | contains keys like "height", "width", "file_name". |
| 405 | outputs: the outputs of a model. It is either list of semantic segmentation predictions |
| 406 | (Tensor [H, W]) or list of dicts with key "sem_seg" that contains semantic |
| 407 | segmentation prediction in the same format. |
| 408 | """ |
| 409 | # for input, output in zip(inputs, outputs): |
| 410 | self.results.append(outputs) |
| 411 | |
| 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 \ |