当前位置:   article > 正文

基于Yolov5的道路缺陷识别,加入CVPR2023 InceptionNeXt、华为诺亚2023 VanillaNet、ASFF、EVC、Decoupled_Detect、TSCODE、WIoU优化_yolov5s 添加2023

yolov5s 添加2023

目录

1.数据集介绍

1.1数据增强,扩充数据集

1.1.1 通过split_train_val.py得到trainval.txt、val.txt、test.txt

1.1.2 通过voc_label.py得到适合yolov5训练需要的

2.基于yolov5的道路缺陷识别

2.1配置 crack.yaml

2.2 修改yolov5s_crack.yaml

2.3训练道路缺陷模型

3.性能评价

3.1 加入ASFF特征金字塔融合

3.2 ECVBlock

3.3 解耦头Decoupled_Detect

3.4 GSConv+Slim Neck

 3.4.1 slimneck-yolov5s.yaml 

 3.4.2 GSConv-yolov5s.yaml​编辑

1.数据集介绍

缺陷类型:crack 

数据集数量:195张

1.1数据增强,扩充数据集

通过medianBlur、GaussianBlur、Blur3倍扩充得到780张图片

按照train、val、test进行8:1:1进行划分

1.1.1 通过split_train_val.py得到trainval.txt、val.txt、test.txt

  1. # coding:utf-8
  2. import os
  3. import random
  4. import argparse
  5. parser = argparse.ArgumentParser()
  6. #xml文件的地址,根据自己的数据进行修改 xml一般存放在Annotations下
  7. parser.add_argument('--xml_path', default='Annotations', type=str, help='input xml label path')
  8. #数据集的划分,地址选择自己数据下的ImageSets/Main
  9. parser.add_argument('--txt_path', default='ImageSets/Main', type=str, help='output txt label path')
  10. opt = parser.parse_args()
  11. trainval_percent = 0.9
  12. train_percent = 0.8
  13. xmlfilepath = opt.xml_path
  14. txtsavepath = opt.txt_path
  15. total_xml = os.listdir(xmlfilepath)
  16. if not os.path.exists(txtsavepath):
  17. os.makedirs(txtsavepath)
  18. num = len(total_xml)
  19. list_index = range(num)
  20. tv = int(num * trainval_percent)
  21. tr = int(tv * train_percent)
  22. trainval = random.sample(list_index, tv)
  23. train = random.sample(trainval, tr)
  24. file_trainval = open(txtsavepath + '/trainval.txt', 'w')
  25. file_test = open(txtsavepath + '/test.txt', 'w')
  26. file_train = open(txtsavepath + '/train.txt', 'w')
  27. file_val = open(txtsavepath + '/val.txt', 'w')
  28. for i in list_index:
  29. name = total_xml[i][:-4] + '\n'
  30. if i in trainval:
  31. file_trainval.write(name)
  32. if i in train:
  33. file_train.write(name)
  34. else:
  35. file_val.write(name)
  36. else:
  37. file_test.write(name)
  38. file_trainval.close()
  39. file_train.close()
  40. file_val.close()
  41. file_test.close()

1.1.2 通过voc_label.py得到适合yolov5训练需要的

  1. # -*- coding: utf-8 -*-
  2. import xml.etree.ElementTree as ET
  3. import os
  4. from os import getcwd
  5. sets = ['train', 'val']
  6. classes = ["crack"] # 改成自己的类别
  7. abs_path = os.getcwd()
  8. print(abs_path)
  9. def convert(size, box):
  10. dw = 1. / (size[0])
  11. dh = 1. / (size[1])
  12. x = (box[0] + box[1]) / 2.0 - 1
  13. y = (box[2] + box[3]) / 2.0 - 1
  14. w = box[1] - box[0]
  15. h = box[3] - box[2]
  16. x = x * dw
  17. w = w * dw
  18. y = y * dh
  19. h = h * dh
  20. return x, y, w, h
  21. def convert_annotation(image_id):
  22. in_file = open('Annotations/%s.xml' % (image_id), encoding='UTF-8')
  23. out_file = open('labels/%s.txt' % (image_id), 'w')
  24. tree = ET.parse(in_file)
  25. root = tree.getroot()
  26. size = root.find('size')
  27. w = int(size.find('width').text)
  28. h = int(size.find('height').text)
  29. for obj in root.iter('object'):
  30. difficult = obj.find('difficult').text
  31. #difficult = obj.find('Difficult').text
  32. cls = obj.find('name').text
  33. if cls not in classes or int(difficult) == 1:
  34. continue
  35. cls_id = classes.index(cls)
  36. xmlbox = obj.find('bndbox')
  37. b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
  38. float(xmlbox.find('ymax').text))
  39. b1, b2, b3, b4 = b
  40. # 标注越界修正
  41. if b2 > w:
  42. b2 = w
  43. if b4 > h:
  44. b4 = h
  45. b = (b1, b2, b3, b4)
  46. bb = convert((w, h), b)
  47. out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
  48. wd = getcwd()
  49. for image_set in sets:
  50. if not os.path.exists('labels/'):
  51. os.makedirs('labels/')
  52. image_ids = open('ImageSets/Main/%s.txt' % (image_set)).read().strip().split()
  53. list_file = open('%s.txt' % (image_set), 'w')
  54. for image_id in image_ids:
  55. list_file.write(abs_path + '/images/%s.jpg\n' % (image_id))
  56. convert_annotation(image_id)
  57. list_file.close()

2.基于yolov5的道路缺陷识别

2.1配置 crack.yaml

  1. train: ./data/crack/train.txt
  2. val: ./data/crack/val.txt
  3. # number of classes
  4. nc: 1
  5. # class names
  6. names: ["crack"]

2.2 修改yolov5s_crack.yaml

  1. # YOLOv5
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/252432
    推荐阅读
    相关标签