CK數據集分類處理

import os
import shutil 
#七種表情分類
emotions = ["anger", "contempt", "disgust", "fear", "happy", "sadness", "surprise"]
path= "cohn-kanade-images"
path_label= "Emotion_labels/Emotion"

#創建文件夾
if not os.path.exists('data/'+emotions[0]):
    for emotion in emotions:
        path_emotion='data'+'/'+emotion
        os.makedirs(path_emotion) 
#遍歷所有文件夾
files = os.listdir(path)
for files_name in files:
    path_two=path+"/"+files_name
    path_two_label=path_label+"/"+files_name
    files_two = os.listdir(path_two)

    for files_two_name in files_two:
        if(len(files_two_name)<=4):
            
            path_three_label=os.path.join(path_two_label,files_two_name)
            path_three_label_file = os.listdir(path_three_label)
            
            path_three=os.path.join(path_two,files_two_name)
            path_three_file = os.listdir(path_three)
            
            print(path_three_file)
            if(len(path_three_label_file)!=0):
                f=open(os.path.join(path_three_label,path_three_label_file[0]))
                lines=f.readline()
                label=int(lines[3])
                for i in range(8,len(path_three_file),3):
                    name=os.path.join(path_three, path_three_file[i])
                    path_emotions='data'+'/'+emotions[label-1]
                    shutil.copy(name,path_emotions) 
                

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章