对于VOC2012数据集的处理

import os
#分割出序号
folder1='F:/datasets/VOC2012/SegmentationClass'
folder2='F:/datasets/VOC2012/JPEGImages'             

folder1_sub_name=os.listdir(folder1)
folder2_sub_name=os.listdir(folder2)

split_folder1=[]
split_folder2=[]
for i in folder1_sub_name:
    i=i.split('.')[0]
    split_folder1.append(i)

for i in folder2_sub_name:
    i=i.split('.')[0]
    split_folder2.append(i)
    
#进行数据处理
file_paths=[]
for i in split_folder2:
    if i not in split_folder1:
        file_path='F:/datasets/VOC2012/JPEGImages'+'/'+str(i)+'.jpg'
        file_paths.append(file_path)
        os.remove(file_path)
        print('the file is removed:',file_path)

 

 

对于VOC2012数据集的处理_第1张图片

对于VOC2012数据集的处理_第2张图片

对于VOC2012的处理代码。消除label中JPEG文件中不对应的图片。

接着将segmentation下的.png文件用JPEG文件代替。

import os
renames=[]

folder2='F:/datasets/VOC2012/Segmentation'
filename2=os.listdir(folder2)
for i in filename2:
#i=>png
    scr_name='F:/datasets/VOC2012/Segmentation'+'/'+i
   # print(scr_name)
    s=os.path.splitext(i)[0]
    tar_name='F:/datasets/VOC2012/Segmentation'+'/'+s+'.jpg'
    print(tar_name)
    rename_1=os.rename(scr_name,tar_name)

 

你可能感兴趣的:(python,python)