import os,shutil
import os.path
identity_CelebA_text = open('D:\\Research_work\\project_3\\umar_version\\data\\celeba\\identity_CelebA.txt', 'r')
eval_partition = open('D:\\Research_work\\project_3\\umar_version\\data\\celeba\\list_eval_partition.txt', 'r')
classified_path="D:\\Research_work\\project_3\\umar_version\\data\celeba\\pair_data\\"
eval_data="D:\\Research_work\\project_3\\umar_version\\data\celeba\\pair_eval_data_correct\\"
Lines = identity_CelebA_text.readlines()
Lines_2=eval_partition.readlines()
from pathlib import Path
for line in Lines:
    image,class_number=line.strip().split()
    for line_2 in Lines_2:
        image_2, type=line_2.strip().split()
        if image==image_2:
            class_path = os.path.join(classified_path, class_number)
            if os.path.isdir(class_path):
                image_path=class_path+"\\"+image
                if type=='0':
                    trian_path=eval_data+"train\\"+class_number
                    if os.path.isdir(trian_path)==False:
                        os.mkdir(trian_path)
                    #print(Path(image).stem)
                    shutil.copy(image_path,trian_path+"\\"+str(int(Path(image).stem))+".jpg")
                if type=='1':
                    val_path = eval_data + "valid\\" + class_number
                    if os.path.isdir(val_path) == False:
                        os.mkdir(val_path)
                    shutil.copy(image_path, val_path + "\\" + str(int(Path(image).stem))+".jpg")
                elif type=='2':
                    test_path = eval_data + "test\\" + class_number
                    if os.path.isdir(test_path) == False:
                        os.mkdir(test_path)
                    shutil.copy(image_path, test_path + "\\" + str(int(Path(image).stem))+".jpg")



import os,shutil
import os.path
identity_CelebA_text = open('D:\\Research_work\\project_3\\umar_version\\data\\celeba\\identity_CelebA.txt', 'r')
eval_partition = open('D:\\Research_work\\project_3\\umar_version\\data\\celeba\\list_eval_partition.txt', 'r')
classified_path="D:\\Research_work\\project_3\\umar_version\\data\celeba\\pair_data\\"
eval_data="D:\\Research_work\\project_3\\umar_version\\data\celeba\\pair_eval_data_correct\\"
Lines = identity_CelebA_text.readlines()
Lines_2=eval_partition.readlines()
from pathlib import Path
for line in Lines:
    image,class_number=line.strip().split()
    for line_2 in Lines_2:
        image_2, type=line_2.strip().split()
        if image==image_2:
            class_path = os.path.join(classified_path, class_number)
            if os.path.isdir(class_path):
                image_path=class_path+"\\"+image
                if type=='0':
                    trian_path=eval_data+"train\\"+class_number
                    if os.path.isdir(trian_path)==False:
                        os.mkdir(trian_path)
                    #print(Path(image).stem)
                    shutil.copy(image_path,trian_path+"\\"+str(int(Path(image).stem))+".jpg")
                if type=='1':
                    val_path = eval_data + "valid\\" + class_number
                    if os.path.isdir(val_path) == False:
                        os.mkdir(val_path)
                    shutil.copy(image_path, val_path + "\\" + str(int(Path(image).stem))+".jpg")
                elif type=='2':
                    test_path = eval_data + "test\\" + class_number
                    if os.path.isdir(test_path) == False:
                        os.mkdir(test_path)
                    shutil.copy(image_path, test_path + "\\" + str(int(Path(image).stem))+".jpg")



#print(Path(image).stem)