在语义分割中,不是一张图片分配一个label,而是为图片的每一个像素点分配一个label。假设我们输入的是RGB三通道的图片,即每个像素点颜色可以表示为(x, y, z),那么为了给像素点打上label,我们需要构建一个映射关系,例如下面,我们定义了21种颜色对应的标签信息:
#@save
VOC_COLORMAP = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
[0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128],
[64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0],
[64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128],
[0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0],
[0, 64, 128]]
#@save
VOC_CLASSES = ['background', 'aeroplane', 'bicycle', 'bird', 'boat',
'bottle', 'bus', 'car', 'cat', 'chair', 'cow',
'diningtable', 'dog', 'horse', 'motorbike', 'person',
'potted plant', 'sheep', 'sofa', 'train', 'tv/monitor']
那么怎么查找标签中每个像素的类索引呢? 我们定义了voc_colormap2label
函数来构建从上述RGB颜色值到类别索引的映射,而voc_lab