轴承缺陷检测数据集

轴承缺陷检测数据集 3200张 轴承缺陷 带标注 voc yolo

项目背景:

轴承是机械设备中的重要部件之一,其性能直接影响到机械系统的可靠性和寿命。轴承缺陷(如磨损、裂纹、剥落等)会导致设备故障,从而影响生产效率和安全性。传统的轴承缺陷检测方法主要依靠人工检查,这种方式不仅耗时耗力,而且容易出现误检漏检的情况。因此,开发一套自动化的轴承缺陷检测系统具有重要意义。本数据集旨在为轴承缺陷检测提供高质量的标注数据,支持自动化检测系统的开发与应用。

数据集概述:

  • 名称:轴承缺陷检测数据集
  • 规模:共计3200张图像
  • 类别:多类轴承缺陷
  • 标注格式:支持VOC和YOLO格式的标注文件,可以直接用于模型训练
数据集特点:
  1. 针对性强:专注于轴承缺陷检测,确保数据集的针对性和实用性。
  2. 高质量标注:每张图像都已详细标注,确保数据的准确性和可靠性。
  3. 适用范围广:支持多种标注格式(VOC、YOLO),方便科研人员和开发者直接使用。
  4. 标准格式:采用广泛使用的标注文件格式,方便导入不同的检测框架。
数据集内容:

假设数据集中包含以下几类轴承缺陷:

  • 磨损(Wear)
  • 裂纹(Crack)
  • 剥落(Spalling)
  • 腐蚀(Corrosion)
  • 划痕(Scratch)
数据集用途:
  1. 缺陷检测:可用于训练和评估深度学习模型,特别是在轴承缺陷检测方面。
  2. 质量控制:帮助实现轴承质量的自动化检测,减少人工检测的工作量。
  3. 科研与教育:为轴承缺陷检测领域的研究和教学提供丰富的数据支持。
使用场景:
  1. 实时监控:在生产设备中,利用该数据集训练的模型可以实时检测轴承缺陷。
  2. 质量改进:在轴承生产和质量改进中,利用该数据集可以提高检测的准确性和速度。
  3. 生产管理:在轴承生产和质量管理工作中,利用该数据集可以提高工作效率和管理水平。
技术指标:

  • 数据量:共计3200张图像,涵盖多种轴承缺陷。
  • 数据划分:数据集是否进行了训练集、验证集和测试集的划分,需根据数据集实际内容确定。
  • 标注格式:支持VOC和YOLO格式的标注文件,方便导入不同的检测框架。
  • 标注精度:所有图像均已详细标注,确保数据的准确性和可靠性。
注意事项:
  • 数据隐私:在使用过程中,请确保遵守相关法律法规,保护个人隐私。
  • 数据预处理:在使用前,建议进行一定的数据预处理,如图像归一化等。
获取方式:
  • 下载链接:请访问项目主页获取数据集下载链接。
  • 许可证:请仔细阅读数据集的使用许可协议。
关键代码示例:

以下是关键代码的示例,包括数据加载、模型训练、检测和结果展示。

数据加载(以VOC格式为例):
 
1import os
2import cv2
3import xml.etree.ElementTree as ET
4import numpy as np
5
6# 数据集路径
7DATASET_PATH = 'path/to/dataset'
8IMAGES_DIR = os.path.join(DATASET_PATH, 'JPEGImages')
9ANNOTATIONS_DIR = os.path.join(DATASET_PATH, 'Annotations')
10
11# 加载数据集
12def load_dataset(directory):
13    images = []
14    annotations = []
15
16    for img_file in os.listdir(IMAGES_DIR):
17        if img_file.endswith('.jpg') or img_file.endswith('.png'):
18            img_path = os.path.join(IMAGES_DIR, img_file)
19            annotation_path = os.path.join(ANNOTATIONS_DIR, img_file.replace('.jpg', '.xml').replace('.png', '.xml'))
20            
21            image = cv2.imread(img_path)
22            tree = ET.parse(annotation_path)
23            root = tree.getroot()
24            
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                objects.append((name, [xmin, ymin, xmax, ymax]))
34            
35            images.append(image)
36            annotations.append(objects)
37
38    return images, annotations
39
40train_images, train_annotations = load_dataset(os.path.join(DATASET_PATH, 'train'))
41val_images, val_annotations = load_dataset(os.path.join(DATASET_PATH, 'val'))
42test_images, test_annotations = load_dataset(os.path.join(DATASET_PATH, 'test'))
模型训练:
1# 初始化YOLOv5模型
2from ultralytics import YOLO
3
4model = YOLO('yolov5s.pt')
5
6# 转换VOC格式到YOLO格式
7def convert_voc_to_yolo(annotations, image_shape=(640, 640), class_names=['Wear', 'Crack', 'Spalling', 'Corrosion', 'Scratch']):
8    yolo_annotations = []
9    class_map = {name: i for i, name in enumerate(class_names)}
10    
11    for ann in annotations:
12        converted = []
13        for name, obj in ann:
14            class_id = class_map[name]
15            x_center = (obj[0] + obj[2]) / 2 / image_shape[1]
16            y_center = (obj[1] + obj[3]) / 2 / image_shape[0]
17            width = (obj[2] - obj[0]) / image_shape[1]
18            height = (obj[3] - obj[1]) / image_shape[0]
19            converted.append([class_id, x_center, y_center, width, height])
20        yolo_annotations.append(converted)
21    return yolo_annotations
22
23# 定义训练参数
24EPOCHS = 100
25BATCH_SIZE = 16
26
27# 转换并训练模型
28train_yolo_annots = convert_voc_to_yolo(train_annotations)
29val_yolo_annots = convert_voc_to_yolo(val_annotations)
30
31results = model.train(data='bearing_defect_detection.yaml', epochs=EPOCHS, batch=BATCH_SIZE)
模型检测:
1# 加载训练好的模型
2model = YOLO('best.pt')
3
4# 检测图像
5def detect_bearing_defects(image):
6    results = model.predict(image)
7    for result in results:
8        boxes = result.boxes
9        for box in boxes:
10            x1, y1, x2, y2 = box.xyxy[0]
11            conf = box.conf
12            class_id = box.cls
13            
14            # 显示结果
15            cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
16            class_name = ['Wear', 'Crack', 'Spalling', 'Corrosion', 'Scratch'][class_id]
17            cv2.putText(image, f'{class_name}, Conf: {conf:.2f}', (int(x1), int(y1)-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
18    
19    return image
20
21# 测试图像
22test_image = cv2.imread('path/to/test_image.jpg')
23result_image = detect_bearing_defects(test_image)
24cv2.imshow('Detected Bearing Defects', result_image)
25cv2.waitKey(0)
26cv2.destroyAllWindows()
配置文件 bearing_defect_detection.yaml
1train: path/to/train/images
2val: path/to/val/images
3test: path/to/test/images
4
5nc: 5  # Number of classes
6names: ['Wear', 'Crack', 'Spalling', 'Corrosion', 'Scratch']  # Class names
7
8# Training parameters
9batch_size: 16
10epochs: 100
11img_size: [640, 640]  # Image size
使用指南:
  1. 数据准备:确保数据集路径正确,并且数据集已准备好。
  2. 模型训练:运行训练脚本,等待训练完成。
  3. 模型检测:使用训练好的模型进行检测,并查看检测结果。
结语:

本数据集提供了一个高质量的轴承缺陷检测数据集,支持自动化缺陷检测、质量控制等多个应用场景。通过利用该数据集训练的模型,可以提高轴承缺陷检测的效率和准确性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值