Args: inputs: the inputs to a model. It is a list of dicts. Each dict corresponds to an image and contains keys like "height", "width", "file_name". outputs: the outputs of a model. It is either list of semantic segmentation predi
(self, inputs, outputs)
| 109 | return |
| 110 | |
| 111 | def process(self, inputs, outputs): |
| 112 | """ |
| 113 | Args: |
| 114 | inputs: the inputs to a model. |
| 115 | It is a list of dicts. Each dict corresponds to an image and |
| 116 | contains keys like "height", "width", "file_name". |
| 117 | outputs: the outputs of a model. It is either list of semantic segmentation predictions |
| 118 | (Tensor [H, W]) or list of dicts with key "sem_seg" that contains semantic |
| 119 | segmentation prediction in the same format. |
| 120 | """ |
| 121 | |
| 122 | for _idx, output in enumerate(outputs): |
| 123 | par_pred = output["sem_seg"] |
| 124 | |
| 125 | try: |
| 126 | gt = np.array(inputs["gt"][_idx].to(self._cpu_device)).astype(np.int) |
| 127 | except: |
| 128 | gt = inputs["gt"][_idx].data.astype(np.int) |
| 129 | # import pdb; |
| 130 | # pdb.set_trace() |
| 131 | par_pred = output["sem_seg"] |
| 132 | par_pred_size = par_pred.size() |
| 133 | gt_h, gt_w = gt.shape[-2], gt.shape[-1] |
| 134 | |
| 135 | if par_pred_size[-2]!=gt_h or par_pred_size[-1]!=gt_w: |
| 136 | par_pred = F.upsample(par_pred.unsqueeze(0), (gt_h, gt_w),mode='bilinear') |
| 137 | output = par_pred[0].argmax(dim=0).to(self._cpu_device) |
| 138 | else: |
| 139 | output = par_pred.argmax(dim=0).to(self._cpu_device) |
| 140 | |
| 141 | pred = np.array(output, dtype=np.int) |
| 142 | |
| 143 | if len(pred.shape)!=2: |
| 144 | import pdb; |
| 145 | pdb.set_trace() |
| 146 | |
| 147 | self._conf_matrix += self.get_confusion_matrix(gt, pred, self._num_classes, self._ignore_label).astype(np.int64) |
| 148 | |
| 149 | |
| 150 | def get_confusion_matrix(self, seg_gt, seg_pred, num_class, ignore=-1): |
nothing calls this directly
no test coverage detected