YOLOv8检测LUNA16肺结节实战(二):开始训练

说明:训练的过程,参考了DeepLung的训练形式,进行交叉训练。但不太明白,交叉训练有什么意义和优势?欢迎大家告知。

1、将注释文件(.xml)转化为YOLO格式:xml2txt.py

classes = ["nodule"]

# 定义一个函数,将坐标信息转换为YOLO格式
def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0 - 1
    y = (box[2] + box[3])/2.0 - 1
    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

# 定义一个函数,接受 XML 文件和输出的文本文件作为参数
def convert_annotation(xml_file, txt_file):
    in_file = open(xml_file, 'r')  # 打开 XML 文件,'r' 表示读取模式
    out_file = open(txt_file, 'w')  # 打开输出的文本文件,'w' 表示写入模式

    tree = ET.parse(in_file)  # 使用 ElementTree 解析 XML 文件
    root = tree.getroot()  # 获取 XML 树的根节点

    size = root.find('size')  # 在根节点中找到 'size' 元素
    w = int(size.find('width').text)  # 获取图像宽度
    h = int(size.find('height').text)  # 获取图像高度

    # 遍历 XML 文件中的每个 'object' 元素
    for obj in root.iter('object'):
        difficult = 0  # difficult默认为0
        cls = obj.find('name').text  # 获取 'name' 元素的文本内容,即物体类别
        if cls not in classes or int(difficult)==1:
            continue
        cls_id = classes.index(cls)  # 获取类别在类别列表中的索引
        xmlbox = obj.find('bndbox')  # 获取 'bndbox' 元素
        b = (
            float(xmlbox.find('xmin
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值