目标检测:windows上YOLOv5-5.0训练自己的数据集

本文介绍了在Windows上使用YOLOv5 v5.0进行目标检测的步骤,包括下载代码、安装依赖、准备PASCAL VOC格式的数据集、修改配置文件、训练模型和进行测试。详细讲解了如何生成训练和验证集文件,以及训练和测试命令的使用。
摘要由CSDN通过智能技术生成

一. 下载代码
3. YOLOv5github地址:https://github.com/ultralytics/yolov5
在target里选择5.0版本。

二.安装所需要的库和环境。

pip install -r requirements.txt

三 .准备自己的数据集。

使用PASCAL VOC数据集的目录结构:
建立文件夹层次为 yolov5 / VOCdevkit / VOC2007
VOC2007下面建立两个文件夹:Annotations和JPEGImages
JPEGImages放所有的训练和测试图片;Annotations放所有的xml标记文件。
建立完文件之后执行如下代码生成训练集和验证集文件:
注意:要在当前路径下。

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
import random
from shutil import copyfile

classes=["heidian","shenban","qianban","guoba","guodi"]  # 你的类别信息

TRAIN_RATIO = 5 # 类别数量

def clear_hidden_files(path):
    dir_list = os.listdir(path)
    for i in dir_list:
        abspath = os.path.join(os.path.abspath(path), i)
        if os.path.isfile(abspath):
            if i.startswith("._"):
                os.remove(abspath)
        else:
            clear_hidden_files(abspath)

def convert(size, box):
    dw = 1./size[0]
    dh = 1./size[1]
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_annotation
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值