diff --git a/docs/data_prepare.md b/docs/data_prepare.md index 50864a730a534c4a0e5eba84fb11dfb1bb9c542d..89f036f81588d1fa1b6fe833aad58e078873f10a 100644 --- a/docs/data_prepare.md +++ b/docs/data_prepare.md @@ -2,6 +2,42 @@ ## 数据标注 +### 标注协议 +PaddleSeg采用单通道的标注图片,每一种像素值代表一种类别,类别从0开始,例如0,1,2,3表示有4种类别。 + +一般的分割库使用单通道灰度图作为标注图片,往往显示出来是全黑的效果。灰度标注图的弊端: +1. 对图像标注后,无法直接观察标注是否正确。 +2. 模型测试过程无法直接判断分割的实际效果。 + +**PaddleSeg支持伪彩色图作为标注图片,在原来的单通道图片基础上,注入调色板。在基本不增加图片大小的基础上,却可以显示出彩色的效果。** + +同时PaddleSeg也兼容灰度图标注,用户原来的灰度数据集可以不做修改,直接使用。 +![](./imgs/annotation/image-11.png) + +### 灰度标注转换为伪彩色标注 +如果用户需要转换成伪彩色标注图,可使用我们的转换工具。适用于以下两种常见的情况: +1. 从指定灰度标注所在的目录读取标注图片 +```buildoutcfg +python pdseg/tools/gray2pseudo_color.py +``` + +|参数|用途| +|-|-| +|dir_or_file|指定灰度标注所在目录| +|output_dir|彩色标注图片的输出目录| + +2. 从已有文件列表中读取标注图片 +```buildoutcfg +python pdseg/tools/gray2pseudo_color.py --dataset_dir --file_separator +``` +|参数|用途| +|-|-| +|dir_or_file|指定文件列表路径| +|output_dir|彩色标注图片的输出目录| +|--dataset_dir|数据集所在根目录| +|--file_separator|文件列表分隔符| + +### 标注教程 用户需预先采集好用于训练、评估和测试的图片,然后使用数据标注工具完成数据标注。 PddleSeg已支持2种标注工具:LabelMe、精灵数据标注工具。标注教程如下: diff --git a/docs/imgs/annotation/image-11.png b/docs/imgs/annotation/image-11.png new file mode 100644 index 0000000000000000000000000000000000000000..2e3b6ff1f1ffd33fb57a35b547bcce31ca248e19 Binary files /dev/null and b/docs/imgs/annotation/image-11.png differ diff --git a/pdseg/__init__.py b/pdseg/__init__.py index 7f051e1e16ed29046c6ea46e341d62e4280f412d..5a1851ecb5fc0575deb449110d69da3087282719 100644 --- a/pdseg/__init__.py +++ b/pdseg/__init__.py @@ -14,3 +14,4 @@ # limitations under the License. import models import utils +import tools \ No newline at end of file diff --git a/pdseg/tools/gray2pseudo_color.py b/pdseg/tools/gray2pseudo_color.py index b385049172c4b134aca849682cbf76193c569f62..59555783436a6ef49aa038b3e467730746f0aa59 100644 --- a/pdseg/tools/gray2pseudo_color.py +++ b/pdseg/tools/gray2pseudo_color.py @@ -8,7 +8,6 @@ import os.path as osp import sys import numpy as np from PIL import Image -from pdseg.vis import get_color_map_list def parse_args(): @@ -26,6 +25,28 @@ def parse_args(): return parser.parse_args() +def get_color_map_list(num_classes): + """ Returns the color map for visualizing the segmentation mask, + which can support arbitrary number of classes. + Args: + num_classes: Number of classes + Returns: + The color map + """ + color_map = num_classes * [0, 0, 0] + for i in range(0, num_classes): + j = 0 + lab = i + while lab: + color_map[i * 3] |= (((lab >> 0) & 1) << (7 - j)) + color_map[i * 3 + 1] |= (((lab >> 1) & 1) << (7 - j)) + color_map[i * 3 + 2] |= (((lab >> 2) & 1) << (7 - j)) + j += 1 + lab >>= 3 + + return color_map + + def gray2pseudo_color(args): """将灰度标注图片转换为伪彩色图片""" input = args.dir_or_file diff --git a/pdseg/tools/jingling2seg.py b/pdseg/tools/jingling2seg.py index 9c1d663685cb357017387c54ed25115e6117408e..28bce3b0436242f5174087c0852dde99a7878684 100644 --- a/pdseg/tools/jingling2seg.py +++ b/pdseg/tools/jingling2seg.py @@ -12,7 +12,7 @@ import numpy as np import PIL.Image import labelme -from pdseg.vis import get_color_map_list +from gray2pseudo_color import get_color_map_list def parse_args(): diff --git a/pdseg/tools/labelme2seg.py b/pdseg/tools/labelme2seg.py index be1c99ee32c249cda29fea3d628b707415bf8b23..6ae3ad3a50a6df750ce321d94b7235ef57dcf80b 100755 --- a/pdseg/tools/labelme2seg.py +++ b/pdseg/tools/labelme2seg.py @@ -12,7 +12,7 @@ import numpy as np import PIL.Image import labelme -from pdseg.vis import get_color_map_list +from gray2pseudo_color import get_color_map_list def parse_args(): diff --git a/pdseg/vis.py b/pdseg/vis.py index 9fc349a3876f2667f8cc86bc1b9556594acfa638..fc524d91c39e8927d1e31eff71ecd41ba83e14cf 100644 --- a/pdseg/vis.py +++ b/pdseg/vis.py @@ -34,6 +34,7 @@ from utils.config import cfg from reader import SegDataset from models.model_builder import build_model from models.model_builder import ModelPhase +from tools.gray2pseudo_color import get_color_map_list def parse_args(): @@ -73,28 +74,6 @@ def makedirs(directory): os.makedirs(directory) -def get_color_map_list(num_classes): - """ Returns the color map for visualizing the segmentation mask, - which can support arbitrary number of classes. - Args: - num_classes: Number of classes - Returns: - The color map - """ - color_map = num_classes * [0, 0, 0] - for i in range(0, num_classes): - j = 0 - lab = i - while lab: - color_map[i * 3] |= (((lab >> 0) & 1) << (7 - j)) - color_map[i * 3 + 1] |= (((lab >> 1) & 1) << (7 - j)) - color_map[i * 3 + 2] |= (((lab >> 2) & 1) << (7 - j)) - j += 1 - lab >>= 3 - - return color_map - - def to_png_fn(fn): """ Append png as filename postfix