当前位置: 首页 > news >正文

五、Ultra-Fast-Lane-Detection 训练数据集转换

转发:深度学习训练数据集转换技巧-CSDN博客

这章节内容少,但非常重要,生成训练时所需的.xt文件,重点在于:xt文件每行后边的1,1,1,1,如果后边1,1,1,1生成不正确,则训练的LOSS是降不下去的,为了快速在自己的训练集Q上训练,建议不要自定义数据集,网上很多教程我也看过,自定义数据集的训练结果非常差,可能是我没有好好排査原因,所以建议大家转换为文章所用的数据集格式,这样不会出错。

上节(四、Ultra-Fast-Lane-Detection训练自己的【汽车车道】线数据集 -CSDN博客)我们完成数据集的基础制作之后形成了以下的json只 文件,里边是一行一行的利用h samples得到的格式如下的标注结果:

{"lanes": [[-2, -2, -2, 482, 468, 455, 442, 428, 415, 401, 387, 372, 357, 343, 328, 313, 299, 284, 270, 256, 241, 227, 212, 198, 183, 169, 154, 140, 126, 111, 97, 82, 68, 53, 39, 25, 10, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, 494, 484, 474, 464, 453, 443, 433, 423, 413, 402, 392, 382, 372, 361, 350, 340, 329, 319, 308, 298, 287, 276, 266, 255, 245, 234, 223, 213, 202, 192, 181, 171, 160, 150, 140, 129, 119, 108, 98, 88, 77, 67, 57, 46, 36, 25, 15, 5, -2, -2, -2], [-2, -2, -2, -2, 521, 514, 508, 501, 495, 488, 481, 475, 468, 462, 455, 449, 442, 435, 429, 422, 416, 409, 403, 396, 390, 383, 376, 370, 363, 357, 350, 343, 337, 330, 324, 317, 310, 304, 297, 290, 284, 277, 271, 264, 257, 251, 244, 237, 231, 224, 218, 211, 204, 198, -2], [-2, -2, -2, -2, -2, -2, -2, 615, 621, 627, 634, 640, 646, 652, 659, 665, 671, 677, 683, 689, 695, 701, 707, 713, 719, 725, 731, 737, 743, 749, 755, 761, 767, 773, 779, 785, 791, 797, 803, 808, 814, 820, 826, 832, 838, 844, 850, 856, 862, 868, 874, 880, 886, 892, -2], [-2, -2, -2, -2, -2, -2, 643, 654, 664, 675, 686, 696, 707, 718, 728, 739, 750, 760, 771, 782, 792, 802, 812, 822, 832, 842, 852, 862, 872, 882, 892, 902, 912, 922, 932, 942, 952, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2], [-2, -2, -2, -2, -2, -2, 680, 695, 710, 725, 741, 756, 771, 786, 801, 815, 830, 845, 859, 874, 889, 903, 918, 933, 947, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2]], 
"h_samples": [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540], 
"raw_file": "my_dataset1/img/MVI_40192_img00051.jpg"}

下图中的每一行都包括 以上的内容:

接下来,我们需要修改Ultra-Fast-Lane-Detection-master/scripts/convert tusimple.py文件下的generate segmentation and train list(root, line txt,names)函数Q,形成自己的车道线顺序。

以4车道线为例

  • 1,1,1,1表示从左到右的车道线都存在;
  • 1.1.0.0,有2条斜率K<0的左侧线;
  • 0,1.0,0表示有1条斜率K<0的左侧线;
  • 0.0.1.0表示有1条斜率k>0的右侧线;

经过分析发现不会出现1,0.0,1或者1,0,1,0。也就是说0不能在中间只能在两边,这个是在训练时发现问题的关键,因此我们在转换的时候一定要注意。我的6车道线转换代码如下,仅仅修改generate segmentation and train list函数:

