第四周的任务主要是对Ultra-fast-lane-detection的进一步探索,对于ultra-fast-lane-detection的训练,推理测速以及目标点选取,和tensorrt的学习。
数据集标注
首先是标注数据集,我选择了软件学院的道路进行拍照,收集了上百张图片进行标注。(后期由于图片数量不足,我先对网上给出的数据集进行了训练和测试,由于场地和模型选择都还没确定,因此我们先只是观察该模型的效果)
标注是使用labelme进行标注。该工具在标注的基础上生成json文件,而我们需要的是标注后的label照片。因此还需要我们自己编写脚本来根据json文件生成label实例掩膜图片
import argparse
import glob
import json
import os
import os.path as ops
import cv2
import numpy as np
def init_args():
parser = argparse.ArgumentParser()
parser.add_argument('--img_dir', type=str, help='The origin path of image')
parser.add_argument('--json_dir', type=str, help='The origin path of json')
return parser.parse_args()
def process_json_file(img_path, json_path, instance_dst_dir):
"""
:param img_path: 原始图像路径
:param json_path: 标签文件路径
:param instance_dst_dir:实例图像保存路径
:return:
"""
assert ops.exists(img_path), '{:s} not exist'.format(img_path)
image = cv2.imread(img_path, cv2.IMREAD_COLOR)
instance_image = np.zeros([image.shape[0], image.shape[1]], np.uint8)
with open(json_path, 'r',encoding='utf8') as file:
info_dict = json.load(file)
for ind,info in enumerate(info_dict['shapes']):
contours = info['points']
contours = np.array(contours,dtype=int)
# 绘制多边形
cv2.fillPoly(instance_image, [contours], (ind+1, ind+1, ind+1)) # * 50 + 20
instance_image_path = img_path.replace(os.path.dirname(img_path),instance_dst_dir)
cv2.imwrite(instance_image_path.replace('.jpg','.png'), instance_image) # 实例分割图像
# 训练库构建
def process_tusimple_dataset(img_dir,json_dir):
"""
:param json_dir: 标签文件路径
:param img_dir: 原始图像路径
:return:
"""
gt_instance_dir = ops.join(os.path.dirname(img_dir), 'label') # 与原始图片文件夹在同级父目录下
os.makedirs(gt_instance_dir, exist_ok=True)
for img_path in glob.glob('{:s}/*.jpg'.format(img_dir)):
286




被折叠的 条评论
为什么被折叠?



