YOLOv8实例分割自建数据集报错

一.问题描述

WARNING ⚠️ Box and segment counts should be equal, but got len(segments) = 102, len(boxes) = 105. To resolve this only boxes will be used and all segments will be removed. To avoid this please supply either a detect or segment dataset, not a detect-segment mixed dataset.

大概意思就是标注文件中有segment和bbox的数量对不上,就是数据集中不全是segment标注。

二.解决办法

labelme标注的数据集可以有多种格式,包括但不限于

1.polygon(实例分割的标准格式)

2.rectangle(bbox框格式)

3.circle(圆圈格式)

如果数据集中包含rectangle等标注格式,不加修改直接转yolo格式进行训练的话,会出现数据集错误,产生如上报错信息

2.1 筛选json文件中的标注格式

import os
import json
import cv2
import numpy as np
import shutil
# json目录
fileDir = '/home/fc/sft/Paper_Detection/python/afan/yolov8/dataset/dataset_lingjian3/json'

output_cropped_img_dir = '/home/afan/Desktop/down/new'

# 使用os.listdir()来列出目录中的所有文件
file_names = os.listdir(fileDir)

# 获取该目录下的.json 文件名称
json_files = [file for file in file_names if file.endswith('.json')]

w = []
y = []
# 遍历指定目录下的 .json文件名称
for json_file in json_files:

    # 文件名称 去掉 .json
    fileName = json_file.replace('.json', '')
    print(fileName)
    # 读取json文件内容,返回字典格式
    with open(f'{fileDir}/{fileName}.json', 'r', encoding='utf8') as fp:
        json_data = json.load(fp)

    # 创建需要返回的字典  my_dict{'分类名称:[point xy坐标]'}
    shaixuan = json_data['shapes']
    for element in shaixuan:
        if 'shape_type' in element and element['shape_type'] != 'polygon':
            print(json_file)
            w += [json_file]
            y += [element['shape_type']]
            break
    else:
        print("All elements have shape_type 'polygon'")
print(w)
print(y)

上述代码会打印除polygon格式外含有的其他格式以及对应的json文件名。

2.2 将其他格式转换为polygon

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值