【保姆级教程】YOLOv8

您所在的位置:网站首页 diffculf意思 【保姆级教程】YOLOv8

【保姆级教程】YOLOv8

2024-06-10 21:29| 来源: 网络整理| 查看: 265

一、YOLOV8环境准备 1.1 下载安装最新的YOLOv8代码 仓库地址: https://github.com/ultralytics/ultralytics 1.2 配置环境 pip install pyproject.dependencies https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

二、数据准备 2.1 安装roLabelImg标注软件(这里需要读者先预先安装好labelImg标注工具) 2.1.1 拉取roLabelImg源码 仓库地址:https://github.com/cgvict/roLabelImg 2.1.2 打开roLabelImg软件 步骤一:先使用Anaconda Prompt启动labeme标注工具 步骤二:然后,运行2.1.1节中roLabelImg文件下的roLabelImg.py文件

在这里插入图片描述

打开的roLabelImg标注软件界面如下:

在这里插入图片描述

2.2 标注自己的数据

在这里插入图片描述

2.3 数据转换 2.3.1 运行下面代码,将xml标签格式转为txt标签格式 # 文件名称 :roxml_to_dota.py # 功能描述 :把rolabelimg标注的xml文件转换成dota能识别的xml文件, # 再转换成dota格式的txt文件 # 把旋转框 cx,cy,w,h,angle,或者矩形框cx,cy,w,h,转换成四点坐标x1,y1,x2,y2,x3,y3,x4,y4 import os import xml.etree.ElementTree as ET import math cls_list = ['zebracrossing'] #修改为自己的标签 def edit_xml(xml_file, dotaxml_file): """ 修改xml文件 :param xml_file:xml文件的路径 :return: """ # dxml_file = open(xml_file,encoding='gbk') # tree = ET.parse(dxml_file).getroot() tree = ET.parse(xml_file) objs = tree.findall('object') for ix, obj in enumerate(objs): x0 = ET.Element("x0") # 创建节点 y0 = ET.Element("y0") x1 = ET.Element("x1") y1 = ET.Element("y1") x2 = ET.Element("x2") y2 = ET.Element("y2") x3 = ET.Element("x3") y3 = ET.Element("y3") # obj_type = obj.find('bndbox') # type = obj_type.text # print(xml_file) if (obj.find('robndbox') == None): obj_bnd = obj.find('bndbox') obj_xmin = obj_bnd.find('xmin') obj_ymin = obj_bnd.find('ymin') obj_xmax = obj_bnd.find('xmax') obj_ymax = obj_bnd.find('ymax') # 以防有负值坐标 xmin = max(float(obj_xmin.text), 0) ymin = max(float(obj_ymin.text), 0) xmax = max(float(obj_xmax.text), 0) ymax = max(float(obj_ymax.text), 0) obj_bnd.remove(obj_xmin) # 删除节点 obj_bnd.remove(obj_ymin) obj_bnd.remove(obj_xmax) obj_bnd.remove(obj_ymax) x0.text = str(xmin) y0.text = str(ymax) x1.text = str(xmax) y1.text = str(ymax) x2.text = str(xmax) y2.text = str(ymin) x3.text = str(xmin) y3.text = str(ymin) else: obj_bnd = obj.find('robndbox') obj_bnd.tag = 'bndbox' # 修改节点名 obj_cx = obj_bnd.find('cx') obj_cy = obj_bnd.find('cy') obj_w = obj_bnd.find('w') obj_h = obj_bnd.find('h') obj_angle = obj_bnd.find('angle') cx = float(obj_cx.text) cy = float(obj_cy.text) w = float(obj_w.text) h = float(obj_h.text) angle = float(obj_angle.text) obj_bnd.remove(obj_cx) # 删除节点 obj_bnd.remove(obj_cy) obj_bnd.remove(obj_w) obj_bnd.remove(obj_h) obj_bnd.remove(obj_angle) x0.text, y0.text = rotatePoint(cx, cy, cx - w / 2, cy - h / 2, -angle) x1.text, y1.text = rotatePoint(cx, cy, cx + w / 2, cy - h / 2, -angle) x2.text, y2.text = rotatePoint(cx, cy, cx + w / 2, cy + h / 2, -angle) x3.text, y3.text = rotatePoint(cx, cy, cx - w / 2, cy + h / 2, -angle) # obj.remove(obj_type) # 删除节点 obj_bnd.append(x0) # 新增节点 obj_bnd.append(y0) obj_bnd.append(x1) obj_bnd.append(y1) obj_bnd.append(x2) obj_bnd.append(y2) obj_bnd.append(x3) obj_bnd.append(y3) tree.write(dotaxml_file, method='xml', encoding='utf-8') # 更新xml文件 # 转换成四点坐标 def rotatePoint(xc, yc, xp, yp, theta): xoff = xp - xc; yoff = yp - yc; cosTheta = math.cos(theta) sinTheta = math.sin(theta) pResx = cosTheta * xoff + sinTheta * yoff pResy = - sinTheta * xoff + cosTheta * yoff return str(int(xc + pResx)), str(int(yc + pResy)) def totxt(xml_path, out_path): # 想要生成的txt文件保存的路径,这里可以自己修改 files = os.listdir(xml_path) i = 0 for file in files: tree = ET.parse(xml_path + os.sep + file) root = tree.getroot() name = file.split('.')[0] output = out_path + '\\' + name + '.txt' file = open(output, 'w') i = i + 1 objs = tree.findall('object') for obj in objs: cls = obj.find('name').text box = obj.find('bndbox') x0 = int(float(box.find('x0').text)) y0 = int(float(box.find('y0').text)) x1 = int(float(box.find('x1').text)) y1 = int(float(box.find('y1').text)) x2 = int(float(box.find('x2').text)) y2 = int(float(box.find('y2').text)) x3 = int(float(box.find('x3').text)) y3 = int(float(box.find('y3').text)) if x0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3