传送带异物破损裂缝检测数据集 2300张 带标注voc yolo

news/2024/9/21 19:33:07/

传送带异物破损裂缝检测数据集 2300张 带标注voc yolo

2

传送带异物破损裂缝检测数据集

数据集描述

数据集旨在用于传送带上的异物、破损、裂缝等缺陷的检测任务。数据集包含大量的图像及其对应的标注信息,可用于训练计算机视觉模型,以识别和定位传送带上的各种缺陷类型。

数据规模

数据集共有2263张图像,标注了13987个对象。

类别及数量

数据集中的类别及数量如下:

  1. 异物 (foreign):1482张图像,标注了2455个对象。
  2. 块状破损 (block):751张图像,标注了10671个对象。
  3. 裂缝 (crack):329张图像,标注了448个对象。
  4. 孔洞 (hole):112张图像,标注了413个对象。
标注格式

数据集中的标注信息采用了VOC(Visual Object Classes)格式,每个图像都有一个对应的XML文件,记录了每个对象的位置信息(边界框坐标)和类别标签。此外,也可以选择YOLO格式的标注文件(TXT文件),方便使用YOLO系列模型进行训练。

数据集结构

典型的数据集目录结构如下:

1conveyor_belt_defect_detection_dataset/
2├── Annotations/
3│   ├── img_0001.xml
4│   ├── img_0002.xml
5│   └── ...
6├── ImageSets/
7│   ├── Main/
8│   │   ├── train.txt
9│   │   ├── val.txt
10│   │   └── test.txt
11├── JPEGImages/
12│   ├── img_0001.jpg
13│   ├── img_0002.jpg
14│   └── ...
15└── labels/
16    ├── train/
17    │   ├── img_0001.txt
18    │   ├── img_0002.txt
19    └── val/
20        ├── img_0001.txt
21        ├── img_0002.txt
应用场景

数据集可以用于以下应用场景:

  • 缺陷检测与分类:训练模型识别传送带上的异物、破损、裂缝等缺陷。
  • 故障诊断:实时监测传送带上的异常情况,提高故障诊断效率。
  • 预防性维护:辅助工厂的预防性维护计划,减少因缺陷导致的生产中断。
  • 科研分析:用于研究传送带缺陷的发生规律和发展趋势。

示例代码

以下是一个使用Python和相关库(如OpenCV、PyTorch等)来加载和展示数据集的简单示例代码:

