语义分割数据集介绍——Camvid和Cityscapes介绍

Camvid数据集介绍

在这里插入图片描述

官方下载地址

http://mi.eng.cam.ac.uk/research/projects/VideoRec/CamVid/

概述

CamVid全称: Cambridge-driving Labeled Video Database
CamVid 数据集是由剑桥大学公开发布的城市道路场景的数据集,它包括 701 张精准标注的图片用于语义分割,如果要使用CamVid数据集做目标检测,就需要bbox标签,
数据集包括 701 张精准标注的图片用于语义分割模型训练,可分为训练集、验证集、测试集。
类别占比
在这里插入图片描述

数据库提供32个ground truth语义标签,各个类别占比如下图:

在这里插入图片描述
Camvid 语义标签为RGB图片,各个类别对应的颜色name_color_dict如下:

name_color_dict={ 'Animal': [64, 128, 64], 
                  'Archway': [192, 0, 128], 
                  'Bicyclist': [0, 128, 192], 
                  'Bridge': [0, 128, 64],
                  'Building': [128, 0, 0], 
                  'Car': [64, 0, 128], 
                  'CartLuggagePram': [64, 0, 192], 
                  'Child': [192, 128, 64],
                  'Column_Pole': [192, 192, 128], 
                  'Fence': [64, 64, 128], 
                  'LaneMkgsDriv': [128, 0, 192],
                  'LaneMkgsNonDriv': [192, 0, 64], 
                  'Misc_Text': [128, 128, 64], 
                  'MotorcycleScooter': [192, 0, 192],
                  'OtherMoving': [128, 64, 64], 
                  'ParkingBlock': [64, 192, 128], 
                  'Pedestrian': [64, 64, 0], 
                  'Road': [128, 64, 128],
                  'RoadShoulder': [128, 128, 192], 
                  'Sidewalk': [0, 0, 192], 
                  'SignSymbol': [192, 128, 128], 
                  'Sky': [128, 128, 128],
                  'SUVPickupTruck': [64, 128, 192], 
                  'TrafficCone': [0, 0, 64], 
                  'TrafficLight': [0, 64, 64], 
                  'Train': [192, 64, 128],
                  'Tree': [128, 128, 0], 
                  'Truck_Bus': [192, 128, 192], 
                  'Tunnel': [64, 0, 64], 
                  'VegetationMisc': [192, 192, 0],
                  'Void': [0, 0, 0], 
                  'Wall': [64, 192, 0],
                 }

语义标签转成bbox标签

选择需要提取的类别 names = [‘Pedestrian’, ‘Car’, ‘Truck_Bus’],根据 camvid 语义分割标签结果提取目标检测bbox标签的代码如下:

import cv2
import torch
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt

def mask_to_2D(label):
    """ return: semantic_map -> [H, W] """
    color_list = list(name_color_dict.values())
    semantic_map = np.zeros(label.shape[:-1])
    for index, color in enumerate(color_list):
        equality = np.equal(label, color)
        class_map = np.all(equality, axis=-1)
        semantic_map[class_map] = index
    return semantic_map

def draw_box(img, boxes, colors):
    """ plots one bounding box on image img """
    for box, color in zip(boxes, colors):
        cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), color, thickness=2, lineType=cv2.LINE_AA)
    plt.imshow(img)
    plt.axis('off')
    plt.show()

def get_bbox(label_file, names):
    """ get bbox from semantic label """
    # convert RGB mask to 2D mask
    mask = np.array(Image.open(label_file))
    mask_2D = mask_to_2D(mask)
    mask_to_save = np.zeros_like(mask_2D)
    # instances are encoded as different colors
    obj_ids = np.unique(mask_2D)
    # split the color-encoded mask into a set of binary masks
    masks = mask_2D == obj_ids[:, None, None]
    # get bounding box coordinates for each mask
    num_objs = len(obj_ids)
    boxes, colors = [], []
    for i in range(num_objs):
        id = obj_ids[i]
        name = list(name_color_dict.keys())[int(id)]
        if name in names:
            binary = masks[i].astype(np.int8)
            num_labels, labels = cv2.connectedComponents(binary, connectivity=8, ltype=cv2.CV_16U)
            for id_label in range(1, num_labels):
                temp_mask = labels == id_label
                pos = np.where(temp_mask)
                xmin = np.min(pos[1])
                xmax = np.max(pos[1])
                ymin = np.min(pos[0])
                ymax = np.max(pos[0])
                 # filter result by setting threshold of width and hegith: 20
                if (xmax - xmin) > 20 and (ymax - ymin) > 20:
                    boxes.append([xmin, ymin, xmax, ymax])
                    color = list(name_color_dict.values())[int(id)]
                    colors.append(color)
                    mask_to_save[pos] = id_label

    # draw mask and bbox
    draw_box(mask, boxes, colors)


if __name__ == '__main__':
    names = ['Pedestrian', 'Car', 'Truck_Bus']
    label_file = "camvid/labels/0001TP_006690_L.png"
    label = np.array(Image.open(label_file))
    get_bbox(label_file, names)

得到bbox标签之后,就可以使用camvid数据集同时做语义分割和目标检测了。

Cityscapes数据集

官方下载地址

https://www.cityscapes-dataset.com/

概述

Cityscapes数据集简单介绍:
城市街景数据集 Cityscapes 收集了来自 50 个不同城市、良好天气条件下的街景,共包含 5000 张高分辨率(1024x2048)图像。其中 3475 张带标注的图像用于训练和验证(2975 张用于训练,500 张用于验证),1525 张未标注图像用于测试。此外,数据集中还提供了 20000 张弱标注图像供研究使用。该数据集涵盖 30 多种类别,主要包括城市街景中的车辆、行人、建筑物、道路等常见物体和场景。

参考

1、Cityscapes数据集:如何将像素级的多边形标注的分割数据标注转为目标检测的bbox标注
2、目标检测: Camvid 语义标签转化为bbox标签

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翟羽嚄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值