Tramac / awesome-semantic-segmentation-pytorch

Semantic Segmentation on PyTorch (include FCN, PSPNet, Deeplabv3, Deeplabv3+, DANet, DenseASPP, BiSeNet, EncNet, DUNet, ICNet, ENet, OCNet, CCNet, PSANet, CGNet, ESPNet, LEDNet, DFANet)
Apache License 2.0
2.8k stars 581 forks source link

How to output freq_IU ? #159

Open lr1234567 opened 3 years ago

Tramac commented 3 years ago

You can put the code here.

lr1234567 commented 3 years ago

def hist_info(pred, label, num_cls): assert pred.shape == label.shape k = (label >= 0) & (label < num_cls) labeled = np.sum(k) correct = np.sum((pred[k] == label[k]))

return np.bincount(num_cls * label[k].astype(int) + pred[k], minlength=num_cls ** 2).reshape(num_cls,
                                                                                             num_cls), labeled, correct

def compute_score(hist, correct, labeled): iu = np.diag(hist) / (hist.sum(1) + hist.sum(0) - np.diag(hist)) mean_IU = np.nanmean(iu) mean_IU_no_back = np.nanmean(iu[1:]) freq = hist.sum(1) / hist.sum() freq_IU = (iu[freq > 0] * freq[freq > 0]).sum() mean_pixel_acc = correct / labeled

return iu, mean_IU, mean_IU_no_back, mean_pixel_acc

Hello, I want to calculate freq_ IU is used as evaluation index, but I don't know how to use these two functions?