哈利路亚
Let's take one million years picnic
欢迎来到Sean Cleveland的博客
软工超越日报-paddle目标检测算法 数据集统合 5/30

今天我们来做数据集统合,和预测算法不同,这次我们要对照的是各自的xml文件

代码如下:

import os

path = ['人纹污灯蛾', '丝带凤蝶', '日本脊吉丁', '星天牛', '杨小舟蛾', '杨扇舟蛾', '松墨天牛',
        '柳兰叶甲', '桑天牛', '美国白蛾', '草履蚧',
        '褐边绿刺蛾成虫', '霜天蛾', '麻皮椿成虫', '黄刺蛾']


def walkFile(file1,id):
    for root, dirs, files in os.walk(file1):

        # 遍历文件
        # for f in files:
        #     print(os.path.join(root, f))
        with open('trainval.txt', 'w') as c:
            for f in files:
                c.write('C:/Users/14997/PycharmProjects/mushi/images/' + path[10] + '/' + os.path.splitext(f)[0] + '.jpg ')
                c.write('C:/Users/14997/Desktop/数据集xml/'+path[10]+'/'+os.path.splitext(f)[0]+'.xml\n')


        with open('test.txt', 'w') as c:
            for f in files:
                c.write('C:/Users/14997/PycharmProjects/mushi/images/' + path[10] + '/' + os.path.splitext(f)[0] + '.jpg ')
                c.write('C:/Users/14997/Desktop/数据集xml/' + path[10] + '/' + os.path.splitext(f)[0] + '.xml\n')



def ssc():
    walkFile("C:/Users/14997/Desktop/数据集xml/"+path[10], 10)


ssc()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

这样就可以实现以下效果:

 

posted on 2021-05-30 20:41  哈利路亚#0207  阅读(66)  评论(0编辑  收藏  举报
Live2D