1. 配置自己的.yaml文件
当加载这个.yaml文件时,能根据里面的路径找到相应的数据。
# 数据集的根目录
path: D:\edge\YOLO\YOLOv8_Official_Version\ultralytics\cfg\datasets
# 训练数据的目录(.jpg目录)
train: D:\edge\YOLO\YOLOv8_Official_Version\ultralytics\cfg\datasets\images\train
# 验证数据的目录(.jpg目录)
val: D:\edge\YOLO\YOLOv8_Official_Version\ultralytics\cfg\datasets\images\val
# 测试数据的目录(.jpg目录)
test: D:\edge\YOLO\YOLOv8_Official_Version\ultralytics\cfg\datasets\images\test
# 类别的数量
nc: 6
# class names
names:
0: ore carrier
1: passenger ship
2: container ship
3: bulk cargo carrier
4: general cargo ship
5: fishing boat
2. 标签数据格式转换 xml格式转换成txt格式
# .xml文件转换成.txt文件
import copy
from lxml.etree import Element, SubElement, tostring, ElementTree
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
# 检测目标的类别
classes = ["ore carrier", "passenger ship",
"container ship", "bulk cargo carrier",
"general cargo ship", "fishing boat"]
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
def convert(size, box):
dw = 1. / size[0]
dh = 1. / size[1]
x = (box[0] + box[1]) / 2.0 # (x_min + x_max) / 2.0
y = (box[2] + box[3]) / 2.0 # (y_min + y_max) / 2.0
w = box[1] - box[0] # x_max - x_min
h