aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtrain.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/train.py b/train.py
index b4aaa89..45e0d02 100755
--- a/train.py
+++ b/train.py
@@ -9,6 +9,8 @@ import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import sys
import random
+import os
+import psutil
from random import randint
from sklearn.neighbors import KNeighborsClassifier
@@ -103,7 +105,10 @@ def test_model(M, faces_train, faces_test, target_train, target_test, args):
e_vecs = np.fliplr(e_vecs).T[:M]
deviations_tr = np.flip(deviations_tr)
deviations_tst = np.flip(deviations_tst)
-
+ if (args.classifyalt):
+ faces_train = np.mean(faces_train.reshape([n_faces,8,2576]), axis=1)
+ target_train = range(n_faces)
+ raw_faces_train = np.mean(raw_faces_train.reshape([n_faces,8,2576]), axis=1)
faces_train = np.dot(faces_train, e_vecs.T)
faces_test = np.dot(faces_test, e_vecs.T)
@@ -172,11 +177,11 @@ def test_model(M, faces_train, faces_test, target_train, target_test, args):
for i in range (104):
j = int(np.floor(i/2))
targer_prob_vec [i] = targer_prob[i][j]
- avg_targer_prob = np.zeros(52)
- for i in range (52):
+ avg_targer_prob = np.zeros(n_faces)
+ for i in range (n_faces):
avg_targer_prob[i] = (targer_prob_vec[2*i] + targer_prob_vec[2*i + 1])/2
#WE CAN FIX THIS BY RESHAPING TARGER_PROB_VEC AND TAKING THE MEAN ON THE RIGHT AXIS
- plt.bar(range(52), avg_targer_prob)
+ plt.bar(range(n_faces), avg_targer_prob)
plt.show()
#Better n_neighbors = 2
@@ -200,10 +205,9 @@ def main():
parser.add_argument("-l", "--lda", help="Use LDA", action='store_true')
parser.add_argument("-r", "--reconstruct", help="Use PCA reconstruction, specify face NR", type=int, default=0)
parser.add_argument("-cm", "--conf_mat", help="Show visual confusion matrix", action='store_true')
-
parser.add_argument("-q", "--pca_r", help="Use Reduced PCA", action='store_true')
parser.add_argument("-pr", "--prob", help="Certainty on each guess", action='store_true')
-
+ parser.add_argument("-alt", "--classifyalt", help="Alternative method ON", action='store_true')
args = parser.parse_args()
raw_faces = genfromtxt(args.data, delimiter=',')
@@ -218,6 +222,7 @@ def main():
accuracy[M - args.eigen] = test_model(M, faces_train, faces_test, target_train, target_test, args)
end = timer()
print("Run with", M, "eigenvalues completed in ", end-start, "seconds")
+ print("Memory Used:", psutil.Process(os.getpid()).memory_info().rss)
#plot
plt.plot(range(args.eigen, args.reigen), 100*accuracy)
plt.xlabel('Number of Eigenvectors used (M)')