MCPcopy Create free account
hub / github.com/IRMVLab/SemGauss-SLAM / batch_intersection_union

Function batch_intersection_union

utils/segmentationMetric.py:88–111  ·  view source on GitHub ↗

mIoU

(output, target, nclass)

Source from the content-addressed store, hash-verified

86
87
88def batch_intersection_union(output, target, nclass):
89 """mIoU"""
90 # inputs are numpy array, output 4D, target 3D
91 mini = 1
92 maxi = nclass
93 nbins = nclass
94 target = torch.max(target, 1).indices.squeeze() #change1
95 target = target.unsqueeze(0)
96 output = torch.max(output, 1).indices.squeeze()
97 output = output.unsqueeze(0)
98 #predict = torch.argmax(output, 1) + 1
99 target = target.float() + 1
100 predict = output + 1
101
102 predict = predict.float() * (target > 0).float()
103 intersection = predict * (predict == target).float()
104 # areas of intersection and union
105 # element 0 in intersection occur the main difference from np.bincount. set boundary to -1 is necessary.
106 area_inter = torch.histc(intersection.cpu(), bins=nbins, min=mini, max=maxi)
107 area_pred = torch.histc(predict.cpu(), bins=nbins, min=mini, max=maxi)
108 area_lab = torch.histc(target.cpu(), bins=nbins, min=mini, max=maxi)
109 area_union = area_pred + area_lab - area_inter
110 assert torch.sum(area_inter > area_union).item() == 0, "Intersection area should be smaller than Union area"
111 return area_inter.float(), area_union.float()
112
113
114def pixelAccuracy(imPred, imLab):

Callers 1

evaluate_workerMethod · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected