Ultra Fast Structure-aware Deep Lane Detection的训练实战

2024-03-14 23:36

本文主要是介绍Ultra Fast Structure-aware Deep Lane Detection的训练实战,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Ultra Fast Structure-aware Deep Lane Detection的训练实战

1、模型介绍

论文
知乎
代码
CULane数据集简介

2、基于CULane数据集格式的训练

2.1、video to img

import glob
import os
import cv2# --------视频转图像-----------------------------------------
def video2image(video_path, save_path, index):if not os.path.exists(save_path): os.makedirs(save_path)cap = cv2.VideoCapture(video_path)img_num = 0while 1:print(index)ret, frame = cap.read()if img_num >2000:breakif ret == False:breaksave_name = os.path.join(save_path, str(index) + ".jpg")cv2.imwrite(save_name, frame)index += 1img_num +=1cap.release()return indexif __name__ == "__main__":video_path = r"Ultra-Fast-Lane-Detection\dataset\video"video_list = os.listdir(video_path)print(video_list)index = 0for i in range(len(video_list)):video_load = os.path.join(video_path, video_list[i])save_path = os.path.join(r"Ultra-Fast-Lane-Detection\dataset\img", video_list[i].split(".")[0])print(save_path)index = video2image(video_load,save_path,index)

2.2 Labelme标注

在这里插入图片描述

2.3 json转label图片

单张图像的代码位于:anaconda2\envs\labelme\Lib\site-packages\labelme\cli\json_to_dataset.py;
批量使用:

import os
import globos.chdir("B:\Anaconda\envs\Lane_Detection\Lib\site-packages\labelme\cli")
path1 = r"conda activate your env"
os.system(path1)json_file = r'your json file'  # 文件路径
json_list = glob.glob("%s/*.json" % (json_file))
for i in json_list:path11 = r"python json_to_dataset.py "path22 = path11 + ios.system(path22)

结果如图所示:
在这里插入图片描述

2.4 基于json生成点坐标的文本文件

import os
import json
import numpy as npdir_json = r'your json path'  # json存储的文件目录
dir_txt = r'your txt save path'  # txt存储目录
if not os.path.exists(dir_txt):os.makedirs(dir_txt)
list_json = os.listdir(dir_json)def json2txt(path_json, path_txt):  # 可修改生成格式with open(path_json, 'r') as path_json:jsonx = json.load(path_json)with open(path_txt, 'w+') as ftxt:for shape in jsonx['shapes']:label = str(shape['label']) + ' 'xy = np.array(shape['points'])strxy = ''for m, n in xy:m = int(m)n = int(n)# print('m:',m)# print('n:',n)strxy += str(m) + ' ' + str(n) + ' 'label = strxyftxt.writelines(label + "\n")for cnt, json_name in enumerate(list_json):path_json = os.path.join(dir_json, json_name)print(path_json)path_txt = os.path.join(dir_txt, json_name.replace('.json', '.lines.txt'))print(path_txt)json2txt(path_json, path_txt)

结果如图所示:
在这里插入图片描述

2.5 train.txt\test.txt\val.txt制作

import osfolder_path = "img/val_img/"  # 文件夹路径
txt_file_path = "list/val.txt"    # 输出txt文件路径with open(txt_file_path, "w") as txt_file:for file_name in os.listdir(folder_path):if file_name.endswith(".jpg"):file_path = "/"+folder_path+file_nametxt_file.write(file_path + "\n")  # 将文件名写入txt文件,每个文件名占一行

效果如图所示:
在这里插入图片描述

2.5 label_Seg文件夹的制作

将2.3步骤生成的文件夹的里的label.png重命名并保存到其它文件夹

import os
import glob
import shutil
save_path = r"D:\pythonFiles\Lane_Detection\2-Ultra-Fast-Lane-Detection\dataset\CULane\laneseg"seg_img_path = r"D:\pythonFiles\Lane_Detection\2-Ultra-Fast-Lane-Detection\dataset\CULane\laneseg\all"img_list = glob.glob("%s/*/*.png" % (seg_img_path))for img_path in img_list:if img_path.split("\\")[-1] == "label.png":num = img_path.split("\\")[-2].split("_")[0]new_name = num + ".png"save_name = os.path.join(save_path, new_name)shutil.copy(img_path, save_name)

效果如图所示:
在这里插入图片描述

2.6 制作train_gt.txt\val_gt.txt

import osfolder_path = "img/train_img/"  # 文件夹路径
txt_file_path = "list/train_gt.txt"    # 输出txt文件路径
seg_path = "laneseg/train_img/"
with open(txt_file_path, "w") as txt_file:for file_name in os.listdir(folder_path):if file_name.endswith(".jpg"):file_path = "/"+folder_path+file_nameprint(file_path)txt_file.write(file_path + " ")  # 将文件名写入txt文件file_gt_path = "/"+seg_path+file_name.split(".")[0]+".png"print(file_gt_path)txt_file.write(file_gt_path + " ")#txt_file.write("1 1 1 1\n")

效果如图所示
在这里插入图片描述

2.7 最终数据集结构

1 CULane
1.1 img
在这里插入图片描述

1.2 laneseg
在这里插入图片描述

1.3 list
在这里插入图片描述

3 开始训练

3.1 configs/culane.py

在这里插入图片描述在这里插入图片描述

3.2 开始训练

python train.py configs/culane.py 

3.3 测试

把之前生成的test.txt复制到CULane数据集的一级目录下

python test.py configs/culane.py --test_model weights/ep048.pth --test_work_dir ./tmp

4 参考

CSDN博客1

CSDN博客2

CSDN博客3

CULane数据集介绍

CSDN博客4

这篇关于Ultra Fast Structure-aware Deep Lane Detection的训练实战的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/810073

相关文章

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语

Java MQTT实战应用

《JavaMQTT实战应用》本文详解MQTT协议,涵盖其发布/订阅机制、低功耗高效特性、三种服务质量等级(QoS0/1/2),以及客户端、代理、主题的核心概念,最后提供Linux部署教程、Sprin... 目录一、MQTT协议二、MQTT优点三、三种服务质量等级四、客户端、代理、主题1. 客户端(Clien

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

深度解析Spring Boot拦截器Interceptor与过滤器Filter的区别与实战指南

《深度解析SpringBoot拦截器Interceptor与过滤器Filter的区别与实战指南》本文深度解析SpringBoot中拦截器与过滤器的区别,涵盖执行顺序、依赖关系、异常处理等核心差异,并... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实

MySQL中的索引结构和分类实战案例详解

《MySQL中的索引结构和分类实战案例详解》本文详解MySQL索引结构与分类,涵盖B树、B+树、哈希及全文索引,分析其原理与优劣势,并结合实战案例探讨创建、管理及优化技巧,助力提升查询性能,感兴趣的朋... 目录一、索引概述1.1 索引的定义与作用1.2 索引的基本原理二、索引结构详解2.1 B树索引2.2

从入门到精通MySQL 数据库索引(实战案例)

《从入门到精通MySQL数据库索引(实战案例)》索引是数据库的目录,提升查询速度,主要类型包括BTree、Hash、全文、空间索引,需根据场景选择,建议用于高频查询、关联字段、排序等,避免重复率高或... 目录一、索引是什么?能干嘛?核心作用:二、索引的 4 种主要类型(附通俗例子)1. BTree 索引(