Potsdam Dataset
ISPRS-Potsdam
The Potsdam dataset is for urban semantic segmentation used in the 2D Semantic Labeling Contest - Potsdam.
The dataset can be requested at the challenge homepage. You need to get a package file named utf-8' 'Potsdam.zip
(size: 13.3GB), and unzip this package to get a folder named Potsdam
which contains 10 files as follows:
1 | Potsdam |
where only 2_Ortho_RGB.zip
and 5_Labels_all.zip
are needed.
1 | Potsdam |
2_Ortho_RGB.zip 中的图片为 tif 格式,Windows 自带的各种图片工具都不能正常打开,使用 vscode 中 tif 插件,例如 TIFF Preview,可以查看 Potsdam 数据集的 tif 原图。此外 Potsdam 数据集的原图存在扭曲现象,这是数据集本身的问题,不是处理的失误。
Correspondence between colors and categories
1 | ''' |
注意如果使用的是 5_Labels_all_noBoundary.zip
作为标签,其包含了边界标注,对应的 color_map 会有所不同
1 | ''' |
Configuration
Use the code below to convert the original images (pixels 6000×6000) to patches (pixels 512×512)
In the 2_Ortho_RGB.zip
file, it contains 38 pictures of size 6000x6000:
In the default configuration, We assign the training, validation, and test sets as follows, 21 for training, 1 for validation and 14 for testing
1 | splits = { |
where there is a problem with the label images for 4_12 and 6_7, so we discard them.
And every picture will be seplited into 12x12=144 patches of size 512x512. There are (38-2)x144=5184=3024+144+2016 patches in total, in which 21 images / 3024 patches are used for training, 1 image / 144 patches for velidation and 14 images / 2016 patches for testing.
For an image with size 6000x6000 and patch_size 512, 6000 = 11×512+368 = 12×512-144, which are not divisible, we split 6000 with 512 as follows:
1 | x/ymin: [0, 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 4608, 5120, 5632] |
1 | 0~512, 512~(2*512), (2*512)~(3*512), ..., (10*512)~(11*512), (11*512-144)~(12*512-144) |
1 | +----------------------------------------------------------------------------------------+ |
Potsdam 数据集中的错误
错误来源于 potsdam 数据集本身的两张 label。第一张是 top_potsdam_6_7_label.tif
包含了错误的像素值
1 | from PIL import Image |
通过python统计 top_potsdam_6_7_label.tif 的像素输出结果如下
1 | # values |
输出中包含 2 个 list,上面的 list 为 rgb 颜色值,下面为各颜色对应的像素数。注意 6_7 包含了一类非正常的 rgb 值 [252, 255, 0],其中第一个值是 252 并非 255,这个 rgb 值在为像素打 label 时造成了错误,所以可以将这个 252 改成 255 即可。
第二张错误 label 是 top_potsdam_4_12_label.tif
,这张图片不正常,其像素标注值非常混乱
1 | from PIL import Image |
从输出结果可以看到,它包含 24850 种 RGB 颜色值,它的像素标签值非常混乱,我们将它舍去。
Split Code
Prepare Dataset: ISPRS-Potsdam | mmsegmentation doc
tools/dataset_converters/potsdam.py | mmsegmentation github
1 | potsdam |
1 | # ref: https://github.com/open-mmlab/mmsegmentation/blob/main/tools/dataset_converters/potsdam.py |
mmsegmentation potsdam.py 代码中的 color_map
源代码见链接 potsdam.py | github,下面的代码块是截取的 color_map 部分
mmsegmentation 源码中对 color_map 的设置为 BGR,与正常的 RGB 正好相反,这一点需要注意。
1 | # mmsegmentation 的 color_map 颜色顺序为 BGR |
mmsegmentation 之所以标注 BGR 的颜色顺序,应该是其 imread 和 imwrite 方法的底层调用了 cv2 的 imread 和 imwrite,或者模仿了它们的设计。这里可以参考一下这篇博客 cv2如何处理RGB和BGR | 文羊羽。
-
mmsegmentaion 的 color map, BGR
1
2
3
4
5
6
70: [ 0 0 0] : boundary
1: [255 255 255] : impervious surfaces
2: [255 0 0] : background
3: [255 255 0] : car
4: [ 0 255 0] : tree
5: [ 0 255 255] : low vegetation
6: [ 0 0 255] : building -
正常的 color map, RGB
1
2
3
4
5
6
70: [ 0 0 0] : boundary
1: [255 255 255] : impervious surfaces
2: [ 0 0 255] : building
3: [ 0 255 255] : low vegetation
4: [ 0 255 0] : tree
5: [255 255 0] : car
6: [255 0 0] : clutter/background