在语义分割的标签文件,存放在SegmentationClass文件夹下,每张jpg的图片会对应一张单通道的png的mask图片。
包括背景,一共有21个类别,
{
"background": 0,
"aeroplane": 1,
"bicycle": 2,
"bird": 3,
"boat": 4,
"bottle": 5,
"bus": 6,
"car": 7,
"cat": 8,
"chair": 9,
"cow": 10,
"diningtable": 11,
"dog": 12,
"horse": 13,
"motorbike": 14,
"person": 15,
"pottedplant": 16,
"sheep": 17,
"sofa": 18,
"train": 19,
"tvmonitor": 20
}
对SegmentationClass下的所有png的图片进行遍历,筛选出标签:
unique labels:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 255]
length labels:22
其中包含255的类别,读入一张图片,将png中不同的label填充成不同的颜色,进行可视化
def show_png_unique():
pngpath='VOCdevkit/VOC2007/SegmentationClass/2007_000063.png'
mask=cv2.imread(pngpath,-1)
height,width=mask.shape
resbs=np.unique(mask)
print(resbs)
dict_colors={
0:[ 0, 250, 154],
1:[255, 160, 122],
2:[255, 0, 255],
3:[210, 180, 140],
4:[ 0, 206, 209],
5:[250, 240, 230],
6:[47, 79, 79],
7:[152, 251, 152],
8:[255, 239, 213],
9:[173, 255, 47],
10:[ 60, 179, 113],
11:[123, 104, 238],
12:[160, 82, 45],
13:[255, 69, 0],
14:[ 0, 255, 127],
15:[ 32, 178, 170],
16:[119, 136, 153],
17:[139, 0, 139],
18:[124, 252, 0],
19:[ 75, 0, 130],
20:[255, 215, 0],
21:[123, 104, 238],
255:[255,255,255],
}
img=np.zeros((height,width,3),dtype=np.uint8)
for resb in resbs:
img[mask==resb]=dict_colors[resb]
cv2.imwrite("color_img.jpg",img)
结果图如上所示,可以看到目标的边缘全部是白色,也就是png图片中255的标签,所对应的区域,在训练的过程中,该区域会被屏蔽掉。