# STEEL-Surface-Error-Detection-Yolov5 **Repository Path**: simonck666/steel-surface-error-detection-yolov5 ## Basic Information - **Project Name**: STEEL-Surface-Error-Detection-Yolov5 - **Description**: STEEL-Surface-Error-Detection-Yolov5 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-02-19 - **Last Updated**: 2022-02-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dataStandardForm ![](data_Standard_form/dataStandardForm.png) ## Train/ 训练集 ![](/Users/simon.yang/Desktop/STEEL_Surface/data_Standard_form/trainFolder.png)![](data_Standard_form/trainFolder.png) - 所有下载好的 NEU-CLS 数据全部放进去 ![](data_Standard_form/train:images.png) - NEU-CLS 数据集 ![](data_Standard_form/Example_data.png) ### Train/labels Folder - **必须 TXT 格式** ![](data_Standard_form/train:label.png) - Label Example - 两行:有两个检测的目标 - 每行第一位:缺陷类别 - 每行后四位:x, y, h, w - 中心点 - 长和宽 - 做了归一化之后的结果 ![](data_Standard_form/label_example.png) ## Valid/ 验证集 ![](data_Standard_form/validFolder.png) ### Valid/images - 一个类别 5 个数据 - 一共三十个数据 ![](data_Standard_form/valid:images.png) ## data.yaml 配置文件 ![](data_Standard_form/dataYaml.png) ```yaml // 这两行 train & val 不要改,直接改动之后的数据集就好 train: ../Dataset/train/images val: ../Dataset/train/images nc: 6 names: ['crazing', 'inclusion', 'patches', 'pitted_surface', 'rolled-in_scale', ''scratches'] ``` # Run Yolov5 `git clone https://github.com/ultralytics/yolov5.git` [GitHub - ultralytics/yolov5: YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite](https://github.com/ultralytics/yolov5.git) ![](data_Standard_form/runArgc.png) - `--data xxx`: 指定当前路径中 `yaml` 配置文件位置 - `--cfg models/yolov5s.yaml`: 指定 Yolov5 网络架构 - 在文件夹:`yolov5/models` 中 - 常用 `models`:l, s, x 模型大小号 - `yolov5l.yaml` - `yolov5s.yaml`:快速识别 -- 最简易 - `yolov5x.yaml`:离线版本模型,速度慢 -- 最精确 > 速度快,精度高。速度慢,精度低 - `--batch-size 8`: 建议选大一点的值 - 8 G 显存,batch-size 8 - 从 16 开始试 ![](data_Standard_form/yolov5_models.png) ## Yolov5s.yaml 配置文件解析 ```yaml # YOLOv5 🚀 by Ultralytics, GPL-3.0 license # Parameters # 分类个数 nc: 80 # number of classes # 模型网络层数缩小/扩大倍数,标准为 1。0.33 * 标准层数 depth_multiple: 0.33 # model depth multiple # 特征图的个数:每一层得到特征图个数缩小/扩大的倍数 width_multiple: 0.50 # layer channel multiple # 特征框大小 anchors: - [10,13, 16,30, 33,23] # P3/8 - [30,61, 62,45, 59,119] # P4/16 - [116,90, 156,198, 373,326] # P5/32 # YOLOv5 v6.0 backbone backbone: # [from, number, module, args] [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 [-1, 3, C3, [128]], [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 [-1, 6, C3, [256]], [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 [-1, 9, C3, [512]], [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 [-1, 3, C3, [1024]], [-1, 1, SPPF, [1024, 5]], # 9 ] # YOLOv5 v6.0 head head: [[-1, 1, Conv, [512, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 6], 1, Concat, [1]], # cat backbone P4 [-1, 3, C3, [512, False]], # 13 [-1, 1, Conv, [256, 1, 1]], [-1, 1, nn.Upsample, [None, 2, 'nearest']], [[-1, 4], 1, Concat, [1]], # cat backbone P3 [-1, 3, C3, [256, False]], # 17 (P3/8-small) [-1, 1, Conv, [256, 3, 2]], [[-1, 14], 1, Concat, [1]], # cat head P4 [-1, 3, C3, [512, False]], # 20 (P4/16-medium) [-1, 1, Conv, [512, 3, 2]], [[-1, 10], 1, Concat, [1]], # cat head P5 [-1, 3, C3, [1024, False]], # 23 (P5/32-large) [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] ``` # yolov5/runs 日志文件夹 - 每一次训练的日志 - 300 epcho ## yolov5/runs/train/exp/weights ![](data_Standard_form/runs:weights.png) - `best.pt`: 迭代 300 epoch, 每一个 epoch 模型报错之前,找到最好精度的模型进行保存,用 `best.pt` 进行预测 - `last.pt`: 保存训练最后的一个模型 -- 当作之前训练之后得到的weights,训练完300epoch之后再来200epoch,会接着之前的训练 ## yolov5/runs/train/exp/labels.jpg ![](yolov5/runs/train/exp/labels.jpg) - 统计类别标签分布 -- 左上 - 中心点的大致位置以及密集程度 -- 左下 - 表示划痕大小的分布 -- 右下 ## yolov5/runs/train/exp/results.txt ![](data_Standard_form/runs:results.png) - 每一个 epoch 的 result 都会保存下来 ## yolov5/runs/train/exp/train_batch0.jpg ![](yolov5/runs/train/exp/train_batch0.jpg) # 使用训练完成的模型进行测试 ## yolov5/detect.py 模型测试 ### 1. 配置参数 ![](data_Standard_form/detect:argc.png) ![](data_Standard_form/detect:argc2.png) - `--source xxx`: 测试的图像 - xxx 甚至可以为一个 .mp4 的文件 - `--weights xxx`: 权重参数文件 -- 找到 runs/train/exp/weights/best.pt - `output xxx`: 将检测结果输出到output文件夹