Last active
July 7, 2020 12:11
-
-
Save santhalakshminarayana/e1ac782406016436e3d3d5ac86a77f47 to your computer and use it in GitHub Desktop.
Face recognition train and test data preparation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prepare Train Data | |
x_train=[] | |
y_train=[] | |
person_rep=dict() | |
person_folders=os.listdir(path+'/Images_crop/') | |
for i,person in enumerate(person_folders): | |
person_rep[i]=person | |
image_names=os.listdir('Images_crop/'+person+'/') | |
for image_name in image_names: | |
img=load_img(path+'/Images_crop/'+person+'/'+image_name,target_size=(224,224)) | |
img=img_to_array(img) | |
img=np.expand_dims(img,axis=0) | |
img=preprocess_input(img) | |
img_encode=vgg_face(img) | |
x_train.append(np.squeeze(K.eval(img_encode)).tolist()) | |
y_train.append(i) | |
# Prepare Test Data | |
x_test=[] | |
y_test=[] | |
person_folders=os.listdir(path+'/Test_Images_crop/') | |
test_image_names=os.listdir('Test_Images_crop/'+person+'/') | |
for image_name in test_image_names: | |
img=load_img(path+'/Test_Images_crop/'+person+'/'+image_name,target_size=(224,224)) | |
img=img_to_array(img) | |
img=np.expand_dims(img,axis=0) | |
img=preprocess_input(img) | |
img_encode=vgg_face(img) | |
x_test.append(np.squeeze(K.eval(img_encode)).tolist()) | |
y_test.append(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment