Evaluate point interactive IoU metrics.
| 68 | self.point_evaluator_oracle.evaluate() |
| 69 | |
| 70 | class InteractiveEvaluator(DatasetEvaluator): |
| 71 | """ |
| 72 | Evaluate point interactive IoU metrics. |
| 73 | """ |
| 74 | |
| 75 | def __init__( |
| 76 | self, |
| 77 | dataset_name, |
| 78 | output_dir, |
| 79 | max_clicks=20, |
| 80 | iou_iter=1, |
| 81 | compute_box=False, |
| 82 | distributed=True, |
| 83 | ): |
| 84 | self._logger = logging.getLogger(__name__) |
| 85 | self._dataset_name = dataset_name |
| 86 | self._distributed = distributed |
| 87 | self._cpu_device = torch.device("cpu") |
| 88 | self._output_dir = output_dir |
| 89 | |
| 90 | self.max_clicks = max_clicks |
| 91 | self.iou_iter = iou_iter |
| 92 | meta = MetadataCatalog.get(dataset_name) |
| 93 | |
| 94 | def reset(self): |
| 95 | self.iou_list = [] |
| 96 | self.num_samples = 0 |
| 97 | self.all_ious = [0.5, 0.8, 0.85, 0.9] |
| 98 | |
| 99 | def process(self, inputs, outputs): |
| 100 | self.iou_list += [o['mask_iou'] for o in outputs] |
| 101 | self.num_samples += len(outputs) |
| 102 | |
| 103 | def compute_noc(self): |
| 104 | def _get_noc(iou_arr, iou_thr): |
| 105 | vals = iou_arr >= iou_thr |
| 106 | return vals.max(dim=0)[1].item() + 1 if vals.any() else self.max_clicks |
| 107 | |
| 108 | noc_list = {} |
| 109 | for iou_thr in self.all_ious: |
| 110 | scores_arr = [_get_noc(iou_arr, iou_thr) for iou_arr in self.iou_list] |
| 111 | noc_list[str(iou_thr)] = scores_arr |
| 112 | |
| 113 | iou_before_max_iter = torch.stack(self.iou_list)[:,self.iou_iter-1] |
| 114 | |
| 115 | if self._distributed: |
| 116 | num_samples = sum(all_gather(self.num_samples)) |
| 117 | noc_list_gather = all_gather(noc_list) |
| 118 | iou_before_max_gather = all_gather(iou_before_max_iter.sum()) |
| 119 | |
| 120 | noc_list = {key:[] for key in noc_list_gather[0]} |
| 121 | for nlg in noc_list_gather: |
| 122 | for key, value in nlg.items(): |
| 123 | noc_list[key] += value |
| 124 | |
| 125 | pred_noc = {} |
| 126 | if self._distributed and (not is_main_process()): |
| 127 | return pred_noc |
no outgoing calls
no test coverage detected