PaddlePaddle / PaddleSeg

Easy-to-use image segmentation library with awesome pre-trained model zoo, supporting wide-range of practical tasks in Semantic Segmentation, Interactive Segmentation, Panoptic Segmentation, Image Matting, 3D Segmentation, etc.
https://arxiv.org/abs/2101.06175
Apache License 2.0
8.62k stars 1.68k forks source link

是否可以将语义分割数据集cityscapes和Camvid等数据集的预测时类别的custom_color的取值给出,使得预测的结果颜色与给的groundtruth一样。 #3343

Closed chongchongmao closed 7 months ago

chongchongmao commented 1 year ago

问题确认 Search before asking

需求描述 Feature Description

  1. 任务目标(请描述你正在做的项目是什么,如模型、论文、项目是什么?); 2. 需求场景(请描述你的项目中为什么需要用此功能); 3. 功能描述(请简单描述或设计这个功能)

是否愿意提交PR Are you willing to submit a PR?

shiyutang commented 1 year ago

这个在预测结果上palatte指定和gt一样就可以了,应该不难设置的。

HongminMu commented 1 year ago

因为论文需要,这个问题我解决了: 把 PaddleSeg\paddleseg\utils\visualize.py中的 get_color_map_list替换成如下即可:

def get_color_map_list(num_classes, custom_color=None): """ Returns the color map for visualizing the segmentation mask, which can support arbitrary number of classes.

Args:
    num_classes (int): Number of classes.
    custom_color (list, optional): Save images with a custom color map. Default: None, use paddleseg's default color map.

Returns:
    (list). The color map.
"""

# Cityscapes predefined colors for 19 classes
CITYSCAPES_PALETTE = [
    (128, 64, 128),
    (244, 35, 232),
    (70, 70, 70),
    (102, 102, 156),
    (190, 153, 153),
    (153, 153, 153),
    (250, 170, 30),
    (220, 220, 0),
    (107, 142, 35),
    (152, 251, 152),
    (70, 130, 180),
    (220, 20, 60),
    (255, 0, 0),
    (0, 0, 142),
    (0, 0, 70),
    (0, 60, 100),
    (0, 80, 100),
    (0, 0, 230),
    (119, 11, 32)
]

color_map = []

# First, use the custom color or Cityscapes palette
if custom_color:
    color_map.extend(custom_color)
else:
    color_map.extend(CITYSCAPES_PALETTE)

# Then, use the default way to generate rest of the colors
while len(color_map) < num_classes:
    idx = len(color_map)
    j = 0
    lab = idx
    r = 0
    g = 0
    b = 0
    while lab:
        r |= (((lab >> 0) & 1) << (7 - j))
        g |= (((lab >> 1) & 1) << (7 - j))
        b |= (((lab >> 2) & 1) << (7 - j))
        j += 1
        lab >>= 3
    color_map.append((r, g, b))

return [item for sublist in color_map for item in sublist][:num_classes * 3]
chongchongmao commented 1 year ago

感谢感谢

毛冲冲 @.***

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2023年08月29日 17:21 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [PaddlePaddle/PaddleSeg] 是否可以将语义分割数据集cityscapes和Camvid等数据集的预测时类别的custom_color的取值给出,使得预测的结果颜色与给的groundtruth一样。 (Issue #3343) |

因为论文需要,这个问题我解决了: 把 PaddleSeg\paddleseg\utils\visualize.py中的 get_color_map_list替换成如下即可:

def get_color_map_list(num_classes, custom_color=None): """ Returns the color map for visualizing the segmentation mask, which can support arbitrary number of classes.

Args: num_classes (int): Number of classes. custom_color (list, optional): Save images with a custom color map. Default: None, use paddleseg's default color map.

Returns: (list). The color map. """

Cityscapes predefined colors for 19 classes

CITYSCAPES_PALETTE = [ (128, 64, 128), (244, 35, 232), (70, 70, 70), (102, 102, 156), (190, 153, 153), (153, 153, 153), (250, 170, 30), (220, 220, 0), (107, 142, 35), (152, 251, 152), (70, 130, 180), (220, 20, 60), (255, 0, 0), (0, 0, 142), (0, 0, 70), (0, 60, 100), (0, 80, 100), (0, 0, 230), (119, 11, 32) ]

color_map = []

First, use the custom color or Cityscapes palette

if custom_color: color_map.extend(custom_color) else: color_map.extend(CITYSCAPES_PALETTE)

Then, use the default way to generate rest of the colors

while len(color_map) < num_classes: idx = len(color_map) j = 0 lab = idx r = 0 g = 0 b = 0 while lab: r |= (((lab >> 0) & 1) << (7 - j)) g |= (((lab >> 1) & 1) << (7 - j)) b |= (((lab >> 2) & 1) << (7 - j)) j += 1 lab >>= 3 color_map.append((r, g, b))

return [item for sublist in color_map for item in sublist][:num_classes * 3]

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

HongminMu commented 5 months ago

https://github.com/HongminMu/PaddleSeg/blob/main/visualize.py