查看数据集是检测还是分割?

原因:标注太难了,所以打算购买数据集。没想到卖家发错货了。
所以写了个代码来检查是检测还是分割

import os


def check_yolo_annotation_format(annotation_path):
    """
    检查 YOLO 标注文件的格式,判断它是用于目标检测还是分割。

    参数:
        annotation_path (str): YOLO 标注文件的路径。

    返回:
        str: 标注文件的类型("Detection" 或 "Segmentation")。
    """
    try:
        with open(annotation_path, 'r') as file:
            lines = file.readlines()

        # 初始化检测和分割的标志
        is_detection = False
        is_segmentation = False

        for line in lines:
            # 去掉空格并分割行
            elements = line.strip().split()

            # 检测格式:<class_id> <x_center> <y_center> <width> <height>
            if len(elements) == 5:
                is_detection = True
            # 分割格式:<class_id> <x1> <y1> <x2> <y2> ... <xn> <yn>
            elif len(elements) > 5 and len(elements) % 2 == 1:
                is_segmentation = True
            else:
                print(f"未知的标注格式: {line.strip()}")

        # 判断标注文件的类型
        if is_detection and not is_segmentation:
            return "Detection"
        elif is_segmentation and not is_detection:
            return "Segmentation"
        else:
            return "Mixed or Unknown"
    except Exception as e:
        print(f"读取标注文件时出错: {e}")
        return "Unknown"


# 示例使用
annotation_path = r"C:\Users\915324472\Desktop\crack\crack\valid\labels\1604.rf.7229a9adfa1c9ec285d55c965172ea32.txt"  # 替换为你的标注文件路径
annotation_type = check_yolo_annotation_format(annotation_path)
print(f"标注文件类型: {annotation_type}")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值