YOLOv3 使用COCO数据集 Model accepts 80 classes labeled from 0 - 79, however you labeled a class**问题解决

首先确认coco数据集标签序号是0-79,默认的是1-80或1-91,需要写脚本改为0-79。
其次是要删除缓存label文件:

train2014.npy
和
val2014.npy

这有我自己写的对应coco2014的批量标签转换python脚本,可以从1-91转换到1-80:

import os

z = []
g = {}
with open(r'F:\codes\coco\coco_labels.txt') as f:  # 结合coco数据集自带的coco_labels.txt文件使用
    lines = f.readlines()
    for x in lines:
        y = x.split(',')
        z.append(y)
for x in z:
    key = x[0]
    val = x[1]
    g[key] = val

path = 'F:\\codes\\coco\\labels\\val2014\\'  # 需要批量操作的label文件夹
filelist = os.listdir(path)
for file in filelist:
    Olddir = os.path.join(path, file)
    filename = os.path.splitext(file)[0];  # 文件名
    filetype = os.path.splitext(file)[1];  # 文件扩展名
    filePath = path + filename + filetype
    newcont = []
    with open(filePath,'r') as fil:
        flines = fil.readlines()
        for x1 in flines:
            z1 = x1[:2]
            z3 = x1[2:]
            # print('老id:'+x1)
            if z1.endswith(' '):
                z1 = x1[:1]
                z3 = x1[1:]
            z2 = g[z1]
            x2 = z2+z3
            newcont.append(x2)
    with open(filePath,'w') as wtfil:
        for line in newcont:
            wtfil.writelines(line)
            # print('新id:'+line)
    print(filename + filetype + ' 已完成')

然后是发现需要标签数减1的情况下写的减1脚本:

import os

# z = []
# g = {}
# with open(r'F:\codes\coco\coco_labels.txt') as f:
#     lines = f.readlines()
#     for x in lines:
#         y = x.split(',')
#         z.append(y)
# for x in z:
#     key = x[0]
#     val = x[1]
#     g[key] = val

path = '/data/coco/labels/val2014/'
filelist = os.listdir(path)
for file in filelist:
    filename = os.path.splitext(file)[0]  # 文件名
    filetype = os.path.splitext(file)[1]  # 文件扩展名
    filePath = path + filename + filetype
    newcont = []
    with open(filePath,'r') as fil:
        flines = fil.readlines()
        for x1 in flines:
            z1 = x1[:2]
            z3 = x1[2:]
            # print('老id:'+x1)
            if z1.endswith(' '):
                z1 = x1[:1]
                z3 = x1[1:]
            z2 = int(z1)-1
            z2 = str(z2)
            x2 = z2+z3
            newcont.append(x2)
    with open(filePath,'w') as wtfil:
        for line in newcont:
            wtfil.writelines(line)
            # print('新id:'+line)
    print(filename + filetype + ' 已完成')

print('全部完成')
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值