dataset-cityscapes
Introduction
cityscapes通常被用作语义分割,里面的数据一共分为8个category,其中包含一个名为void的category,每个category中又有多个class,cityscapes一共有30个class,但是cityscapes编号过后的label一共有35种,其中也包含unlabeled等并没有算作class的label。
paper中常用的数据大概只有一部分,即fine标记过的数据集,其它一些额外的粗糙标记的数据使用相对比较少,下面先介绍一下这些常用的数据。
常用的一些数据如下图:

上面两个是标记之后的mask,下面两个是原始的数据,即8位的照片,这两对数据也分成了两个部分,一部分是fine标记过的,另一部分为粗糙标记的额外数据,对应于train_extra,通常不用来训练。对于fine标记的数据,一共有5000张照片和对应的标记,其中有2975张用于train,500张用于val,1525张用于test和benchmark。
cityscapes的标记数据
这里重点介绍一下cityscapes的标记数据,这一块比较麻烦一些,对于每一张图片,其标记数据有四种,也包含在gtFine的文件夹里面,每个图片所对应的4种标记分别为:xxx_gtFine_color.png,xxx_gtFine_instanceIds.png,xxx_gtFine_labelIds.png,xxx_gtFine_polygons.json。其中xxx_gtFine_color.png为标记的彩色表示,主要用于可视化,xxx_gtFine_instanceIds.png是instance-level分割的任务所使用的标记,xxx_gtFine_labelIds.png是pixel-level分割所使用的标记,xxx_gtFine_polygons.json是标记的具体信息,包括图像尺寸,标记的类别和多边形的顶点。

需要注意的是,这里面的文件并不适合直接拿来训练,cityscapes对每个label都进行了编号,包括天空之类的,这个编号我们称之为绝对编号。
对于instance-level的任务,在xxx_gtFine_instanceIds.png中,其每个像素对应的灰度值和这些ID并不是一一对应的,而需要一些函数来将其进行转换,这些函数可以在citycapesscripts里面找到,转换之后的文件为xxx_gtFine_instanceTrainIds.png,然后才能将其用于instance-level的训练。
对于pixel-level的任务,同样也不能直接使用xxx_gtFine_labelIds.png作为标记,这里面的灰度值代表cityscapes对每个label进行的编号,也就是绝对编号,而其中很多label并不会用在训练和最后的val之中,比如天空等,所以也需要对这些编号进行转换,可以利用citycapesscripts里面的createTrainIdLabelImgs函数,将其转换为xxx_gtFine_labelTrainIds.png,这里面每个像素对应的灰度值是一个临时编号,包含-1,0->18,255的编号,其中-1和255的编号都不会在val里面被检测,所以可以将二者归类为19编号,即最后训练的编号变成了0-19这20类label,因此一共进行分类的类别有20种。需要注意的是,如果要提交结果到cityscapes的benchmark上,那么必须将这些分类转换为绝对编号再上传,各种编号与颜色之间的对应关系可以在citycapesscripts中的labels.py文件中找到,其中的trainId也就相当于拿来做pixel-level segmentation训练的临时编号。
| name | id | trainId | category | catId | hasInstances | ignoreInEval | color |
|---|---|---|---|---|---|---|---|
| unlabeled | 0 | 255 | void | 0 | False | True | (0, 0, 0) |
| ego vehicle | 1 | 255 | void | 0 | False | True | (0, 0, 0) |
| rectification border | 2 | 255 | void | 0 | False | True | (0, 0, 0) |
| out of roi | 3 | 255 | void | 0 | False | True | (0, 0, 0) |
| static | 4 | 255 | void | 0 | False | True | (0, 0, 0) |
| dynamic | 5 | 255 | void | 0 | False | True | (111, 74, 0) |
| ground | 6 | 255 | void | 0 | False | True | (81, 0, 81) |
| road | 7 | 0 | flat | 1 | False | False | (128, 64, 128) |
| sidewalk | 8 | 1 | flat | 1 | False | False | (244, 35, 232) |
| parking | 9 | 255 | flat | 1 | False | True | (250, 170, 160) |
| rail track | 10 | 255 | flat | 1 | False | True | (230, 150, 140) |
| building | 11 | 2 | construction | 2 | False | False | (70, 70, 70) |
| wall | 12 | 3 | construction | 2 | False | False | (102, 102, 156) |
| fence | 13 | 4 | construction | 2 | False | False | (190, 153, 153) |
| guard rail | 14 | 255 | construction | 2 | False | True | (180, 165, 180) |
| bridge | 15 | 255 | construction | 2 | False | True | (150, 100, 100) |
| tunnel | 16 | 255 | construction | 2 | False | True | (150, 120, 90) |
| pole | 17 | 5 | object | 3 | False | False | (153, 153, 153) |
| polegroup | 18 | 255 | object | 3 | False | True | (153, 153, 153) |
| traffic light | 19 | 6 | object | 3 | False | False | (250, 170, 30) |
| traffic sign | 20 | 7 | object | 3 | False | False | (220, 220, 0) |
| vegetation | 21 | 8 | nature | 4 | False | False | (107, 142, 35) |
| terrain | 22 | 9 | nature | 4 | False | False | (152, 251, 152) |
| sky | 23 | 10 | sky | 5 | False | False | (70, 130, 180) |
| person | 24 | 11 | human | 6 | True | False | (220, 20, 60) |
| rider | 25 | 12 | human | 6 | True | False | (255, 0, 0) |
| car | 26 | 13 | vehicle | 7 | True | False | (0, 0, 142) |
| truck | 27 | 14 | vehicle | 7 | True | False | (0, 0, 70) |
| bus | 28 | 15 | vehicle | 7 | True | False | (0, 60, 100) |
| caravan | 29 | 255 | vehicle | 7 | True | True | (0, 0, 90) |
| trailer | 30 | 255 | vehicle | 7 | True | True | (0, 0, 110) |
| train | 31 | 16 | vehicle | 7 | True | False | (0, 80, 100) |
| motorcycle | 32 | 17 | vehicle | 7 | True | False | (0, 0, 230) |
| bicycle | 33 | 18 | vehicle | 7 | True | False | (119, 11, 32) |
| license plate | -1 | -1 | vehicle | 7 | False | True | (0, 0, 142) |
Cityscapes中的类别标记