本文主要是介绍【idd】——印度自动驾驶场景语义分割数据集(解析代码),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
语义分割,街景场景
简介
该数据集由安装在汽车上的前置摄像头获得的图像组成。这辆车在海德拉巴、班加罗尔等城市及其郊区行驶。图像大多是1080p分辨率,但也有一些图像是720p和其他分辨率。
我们的数据集标注有独特的标签,如广告牌、机动人力车、动物等。此外,我们亦会留意道路旁可能安全的驾驶区域。
数据集的标签被组织为4级层次结构。每个级别都给出了唯一的整数标识符。如下图所示:
y轴上每个标签的像素数。
四个级别的标签层次结构和中间级别(级别2,级别3)的标签id。
将用于预测和地面真实掩模的颜色编码分别对应于相应的掩模。
例子
输入图像的一些例子,基线cityscape预训练模型的预测,在这个数据集上训练的相同基线的预测,以及验证集的基本事实(按列顺序),可以在下面看到。
可以看到,在我们的数据集上训练的模型清楚地将道路旁的泥泞可行驶区域与道路本身区分开来。我们的数据集有广告牌和道路中间的路边/中间的标签。此外,我们的图像帧来自非结构化的驾驶设置,道路泥泞,车道弟子不常遵循,道路上有大量的车辆。
语义label的解析
参考:semantic-segmentation-indian-driving-dataset
code:
import os
import cv2
import sys
import jsonimport numpy as np
import skimage.io as iofrom skimage.draw import polygon
from skimage import img_as_float# %%
root = './anue/'
root = 'D:/19segmentation/idd-20k-II/idd20kIID/19segmentation/idd-20k-II/idd20kII'# %% [markdown]
# # Get all labels in the dataset as a dictionary# %%
def get_all_labels(root):labels = []final_labels = {}img_folder, segmap_folder = os.listdir(root)# sub_path_train_img = os.path.join(root, img_folder, './train')sub_path_train_seg = os.path.join(root, segmap_folder, './train')# sub_path_val_img = os.path.join(root, img_folder, './val')sub_path_val_seg = os.path.join(root, segmap_folder, './val')# extract training labelsfor folder in os.listdir(sub_path_train_seg):
# curr_img_folder = os.path.join(sub_path_train_img, folder)curr_seg_folder = os.path.join(sub_path_train_seg, folder)for file in os.listdir(curr_seg_folder):if 'json' not in file:continuef = open(os.path.join(curr_seg_folder, file), 'r')data = json.loads(f.read())for obj in data['objects']:if obj['label'] not in labels:labels.append(obj['label'])# extract validation labelsfor folder in os.listdir(sub_path_val_seg):
# curr_img_folder = os.path.join(sub_path_val_img, folder)curr_seg_folder = os.path.join(sub_path_val_seg, folder)for file in os.listdir(curr_seg_folder):if 'json' not in file:continuef = open(os.path.join(curr_seg_folder, file), 'r')data = json.loads(f.read())for obj in data['objects']:if obj['label'] not in labels:labels.append(obj['label'])for i in range(len(labels)):final_labels[labels[i]] = ireturn final_labels# %%
labels = get_all_labels(root)# %%
labels# %% [markdown]
# # Generate Segmentation Maps# %%
def create_segmentation_maps(root, labels):img_folder, segmap_folder = os.listdir(root)if not os.path.exists('./img'):os.makedirs('img')if not os.path.exists('./img/train'):os.makedirs('img/train')if not os.path.exists('./img/val'):os.makedirs('img/val')if not os.path.exists('./seg'):os.makedirs('seg')if not os.path.exists('./seg/train'):os.makedirs('seg/train')if not os.path.exists('./seg/val'):os.makedirs('seg/val')sub_path_train_img = os.path.join(root, img_folder, './train')sub_path_train_seg = os.path.join(root, segmap_folder, './train')sub_path_val_img = os.path.join(root, img_folder, './val')sub_path_val_seg = os.path.join(root, segmap_folder, './val')for folder in os.listdir(sub_path_train_seg):curr_img_folder = os.path.join(sub_path_train_img, folder)curr_seg_folder = os.path.join(sub_path_train_seg, folder)for file in os.listdir(curr_img_folder):id = file.split('_')[0]img = cv2.imread(os.path.join(curr_img_folder, file))f = open(os.path.join(curr_seg_folder, id+'_gtFine_polygons.json'), 'r')data = json.loads(f.read())seg_map = np.zeros((data['imgWidth'],data['imgHeight']))for obj in data['objects']:label = obj['label']poly = np.array(obj['polygon'])rr, cc = polygon(poly[:,0], poly[:,1], seg_map.shape)seg_map[rr,cc] = labels[label]cv2.imwrite('./img/train/'+id+'.png', img)cv2.imwrite('./seg/train/'+id+'.png', seg_map.T)for folder in os.listdir(sub_path_val_seg):curr_img_folder = os.path.join(sub_path_val_img, folder)curr_seg_folder = os.path.join(sub_path_val_seg, folder)for file in os.listdir(curr_img_folder):id = file.split('_')[0]img = cv2.imread(os.path.join(curr_img_folder, file))f = open(os.path.join(curr_seg_folder, id+'_gtFine_polygons.json'), 'r')data = json.loads(f.read())seg_map = np.zeros((data['imgWidth'],data['imgHeight']), np.uint8)for obj in data['objects']:label = obj['label']poly = np.array(obj['polygon'])rr, cc = polygon(poly[:,0], poly[:,1], seg_map.shape)seg_map[rr,cc] = labels[label]cv2.imwrite('./img/val/'+id+'.png', img)cv2.imwrite('./seg/val/'+id+'.png', seg_map.T)# %%
create_segmentation_maps(root, labels)
解析出来可视化的例子
语义标签
共39个类别, 类别仅供参考
这篇关于【idd】——印度自动驾驶场景语义分割数据集(解析代码)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!