码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 以YOLOv5为基准实现布匹缺陷检测(Fabric Defect Detection)


    一、YOLOv5 安装

    使用以下命令安装最新版的YOLOv5

    # 下载代码
    git clone https://github.com/ultralytics/yolov5  # clone
    cd yolov5
    # 创建 python 环境
    conda create -n yolov5 python=3.8
    conda activate yolov5
    # 安装依赖项
    pip install -r requirements.txt  # install
    # 安装显卡版本(RTX 30xx 系列)
    conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    二、天池数据集下载

    1. 下载数据集

    官网中的布匹瑕疵检测数据集仅包括第一轮的数据集,而2019广东工业智造创新大赛【赛场一】季军解决方案 全套代码 则提供了第二轮的代码,下载地址如下:数据集-百度网盘(密码:jp7d)。共16个文件,目录结构如下:
    在这里插入图片描述
    下载完成后,在项目根目录下创建 train_data 文件夹,将 guangdong1_round2_train2_20191004_Annotations.zip 和 train2_images_1.zip 解压缩后,放入该文件夹。目录结构如下:
    在这里插入图片描述

    2. 图片分类与标签转换 convertTrainLabel.py

    从 DefectDetection 下载 convertTrainLabel.py,将其放入根目录,运行如下代码,将数据集进行转换。

    python convertTrainLabel.py
    
    • 1

    具体代码如下:

    import numpy as np # linear algebra
    import os
    import json
    from tqdm.auto import tqdm
    import shutil as sh
    import cv2
    
    josn_path = "./train_data/guangdong1_round2_train2_20191004_Annotations/Annotations/anno_train.json"
    image_path = "./train_data/guangdong1_round2_train2_20191004_images/defect/"
    
    name_list = []
    image_h_list = []
    image_w_list = []
    c_list = []
    w_list = []
    h_list = []
    x_center_list = []
    y_center_list = []
    
    with open(josn_path, 'r') as f:
        temps = tqdm(json.loads(f.read()))
        for temp in temps:
            # image_w = temp["image_width"]
            # image_h = temp["image_height"]
            name = temp["name"].split('.')[0]
            path = os.path.join(image_path, name, temp["name"])
            # print('path: ',path)
            im = cv2.imread(path)
            sp = im.shape
            image_h, image_w = sp[0], sp[1]
            # print("image_h, image_w: ", image_h, image_w)
            # print("defect_name: ",temp["defect_name"])
            #bboxs
            x_l, y_l, x_r, y_r = temp["bbox"]
            # print(temp["name"], temp["bbox"])
            if temp["defect_name"]=="沾污":
                defect_name = '0'
            elif temp["defect_name"]=="错花":
                defect_name = '1'
            elif temp["defect_name"] == "水印":
                defect_name = '2'
            elif temp["defect_name"] == "花毛":
                defect_name = '3'
            elif temp["defect_name"] == "缝头":
                defect_name = '4'
            elif temp["defect_name"] == "缝头印":
                defect_name = '5'
            elif temp["defect_name"] == "虫粘":
                defect_name = '6'
            elif temp["defect_name"] == "破洞":
                defect_name = '7'
            elif temp["defect_name"] == "褶子":
                defect_name = '8'
            elif temp["defect_name"] == "织疵":
                defect_name = '9'
            elif temp["defect_name"] == "漏印":
                defect_name = '10'
            elif temp["defect_name"] == "蜡斑":
                defect_name = '11'
            elif temp["defect_name"] == "色差":
                defect_name = '12'
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
  • 相关阅读:
    Realsense相机SDK使用(二)----------- 利用深度信息完成测距任务(不使用Ros)
    数据结构-难点突破(C++/Java详解实现串匹配算法KMP,next数组求法,KMP算法优化nextval数组)
    docker-部署 redis 主从同步(一主,两从+哨兵模式)tag:redis:6.2.6
    day12:MyBatis的Dao层实现方式
    获取淘宝/天猫购买到商品的订单详情——buyer_order_detail
    Redis 在 C# 中的应用与集成
    基于BPM(业务流程管理)的低代码开发平台有哪些优势?
    【毕业设计】深度学习手势识别 - yolo python opencv cnn 机器视觉
    Kotlin高仿微信-第17篇-单聊-转账
    6.串口、时钟
  • 原文地址:https://blog.csdn.net/zhuxiaoyang2000/article/details/126756305
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号