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

Method evaluate

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

:return: mean_IoU, IoU_array, pixel_acc, mean_acc

(self)

Source from the content-addressed store, hash-verified

186
187
188 def evaluate(self):
189 """
190
191 :return: mean_IoU, IoU_array, pixel_acc, mean_acc
192 """
193
194 if self._distributed:
195 link.synchronize()
196
197 conf_matrix_list = self.all_gather(self._conf_matrix)
198 # self._predictions = self.all_gather(self._predictions)
199 # self._predictions = list(itertools.chain(*self._predictions))
200 if link.get_rank() != 0:
201 return
202
203 self._conf_matrix = np.zeros_like(self._conf_matrix)
204 for conf_matrix in conf_matrix_list:
205 self._conf_matrix += conf_matrix
206
207 # if self._output_dir:
208 # os.makedirs(self._output_dir, exist_ok=True)
209 # file_path = os.path.join(self._output_dir, "humam_parsing_predictions.json")
210 # with open(file_path, "w") as f:
211 # f.write(json.dumps(self._predictions))
212
213 acc = np.full(self._num_classes, np.nan, dtype=np.float)
214 iou = np.full(self._num_classes, np.nan, dtype=np.float)
215 tp = self._conf_matrix.diagonal().astype(np.float)
216 pos_gt = np.sum(self._conf_matrix, axis=0).astype(np.float)
217 # class_weights = pos_gt / np.sum(pos_gt)
218 pos_pred = np.sum(self._conf_matrix, axis=1).astype(np.float)
219 acc_valid = pos_gt > 0
220 acc[acc_valid] = tp[acc_valid] / pos_gt[acc_valid]
221 iou_valid = (pos_gt + pos_pred) > 0
222 union = pos_gt + pos_pred - tp
223 iou[acc_valid] = tp[acc_valid] / union[acc_valid]
224 macc = np.sum(acc[acc_valid]) / np.sum(acc_valid)
225 miou = np.sum(iou[acc_valid]) / np.sum(iou_valid)
226 # fiou = np.sum(iou[acc_valid] * class_weights[acc_valid])
227 pacc = np.sum(tp) / np.sum(pos_gt)
228
229 res = {}
230 res["mIoU"] = 100 * miou
231 # res["fwIoU"] = 100 * fiou
232 for i, name in enumerate(self._class_names):
233 res["IoU-{}".format(name)] = 100 * iou[i]
234 res["mACC"] = 100 * macc
235 res["pACC"] = 100 * pacc
236 for i, name in enumerate(self._class_names):
237 res["ACC-{}".format(name)] = 100 * acc[i]
238
239 if self._output_dir:
240 file_path = os.path.join(self._output_dir, "human_parsing_evaluation.pth")
241 with open(file_path, "wb") as f:
242 torch.save(res, f)
243 results = OrderedDict({"human_parsing": res})
244 self._logger.info(results)
245 return results

Callers

nothing calls this directly

Calls 3

all_gatherMethod · 0.95
saveMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected