cityscapes数据集配一个cityscapesscripts工具。该工具内有定义自己类别数的实现文件。

例如不想要这么多类的语义分割,先修改labels.py文件,把想注释掉的类别的trainId修改为255,ignoreInEval修改为True。然后运行createTrainIdLabelImgs.py。这个文件读取json文件的多边形,将多边形区域设置为trainId的值。输出文件为类似

其中白色就是255 暗色就是各个类别的trainid值。

很遗憾,没安明白。又搜到了下面的方法,也可以实现生成上面标注图的功能。

第一步首先要找到数据集label颜色对应类别的列表:(这个一般在官网或者是github上会有,cityscapes我就是从github上找的)

Label = namedtuple('Label', ['name', 'id', 'trainId', 'category', 'categoryId', 'hasInstances', 'ignoreInEval', 'color'])labels = [#       name                     id    trainId   category            catId     hasInstances   ignoreInEval   colorLabel(  'unlabeled'            ,  0 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'ego vehicle'          ,  1 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'rectification border' ,  2 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'out of roi'           ,  3 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'static'               ,  4 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'dynamic'              ,  5 ,      255 , 'void'            , 0       , False        , True         , (111, 74,  0) ),Label(  'ground'               ,  6 ,      255 , 'void'            , 0       , False        , True         , ( 81,  0, 81) ),Label(  'road'                 ,  7 ,        1 , 'flat'            , 1       , False        , False        , (128, 64,128) ),Label(  'sidewalk'             ,  8 ,        2 , 'flat'            , 1       , False        , False        , (244, 35,232) ),Label(  'parking'              ,  9 ,      255 , 'flat'            , 1       , False        , True         , (250,170,160) ),Label(  'rail track'           , 10 ,      255 , 'flat'            , 1       , False        , True         , (230,150,140) ),Label(  'building'             , 11 ,        3 , 'construction'    , 2       , False        , False        , ( 70, 70, 70) ),Label(  'wall'                 , 12 ,        4 , 'construction'    , 2       , False        , False        , (102,102,156) ),Label(  'fence'                , 13 ,        5 , 'construction'    , 2       , False        , False        , (190,153,153) ),Label(  'guard rail'           , 14 ,      255 , 'construction'    , 2       , False        , True         , (180,165,180) ),Label(  'bridge'               , 15 ,      255 , 'construction'    , 2       , False        , True         , (150,100,100) ),Label(  'tunnel'               , 16 ,      255 , 'construction'    , 2       , False        , True         , (150,120, 90) ),Label(  'pole'                 , 17 ,        6 , 'object'          , 3       , False        , False        , (153,153,153) ),Label(  'polegroup'            , 18 ,      255 , 'object'          , 3       , False        , True         , (153,153,153) ),Label(  'traffic light'        , 19 ,        7 , 'object'          , 3       , False        , False        , (250,170, 30) ),Label(  'traffic sign'         , 20 ,        8 , 'object'          , 3       , False        , False        , (220,220,  0) ),Label(  'vegetation'           , 21 ,        9 , 'nature'          , 4       , False        , False        , (107,142, 35) ),Label(  'terrain'              , 22 ,       10 , 'nature'          , 4       , False        , False        , (152,251,152) ),Label(  'sky'                  , 23 ,       11 , 'sky'             , 5       , False        , False        , ( 70,130,180) ),Label(  'person'               , 24 ,       12 , 'human'           , 6       , True         , False        , (220, 20, 60) ),Label(  'rider'                , 25 ,       13 , 'human'           , 6       , True         , False        , (255,  0,  0) ),Label(  'car'                  , 26 ,       14 , 'vehicle'         , 7       , True         , False        , (  0,  0,142) ),Label(  'truck'                , 27 ,       15 , 'vehicle'         , 7       , True         , False        , (  0,  0, 70) ),Label(  'bus'                  , 28 ,       16 , 'vehicle'         , 7       , True         , False        , (  0, 60,100) ),Label(  'caravan'              , 29 ,      255 , 'vehicle'         , 7       , True         , True         , (  0,  0, 90) ),Label(  'trailer'              , 30 ,      255 , 'vehicle'         , 7       , True         , True         , (  0,  0,110) ),Label(  'train'                , 31 ,       17 , 'vehicle'         , 7       , True         , False        , (  0, 80,100) ),Label(  'motorcycle'           , 32 ,       18 , 'vehicle'         , 7       , True         , False        , (  0,  0,230) ),Label(  'bicycle'              , 33 ,       19 , 'vehicle'         , 7       , True         , False        , (119, 11, 32) ),Label(  'license plate'        , -1 ,       -1 , 'vehicle'         , 7       , False        , True         , (  0,  0,142) ),
]

第二步,把labels的标注读到一个color2index字典当中:

    color2index = {}color2index[(0, 0, 0)] = 0  # add an void classfor obj in labels:if obj.ignoreInEval:continueidx = obj.trainIdlabel = obj.namecolor = obj.colorcolor2index[color] = idxprint(color2index)

第三步,读入label图片,然后把图片中每个像素的RGB值跟color2index字典对比,相同的则记录下color2index里该RGB值的索引index

完整代码:

import numpy as np
import scipy.misc
from collections import namedtuple
np.set_printoptions(threshold=np.inf)
Label = namedtuple('Label', ['name','id','trainId','category','categoryId','hasInstances','ignoreInEval','color'])labels = [#       name                     id    trainId   category            catId     hasInstances   ignoreInEval   colorLabel(  'unlabeled'            ,  0 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'ego vehicle'          ,  1 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'rectification border' ,  2 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'out of roi'           ,  3 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'static'               ,  4 ,      255 , 'void'            , 0       , False        , True         , (  0,  0,  0) ),Label(  'dynamic'              ,  5 ,      255 , 'void'            , 0       , False        , True         , (111, 74,  0) ),Label(  'ground'               ,  6 ,      255 , 'void'            , 0       , False        , True         , ( 81,  0, 81) ),Label(  'road'                 ,  7 ,        1 , 'flat'            , 1       , False        , False        , (128, 64,128) ),Label(  'sidewalk'             ,  8 ,        2 , 'flat'            , 1       , False        , False        , (244, 35,232) ),Label(  'parking'              ,  9 ,      255 , 'flat'            , 1       , False        , True         , (250,170,160) ),Label(  'rail track'           , 10 ,      255 , 'flat'            , 1       , False        , True         , (230,150,140) ),Label(  'building'             , 11 ,        3 , 'construction'    , 2       , False        , False        , ( 70, 70, 70) ),Label(  'wall'                 , 12 ,        4 , 'construction'    , 2       , False        , False        , (102,102,156) ),Label(  'fence'                , 13 ,        5 , 'construction'    , 2       , False        , False        , (190,153,153) ),Label(  'guard rail'           , 14 ,      255 , 'construction'    , 2       , False        , True         , (180,165,180) ),Label(  'bridge'               , 15 ,      255 , 'construction'    , 2       , False        , True         , (150,100,100) ),Label(  'tunnel'               , 16 ,      255 , 'construction'    , 2       , False        , True         , (150,120, 90) ),Label(  'pole'                 , 17 ,        6 , 'object'          , 3       , False        , False        , (153,153,153) ),Label(  'polegroup'            , 18 ,      255 , 'object'          , 3       , False        , True         , (153,153,153) ),Label(  'traffic light'        , 19 ,        7 , 'object'          , 3       , False        , False        , (250,170, 30) ),Label(  'traffic sign'         , 20 ,        8 , 'object'          , 3       , False        , False        , (220,220,  0) ),Label(  'vegetation'           , 21 ,        9 , 'nature'          , 4       , False        , False        , (107,142, 35) ),Label(  'terrain'              , 22 ,       10 , 'nature'          , 4       , False        , False        , (152,251,152) ),Label(  'sky'                  , 23 ,       11 , 'sky'             , 5       , False        , False        , ( 70,130,180) ),Label(  'person'               , 24 ,       12 , 'human'           , 6       , True         , False        , (220, 20, 60) ),Label(  'rider'                , 25 ,       13 , 'human'           , 6       , True         , False        , (255,  0,  0) ),Label(  'car'                  , 26 ,       14 , 'vehicle'         , 7       , True         , False        , (  0,  0,142) ),Label(  'truck'                , 27 ,       15 , 'vehicle'         , 7       , True         , False        , (  0,  0, 70) ),Label(  'bus'                  , 28 ,       16 , 'vehicle'         , 7       , True         , False        , (  0, 60,100) ),Label(  'caravan'              , 29 ,      255 , 'vehicle'         , 7       , True         , True         , (  0,  0, 90) ),Label(  'trailer'              , 30 ,      255 , 'vehicle'         , 7       , True         , True         , (  0,  0,110) ),Label(  'train'                , 31 ,       17 , 'vehicle'         , 7       , True         , False        , (  0, 80,100) ),Label(  'motorcycle'           , 32 ,       18 , 'vehicle'         , 7       , True         , False        , (  0,  0,230) ),Label(  'bicycle'              , 33 ,       19 , 'vehicle'         , 7       , True         , False        , (119, 11, 32) ),Label(  'license plate'        , -1 ,       -1 , 'vehicle'         , 7       , False        , True         , (  0,  0,142) ),
]if __name__ =='__main__':color2index = {}color2index[(0, 0, 0)] = 0  # add an void classfor obj in labels:if obj.ignoreInEval:continueidx = obj.trainIdlabel = obj.namecolor = obj.colorcolor2index[color] = idxprint(color2index)img = r'F:\dataset\cityspaces\gtFine\train\aachen\aachen_000002_000019_gtFine_color.png'img = scipy.misc.imread(img, mode='RGB')height, weight, _ = img.shapel = []idx_mat = np.zeros((height, weight))for h in range(height):for w in range(weight):color = tuple(img[h, w])#print(color)# print(color)try:index = color2index[color]idx_mat[h, w] = indexif index not in l:l.append(index)except:# no index, assign to voididx_mat[h, w] = 0idx_mat = idx_mat.astype(np.uint8)print(l)  #打印出现过的索引(类别)

