为了训练自己的车道线检测模型,由于tusimple数据集场景较为单一,因此自己标注了一个数据集
模型:lanenet
数据集格式:tusimple
标注工具:labelme
1、使用labelme进行数据标注
使用指令进行安装labelme
pip install labelme
2、在环境下使用指令进行启动labelme
labelme
3、进入界面后选择图片,右键选择Create lineStrip选项进行线段标记
1、使用指令将json文件转换成标记数据
labelme_json_to_dataset ****.json
转换后会生成如下的文件:
2、批量处理需要编写相应的脚本文件:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
if __name__ == '__main__':
path = "./images"
for scan_dir in ['night_drive_merchandise']:
json_data = os.path.join(path, scan_dir+'/annotations')
for name in os.listdir(json_data):
file_path = os.path.join(json_data, name)
os.system(str("labelme_json_to_dataset " + file_path))
print("success json to dataset: ", file_path)
1、按照tusimple数据集格式需要生成如下几个文件
gt_binary_image、gt_image、gt_instance_image例图如下:
2、由于转换的数据不包含gt_binary_image和gt_instance_image的内容,需要自己编写脚本进行转换:
import cv2
from skimage import measure, color
from skimage.measure import regionprops
import numpy as np
import os
import copy
def skimageFilter(gray):
binary_warped = copy.copy(gray)
binary_warped[binary_warped > 0.1] = 255
gray = (np.dstack((gray, gray, gray))*255).astype('uint8')
labels = measure.label(gray[:, :, 0], connectivity=1)
dst = color.label2rgb(labels,bg_label=0, bg_color=(0,0,0))
gray = cv2.cvtColor(np.uint8(dst*255), cv2.COLOR_RGB2GRAY)
return binary_warped, gray
def moveImageTodir(path,targetPath,name):
if os.path.isdir(path):
image_name = "gt_image/"+str(name)+".png"
binary_name = "gt_binary_image/"+str(name)+".png"
instance_name = "gt_instance_image/"+str(name)+".png"
train_rows = image_name + " " + binary_name + " " + instance_name + "\n"
origin_img = cv2.imread(path+"/img.png")
origin_img = cv2.resize(origin_img, (1280,720))
cv2.imwrite(targetPath+"/"+image_name, origin_img)
img = cv2.imread(path+'/label.png')
img = cv2.resize(img, (1280,720))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
binary_warped, instance = skimageFilter(gray)
cv2.imwrite(targetPath+"/"+binary_name, binary_warped)
cv2.imwrite(targetPath+"/"+instance_name, instance)
print("success create data name is : ", train_rows)
return train_rows
return None
if __name__ == "__main__":
count = 1
with open("./train.txt", 'w+') as file:
for images_dir in os.listdir("./images"):
dir_name = os.path.join("./images", images_dir + "/annotations")
for annotations_dir in os.listdir(dir_name):
json_dir = os.path.join(dir_name, annotations_dir)
if os.path.isdir(json_dir):
train_rows = moveImageTodir(json_dir, "./", str(count).zfill(4))
file.write(train_rows)
count += 1
1、由于lanenet模型处理需要按照tusimple数据进行,首先需要将上一步处理的数据生成tfrecords格式
调用如下指令进行执行:
python data_provider/lanenet_data_feed_pipline.py --dataset_dir ../dataset/lane_detection_dataset/ --tfrecords_dir ../dataset/lane_detection_dataset/tfrecords
2、执行后会生成如下文件:
3、处理完成