mirror of
https://github.com/botastic/SoftGroup.git
synced 2025-10-16 11:45:42 +00:00
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import numpy as np
|
|
|
|
|
|
def evaluate_semantic_acc(pred_list, gt_list, ignore_label=-100, logger=None):
|
|
gt = np.concatenate(gt_list, axis=0)
|
|
pred = np.concatenate(pred_list, axis=0)
|
|
assert gt.shape == pred.shape
|
|
correct = (gt[gt != ignore_label] == pred[gt != ignore_label]).sum()
|
|
whole = (gt != ignore_label).sum()
|
|
acc = correct.astype(float) / whole * 100
|
|
logger.info(f'Acc: {acc:.1f}')
|
|
return acc
|
|
|
|
|
|
def evaluate_semantic_miou(pred_list, gt_list, ignore_label=-100, logger=None):
|
|
gt = np.concatenate(gt_list, axis=0)
|
|
pred = np.concatenate(pred_list, axis=0)
|
|
pos_inds = gt != ignore_label
|
|
gt = gt[pos_inds]
|
|
pred = pred[pos_inds]
|
|
assert gt.shape == pred.shape
|
|
iou_list = []
|
|
for _index in np.unique(gt):
|
|
if _index != ignore_label:
|
|
intersection = ((gt == _index) & (pred == _index)).sum()
|
|
union = ((gt == _index) | (pred == _index)).sum()
|
|
iou = intersection.astype(float) / union * 100
|
|
iou_list.append(iou)
|
|
miou = np.mean(iou_list)
|
|
logger.info('Class-wise mIoU: ' + ' '.join(f'{x:.1f}' for x in iou_list))
|
|
logger.info(f'mIoU: {miou:.1f}')
|
|
return miou
|