例子:

输入图片:

输出:

这表示label图片里有多少类别

但是如果输出idx_max则是把图片的像素值全换成index值了,也就是0~19的数字(共20个类)

如:

cityscapes数据集具体使用方法相关推荐

  1. Dataset之Cityscapes:Cityscapes数据集的简介、安装、使用方法之详细攻略

    Dataset之Cityscapes:Cityscapes数据集的简介.安装.使用方法之详细攻略 目录 Cityscapes数据集的简介 1.Cityscapes数据集的特点 2.Cityscapes ...

  2. cityscapes场景图_Dataset之Cityscapes:Cityscapes数据集的简介、安装、使用方法之详细攻略...

    Dataset之Cityscapes:Cityscapes数据集的简介.安装.使用方法之详细攻略 目录 Cityscapes数据集的简介 1.Cityscapes数据集的特点 2.Cityscapes ...

  3. cityscapes场景图_图像语意分割训练Cityscapes数据集SegNet-ConvNet神经网络详解

    版权声明:本文首发于本人CSDN博客. 前言:经过将近一个月的陆续学习研究,在神经网络中训练多分类任务识别Cityscapes数据集,终于在最近得到了理想中的实验结果.在我陷入对细节参数调整不当及诸多 ...

  4. Cityscapes数据集的深度完整解析

    cityscapes数据集是分割模型训练时比较常用的一个数据集,他还可以用来训练GAN网络生成街景图片. 数据集下载和文件夹组成: - 整个数据集包含50个欧洲城市,5000张精细标注图像(标注位于g ...

  5. 无人驾驶常用数据集---图像语义分割数据集--Cityscapes数据集的解读(for 小白)

    ** 无人驾驶常用数据集–图像语义分割数据集–Cityscapes数据集的解读(for 小白) ** 一.什么是Cityscapes数据集? Cityscapes是关于城市街道场景的语义理解图片数据集 ...

  6. 数据集的使用方法和技巧

    数据集的使用方法和技巧 数据集概述 1.1数据集 l         是一种代表关系数据的内存驻留结构 l         是以XML 形式表示的数据视图,是一种数据关系视图. l         在 ...

  7. 语义分割之VOC2012、Cityscapes数据集介绍

    PASCAL-VOC2012 PASCAL-VOC2012数据集介绍官网: 参考 数据集下载地址:http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCt ...

  8. 小样本点云深度学习库_基于点云深度学习的点云数据集制作系统及方法与流程...

    本发明涉及测控技术领域,尤其涉及一种基于点云深度学习的点云数据集制作系统及方法. 背景技术: 深度学习网络模型一般都是基于64线单帧激光数据集进行.但64线激光器和单帧的限定,造成了工程应用中点云数据 ...

  9. 【工程测试与训练】使用BiSeNetv2测试、训练cityscapes数据集、训练自己的数据集

    1 准备工作 下载工程 工程下载:https://github.com/CoinCheung/BiSeNet 预训练模型下载: 工程下载后解压,并在其中创建文件夹[MODEL]用于存放预训练模型   ...

最新文章

  1. 2022-2028年中国盲盒行业市场研究及前瞻分析报告
  2. python中的装饰器有哪些-python中的装饰器详解
  3. Java多线程:捕获线程异常
  4. 基于asp.net + easyui框架,一步步学习easyui-datagrid——界面(一)
  5. 试着理解cookie和session
  6. MySQ软件的卸载-通过控制面板方式
  7. JavaScript数组sort方法(数组排序)
  8. 7-7 硬币找钱问题 (10 分)(思路+详解+double类型数据的处理)Come baby!!!!!!!!!!!!!!!!!!!!
  9. 【汇编语言学习之路】第一章 汇编语言核心方法论
  10. oracle19c xp安装 客户端_windows下安装oracle19c
  11. Cocos2dx技术(三)——cocos2dx基本概念(六)控件库
  12. android助手最新版本,Android 开发助手功能及版本介绍
  13. mbedtls 探索
  14. [笑话]1+1等于几?(新版)
  15. 相似的核心玩法之下,谁能在“自走棋”的路上走得更远?
  16. 多元线性回归分析spss结果解读_多重线性回归分析SPSS操作与解读
  17. 新浪微博分享出现libc++abi.dylib: terminating with uncaught exception of type NSException微博微信SDK运行编译报错
  18. python - 啃书 第八章 正则表达式
  19. AMiner论文推荐:
  20. 减治法(Decrease and Conquer)

热门文章

  1. excel中提取箱单中的箱数
  2. Maven基础:在Eclipse直接使用maven
  3. 思科计算机网络第七章7.4.1.2,计算机网络安全技术与实施(旧) 思科网络学院CCNA Security资源 CCNA安全第7章实验1_Explor-Encrypt_教师实验手册.doc...
  4. termux怎么生成木马_metasploit 生成木马常用命令
  5. Vision Transformer(iGPT,ViT,DERT,IPT,TransReID,TransGAN,TNT,CvT)
  6. 美团新一代渠道包打包神器walle
  7. RK3399处理器性能介绍
  8. 2022-2027年中国现代通信网络行业市场调研及未来发展趋势预测报告
  9. 电力电子技术(9)——单相可控整流电路
  10. 《CWNA官方学习指南(第3版):认证无线网络管理员PW0-105》