修改yolo数据集格式txt文件中类别编号

 
  

 

 

import os
def recursive_listdir(path):

    files = os.listdir(path)
    for file_path in files:
        file = os.path.join(path, file_path)
        # print(file)
        with open(file,'r') as f1:
            txt = f1.readline()
            f1.close()
            # print(txt)
            list = txt.split(' ')
            # print(list)
            # 4是自定义的数字
            first_num = int(list[0])-4
            # print(first_num)
            list[0] = str(first_num)
            print(list)
            with open(file,'w') as w:
                for i in range(5):
                    w.write(list[i])
                    w.write(' ')
                w.close()
recursive_listdir(r'mydataset/labels/val')

# 4 0.528125 0.445833 0.293750 0.570833



 
 

你可能感兴趣的:(yolo,YOLO,python,深度学习)