hszhao / semseg

Semantic Segmentation in Pytorch
MIT License
1.34k stars 244 forks source link

A little mistake in intersectionAndUnion #11

Closed irfanICMLL closed 5 years ago

irfanICMLL commented 5 years ago

Hi! I use this code to train a model on Camvid, and the ignore_label is 11 on this dataset. I found here is a little mistake in the testing code. We should add a line in the 'intersectionAndUnion' in 'util/utils.py', and also add 'intersection, union, target = intersectionAndUnion(pred, target, classes,ignore_index=args.ignore_label)' in tool/test.py

def intersectionAndUnion(output, target, K, ignore_index=255):

'K' classes, output and target sizes are N or N L or N H * W, each value in range 0 to K - 1.

assert (output.ndim in [1, 2, 3])
assert output.shape == target.shape
output = output.reshape(output.size).copy()
target = target.reshape(target.size)
output[np.where(target == ignore_index)[0]] = 255
**target[np.where(target == ignore_index)[0]] = 255**
intersection = output[np.where(output == target)[0]]
area_intersection, _ = np.histogram(intersection, bins=np.arange(K+1))
area_output, _ = np.histogram(output, bins=np.arange(K+1))
area_target, _ = np.histogram(target, bins=np.arange(K+1))
area_union = area_output + area_target - area_intersection
return area_intersection, area_union, area_target
hszhao commented 5 years ago

Many thanks for the issue. I have updated the code as: output[np.where(target == ignore_index)[0]] = ignore_index.