-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrxPCAtest.py
58 lines (49 loc) · 1.43 KB
/
rxPCAtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cv2
import matplotlib.pyplot as plt
# import dlib
# from imutils import face_utils
import numpy as np
import pandas as pd
from joblib import load, dump
import glob
import random
from scipy import linalg
from numpy.linalg import eig
from functools import reduce
import pprint
pp = pprint.PrettyPrinter(indent=4)
from rxPCA import PCA
def main():
#load faceDict
try:
faceDict = load('faceDict.bin')
except:
print("Unable to load faceDict from disk")
iVectorDict = dict()
#select k number of images to form dataset
k = 10
persons = random.choices(list(faceDict.keys()), k=k)
for person in persons:
try:
subImage = faceDict[person]
except:
print("Unable to find image for " + person)
iVectorDict[person] = subImage.flatten('C')
# print('iVectorDict[person]')
# print(iVectorDict[person])
print("iVectorDict keys: " + str(list(iVectorDict.keys())) )
print("# keys in iVectorDict: " + str(len(iVectorDict)))
iVectorsPDF = pd.DataFrame(list(iVectorDict.values()))
#train test split
iVectorsTrainPDF = iVectorsPDF[:-3] #train data
iVectorsTestPDF = iVectorsPDF[-3:] #test data
# print('iVectorsTestPDF')
# print(iVectorsTestPDF)
#fit principal components of dataset
pcaModel = PCA(n_components=0.7)
pcaModel.fit(iVectorsTrainPDF)
#transform test data from image space to eigenspace
for index,sample in iVectorsTestPDF.iterrows():
pcaModel.transform(pd.DataFrame(sample))
plt.imshow(subImage, cmap='gray')
main()