1import os
2import cv2
3import xml.etree.ElementTree as ET
4from PIL import Image
5import numpy as np
6
7# 数据集路径
8dataset_path = 'path/to/conveyor_belt_defect_detection_dataset/'
9
10# 加载图像和标签
11def load_image_and_label(image_path, annotation_path):
12    # 读取图像
13    image = Image.open(image_path).convert('RGB')
14    # 解析XML文件
15    tree = ET.parse(annotation_path)
16    root = tree.getroot()
17    objects = []
18    for obj in root.findall('object'):
19        name = obj.find('name').text
20        bbox = obj.find('bndbox')
21        xmin = int(bbox.find('xmin').text)
22        ymin = int(bbox.find('ymin').text)
23        xmax = int(bbox.find('xmax').text)
24        ymax = int(bbox.find('ymax').text)
25        objects.append([xmin, ymin, xmax, ymax, name])
26    return image, objects
27
28# 展示图像
29def show_image_with_boxes(image, boxes):
30    img = np.array(image)
31    for box in boxes:
32        xmin, ymin, xmax, ymax, name = box
33        cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)
34        cv2.putText(img, name, (xmin, ymin - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
35    cv2.imshow('Image with Boxes', img)
36    cv2.waitKey(0)
37    cv2.destroyAllWindows()
38
39# 主函数
40if __name__ == "__main__":
41    images_dir = os.path.join(dataset_path, 'JPEGImages')
42    annotations_dir = os.path.join(dataset_path, 'Annotations')
43    
44    # 获取图像列表
45    image_files = [f for f in os.listdir(images_dir) if f.endswith('.jpg')]
46    
47    # 随机选择一张图像
48    selected_image = np.random.choice(image_files)
49    image_path = os.path.join(images_dir, selected_image)
50    annotation_path = os.path.join(annotations_dir, selected_image.replace('.jpg', '.xml'))
51    
52    # 加载图像和标签
53    image, boxes = load_image_and_label(image_path, annotation_path)
54    
55    # 展示带有标注框的图像
56    show_image_with_boxes(image, boxes)

这段代码展示了如何加载图像和其对应的VOC XML标注文件,并在图像上绘制边界框和类别标签。您可以根据实际需求进一步扩展和修改这段代码,以适应您的具体应用场景。

示例代码:从VOC格式转换为YOLO格式

以下是将VOC格式的标注文件转换为YOLO格式的标签文件的示例代码:

1import os
2import xml.etree.ElementTree as ET
3import shutil
4
5# 数据集路径
6dataset_path = 'path/to/conveyor_belt_defect_detection_dataset/'
7
8# VOC标注文件目录
9voc_annotations_dir = os.path.join(dataset_path, 'Annotations')
10# 输出YOLO标签文件目录
11yolo_labels_dir = os.path.join(dataset_path, 'labels')
12
13# 创建YOLO标签目录
14os.makedirs(yolo_labels_dir, exist_ok=True)
15
16# 复制VOC图像集划分文件到YOLO目录
17for split in ['train', 'val']:
18    shutil.copy(os.path.join(dataset_path, 'ImageSets/Main/{}.txt'.format(split)), os.path.join(yolo_labels_dir, '{}.txt'.format(split)))
19
20# 从VOC格式转换为YOLO格式
21def convert_voc_to_yolo(voc_path, yolo_path, width, height):
22    with open(voc_path, 'r') as infile:
23        tree = ET.parse(infile)
24        root = tree.getroot()
25        objects = []
26        for obj in root.findall('object'):
27            name = obj.find('name').text
28            bbox = obj.find('bndbox')
29            xmin = int(bbox.find('xmin').text)
30            ymin = int(bbox.find('ymin').text)
31            xmax = int(bbox.find('xmax').text)
32            ymax = int(bbox.find('ymax').text)
33            x_center = (xmin + xmax) / 2.0
34            y_center = (ymin + ymax) / 2.0
35            w = xmax - xmin
36            h = ymax - ymin
37            x_center /= width
38            y_center /= height
39            w /= width
40            h /= height
41            objects.append([name, x_center, y_center, w, h])
42
43    with open(yolo_path, 'w') as outfile:
44        for obj in objects:
45            class_index = {'foreign': 0, 'block': 1, 'crack': 2, 'hole': 3}[obj[0]]
46            line = f"{class_index} {obj[1]} {obj[2]} {obj[3]} {obj[4]}\n"
47            outfile.write(line)
48
49# 主函数
50if __name__ == "__main__":
51    # 获取VOC标注文件列表
52    voc_files = [f for f in os.listdir(voc_annotations_dir) if f.endswith('.xml')]
53    
54    # 遍历VOC文件并转换为YOLO格式
55    for voc_file in voc_files:
56        # 获取图像尺寸
57        image_file = os.path.join(dataset_path, 'JPEGImages', voc_file.replace('.xml', '.jpg'))
58        image = Image.open(image_file)
59        width, height = image.size
60        
61        # 转换并保存YOLO标签文件
62        yolo_file = os.path.join(yolo_labels_dir, voc_file.replace('.xml', '.txt'))
63        convert_voc_to_yolo(os.path.join(voc_annotations_dir, voc_file), yolo_file, width, height)

这段代码展示了如何将VOC格式的标注文件转换为YOLO格式的标签文件,方便使用YOLO系列模型进行训练。您可以根据实际需求进一步扩展和修改这段代码,以适应您的具体应用场景。

 


http://www.ppmy.cn/news/1528522.html

相关文章

STM32 使用 CubeMX 实现按键外部中断

目录 问题背景知识参考需要改什么注意尽量不要在中断函数使用 循环函数做延时中断函数中延时方法调试 问题 我想实现按钮触发紧急停止类似功能,需要使用按键中断功能。 背景知识 GPIO 点亮 LED。stm32cubemx hal学习记录:GPIO输入输出。STM32—HAL库 …

Java面试篇基础部分-Java语言中的锁有哪些?

Java中的锁主要是用于保障并发线程场景下的数据一致性问题。在多线程编程中为了保证数据一致性,通常需要在使用对象或者方法之前进行加锁操作。也就是说要保证在同一时间内只能由一个线程来对对象进行修改,从而保证了数据一致性,保证了数据安…

【Linux】简易日志系统

目录 一、概念 二、可变参数 三、日志系统 一、概念 一个正在运行的程序或系统就像一个哑巴,一旦开始运行我们很难知晓其内部的运行状态。 但有时在程序运行过程中,我们想知道其内部不同时刻的运行结果如何,这时一个日志系统可以有效的帮…

RMC语句格式

RMC语句格式举例 在GNSS(全球导航卫星系统)通信中,RMC(Recommended Minimum Specific GNSS Data)语句是一种常用的NMEA 0183格式数据,用于提供关于接收机的定位信息、速度及方向等关键数据。RMC语句特别适…

conda 安装tensorflow一些命令

1、conda env list 查看当前存在的虚拟环境列表 2、conda create -n tensor_py3.7 pip python3.7 第一次安装环境的时候创建,如果有直接第3步,n后边的tensor_py3.7 为虚拟环境名称,可根据自己情况起名, 后边为Python版本号&#…

社团周报系统可行性研究-web后端框架对比-springboot,django,gin

对于目前市面上web后端框架,我主要了解到的就是springboot,django gin等,分别对应java python go三种语言,目前我比较熟悉的就是springboot 目录 spring boot框架 简介 优点 缺点 适用场景 与需求匹配度 django框架 简介…

Ubuntu 与Uboot网络共享资源

1、NFS 1.1 Ubuntu 下 NFS 服务开启 sudo apt-get install nfs-kernel-server rpcbind 等待安装完成,安装完成以后在用户根目录下创建一个名为“Linux”的文件夹,以后所有 的东西都放到这个“Linux”文件夹里面,在“Linux”文件夹里面新建…

HT876 带任意限幅的10.9Wx2高保真音频功放

特点 可任意配置的限幅功能 自由选择音频限制幅度,使输出音频信号限制在固定 失真水平内 内置自动限温控制功能 支持AB类与D类切换 THDN:0.02%(VDD8.4V, RL 4Ω, fIN 1kHz, Po 2x1.0W, BTL) 输出功率(fIN1kHZ,THDN10%) 2x10.9W (VDD9.0V, RL4Ω, BTL) VDD供电范围:2…