Indoor scene evaluation metric. Args: iou_thr (list[float]): List of iou threshold when calculate the metric. Defaults to [0.25, 0.5]. collect_device (str, optional): Device name used for collecting results from different ranks during distributed trainin
| 16 | |
| 17 | @METRICS.register_module() |
| 18 | class OccupancyMetric(BaseMetric): |
| 19 | """Indoor scene evaluation metric. |
| 20 | |
| 21 | Args: |
| 22 | iou_thr (list[float]): List of iou threshold when calculate the |
| 23 | metric. Defaults to [0.25, 0.5]. |
| 24 | collect_device (str, optional): Device name used for collecting |
| 25 | results from different ranks during distributed training. |
| 26 | Must be 'cpu' or 'gpu'. Defaults to 'cpu'. |
| 27 | prefix (str): The prefix that will be added in the metric |
| 28 | names to disambiguate homonymous metrics of different evaluators. |
| 29 | If prefix is not provided in the argument, self.default_prefix |
| 30 | will be used instead. Default: None |
| 31 | """ |
| 32 | |
| 33 | def __init__(self, |
| 34 | collect_device: str = 'cpu', |
| 35 | prefix: Optional[str] = None, |
| 36 | batchwise_anns: bool = False, |
| 37 | **kwargs): |
| 38 | super(OccupancyMetric, self).__init__(prefix=prefix, |
| 39 | collect_device=collect_device) |
| 40 | self.batchwise_anns = batchwise_anns |
| 41 | |
| 42 | def process(self, data_batch: dict, data_samples: Sequence[dict]) -> None: |
| 43 | """Process one batch of data samples and predictions. |
| 44 | |
| 45 | The processed results should be stored in ``self.results``, |
| 46 | which will be used to compute the metrics when all batches |
| 47 | have been processed. |
| 48 | |
| 49 | Args: |
| 50 | data_batch (dict): A batch of data from the dataloader. |
| 51 | data_samples (Sequence[dict]): A batch of outputs from |
| 52 | the model. |
| 53 | """ |
| 54 | for data_sample in data_samples: |
| 55 | pred_occ = data_sample['pred_occupancy'] |
| 56 | gt_4 = data_sample['gt_occupancy'] |
| 57 | gt_occ = torch.zeros_like(pred_occ) |
| 58 | gt_occ[gt_4[:, 0], gt_4[:, 1], gt_4[:, 2]] = gt_4[:, 3] |
| 59 | if 'gt_occupancy_masks' in data_sample: |
| 60 | gt_occ_mask = data_sample['gt_occupancy_masks'] |
| 61 | gt_occ[~gt_occ_mask] = 255 |
| 62 | self.results.append((gt_occ, pred_occ)) |
| 63 | |
| 64 | def compute_metrics(self, results: list) -> Dict[str, float]: |
| 65 | """Compute the metrics from processed results. |
| 66 | |
| 67 | Args: |
| 68 | results (list): The processed results of each batch. |
| 69 | |
| 70 | Returns: |
| 71 | Dict[str, float]: The computed metrics. The keys are the names of |
| 72 | the metrics, and the values are corresponding results. |
| 73 | """ |
| 74 | logger: MMLogger = MMLogger.get_current_instance() |
| 75 | num_class = len(self.dataset_meta['classes']) + 1 |
nothing calls this directly
no outgoing calls
no test coverage detected