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('全部完成')

你可能感兴趣的:(python,yolov3,机器学习)