def generate_segmentation_and_train_list(root, line_txt, names):
    train_gt_fp = open(os.path.join(root,'train_gt.txt'),'w')
    
    for i in tqdm.tqdm(range(len(line_txt))):

        tmp_line = line_txt[i]
        lines = []
        for j in range(len(tmp_line)):
            lines.append(list(map(float,tmp_line[j])))
        
        ks = np.array([calc_k(line) for line in lines])             # get the direction of each lane

        k_neg = ks[ks<0].copy()
        k_pos = ks[ks>0].copy()
        k_neg = k_neg[k_neg != -10]                                      # -10 means the lane is too short and is discarded
        k_pos = k_pos[k_pos != -10]
        k_neg.sort()
        k_pos.sort()

        label_path = names[i][:-3]+'png'
        label = np.zeros((540,960),dtype=np.uint8)
        bin_label = [0,0,0,0,0,0]
        if len(k_neg) == 1:                                           # for only one lane in the left
            which_lane = np.where(ks == k_neg[0])[0][0]
            draw(label,lines[which_lane],3)
            bin_label[2] = 1
        elif len(k_neg) == 2:                                         # for two lanes in the left
            which_lane = np.where(ks == k_neg[1])[0][0]
            draw(label,lines[which_lane],2)
            which_lane = np.where(ks == k_neg[0])[0][0]
            draw(label,lines[which_lane],3)
            bin_label[1] = 1
            bin_label[2] = 1
        elif len(k_neg) == 3:
            which_lane = np.where(ks == k_neg[2])[0][0]
            draw(label,lines[which_lane],1)                                         # for two lanes in the left
            which_lane = np.where(ks == k_neg[1])[0][0]
            draw(label,lines[which_lane],2)
            which_lane = np.where(ks == k_neg[0])[0][0]
            draw(label,lines[which_lane],3)
            bin_label[1] = 1
            bin_label[2] = 1
            bin_label[0] = 1
        elif len(k_neg) > 3:                                           # for more than two lanes in the left, 
            which_lane = np.where(ks == k_neg[2])[0][0]
            draw(label,lines[which_lane],1)                                         # for two lanes in the left
            which_lane = np.where(ks == k_neg[1])[0][0]
            draw(label,lines[which_lane],2)
            which_lane = np.where(ks == k_neg[0])[0][0]
            draw(label,lines[which_lane],3)
            bin_label[1] = 1
            bin_label[2] = 1
            bin_label[0] = 1
        if len(k_pos) == 1:                                            # For the lanes in the right, the same logical is adopted.
            which_lane = np.where(ks == k_pos[0])[0][0]
            draw(label,lines[which_lane],4)
            bin_label[3] = 1
        elif len(k_pos) == 2:
            which_lane = np.where(ks == k_pos[1])[0][0]
            draw(label,lines[which_lane],4)
            which_lane = np.where(ks == k_pos[0])[0][0]
            draw(label,lines[which_lane],5)
            bin_label[3] = 1
            bin_label[4] = 1
        elif len(k_pos) == 3:
            which_lane = np.where(ks == k_pos[2])[0][0]
            draw(label,lines[which_lane],4)
            which_lane = np.where(ks == k_pos[1])[0][0]
            draw(label,lines[which_lane],5)
            which_lane = np.where(ks == k_pos[0])[0][0]
            draw(label,lines[which_lane],6)
            bin_label[3] = 1
            bin_label[4] = 1
            bin_label[5] = 1
        elif len(k_pos)>3:
            which_lane = np.where(ks == k_pos[1])[0][0]
            draw(label,lines[which_lane],4)
            which_lane = np.where(ks == k_pos[1])[0][0]
            draw(label,lines[which_lane],5)
            which_lane = np.where(ks == k_pos[0])[0][0]
            draw(label,lines[which_lane],6)
            bin_label[3] = 1
            bin_label[4] = 1
            bin_label[5] = 1     
        cv2.imwrite(os.path.join(root,label_path),label)


        train_gt_fp.write(names[i] + ' ' + label_path + ' '+' '.join(list(map(str,bin_label))) + '\n')
    train_gt_fp.close()

相关文章:

  • 802.11标准
  • Java8计算集合属性的平均值
  • 一文了解大模型Function Calling
  • 成绩排序(结构体排序)
  • JVM内存结构笔记01-运行时数据区域
  • 3.14学习总结
  • RISC-V汇编学习(五)—— 汇编实战、GCC内联汇编(基于芯来平台)
  • 【训练细节解读】文本智能混合分块(Mixtures of Text Chunking,MoC)引领RAG进入多粒度感知智能分块阶段
  • 【乐企板式文件】关于乐企板式文件使用OFD模板解析的方式实现说明
  • AAAI2025 Accepted Papers(二)
  • AWS Bedrock全托管接入国产大模型DeepSeek-R1[内涵免费使用DeepSeek-R1满血版]
  • 【0x80070666】-已安装另一个版本...(Tableau 安装失败)
  • MFC中使用Create或CreateDialog创建对话框失败,GetLastError错误码为1813(找不到映像文件中指定的资源类型)
  • linux 命令 case
  • 力扣——合并K个排序链表
  • Ubuntu 18,04 LTS 通过APT安装mips64el的交叉编译器。
  • 平安养老险广西分公司2025年“3∙15”金融消费者权益教育宣传活动暨南湖公园健步行活动
  • uni-app+SpringBoot: 前端传参,后端如何接收参数
  • 矫平机:解锁精密制造的工业之手
  • 命令行创建 Docker 网络
  • C919上海虹桥-深圳航线开通,东航今年计划再接收10架C919
  • 武康大楼再开发:一栋楼火还不够,要带火街区“朋友圈”
  • 铁路端午假期运输火车票今日开售,12306提升应对超大规模并发访问需求能力
  • 中国进出口银行:1-4月投放制造业中长期贷款超1800亿元
  • 农行再回应客户办理业务期间离世:亲属连续三次输错密码,理解亲属悲痛,将协助做好善后
  • 俄方代表团抵达土耳其,俄乌直接谈判有望于当地时间上午重启