def number_classes(Yin, omitLabels=[]):
"""Remaps class labels to contiguous natural numbers starting at 0.
In many frameworks (e.g. caffe) class labels are mapped to indices at
the output of the CNN; hence this remapping.
Any pixels that should be ignored will have class label of -1.
"""
if Yin is None: return None
yAll = np.sort(np.unique(Yin))
yAll = [y for y in yAll if y not in omitLabels]
Yout = -1*np.ones(Yin.shape, dtype=Yin.dtype)
for yIdx, y in enumerate(yAll):
Yout[Yin==y] = yIdx
return Yout
评论列表
文章目录