From d9dfdca7a88a6f71681f9cf46f80454882928c73 Mon Sep 17 00:00:00 2001 From: mohitmajithia <64708578+mohitmajithia@users.noreply.github.com> Date: Mon, 4 May 2020 16:17:54 +0530 Subject: [PATCH] Update eigenfaces.py made changes in this file #4990 --- .../python/graphical/eigenfaces.py | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/undocumented/python/graphical/eigenfaces.py b/examples/undocumented/python/graphical/eigenfaces.py index 60253957680..eaaf437c6c0 100644 --- a/examples/undocumented/python/graphical/eigenfaces.py +++ b/examples/undocumented/python/graphical/eigenfaces.py @@ -40,10 +40,7 @@ import numpy as np from numpy import random - -from shogun import RealFeatures -from shogun import PCA -from shogun import EuclideanDistance +from shogun import sg import math import os import pylab as pl @@ -69,9 +66,9 @@ def train(self, images, labels): self._labels = labels; #transform the numpe vector to shogun structure - features = RealFeatures(images) + features = sg.RealFeatures(images) #PCA - self.pca = PCA() + self.pca = sg.PCA() #set dimension self.pca.set_target_dim(self._num_components); #compute PCA @@ -92,7 +89,7 @@ def predict(self, image): imageAsRow = np.asarray(image.reshape(image.shape[0]*image.shape[1],1), np.float64); #project inthe subspace - p = self.pca.apply_to_feature_vector(RealFeatures(imageAsRow).get_feature_vector(0)); + p = self.pca.apply_to_feature_vector(sg.RealFeatures(imageAsRow).get_feature_vector(0)); #min value to find the face minDist =1e100; @@ -100,10 +97,10 @@ def predict(self, image): minClass = -1; #search which face is the best match for sampleIdx in range(len(self._projections)): - test = RealFeatures(np.asmatrix(p,np.float64).T) - projection = RealFeatures(np.asmatrix(self._projections[sampleIdx], + test = sg.RealFeatures(np.asmatrix(p,np.float64).T) + projection = sg.RealFeatures(np.asmatrix(self._projections[sampleIdx], np.float64).T) - dist = EuclideanDistance( test, projection).distance(0,0) + dist = sg.EuclideanDistance( test, projection).distance(0,0) if(dist < minDist ): minDist = dist; @@ -229,17 +226,17 @@ def plot_gallery(images, titles, h, w, n_row=3, n_col=4): print "Reconstruct with " + str(i) + " eigenvectors" - pca = PCA() + pca = sg.PCA() #set dimension pca.set_target_dim(i); #compute PCA - pca.init(RealFeatures(images)) + pca.init(sg.RealFeatures(images)) - pca.apply_to_feature_vector(RealFeatures(imageAsRow) + pca.apply_to_feature_vector(sg.RealFeatures(imageAsRow) .get_feature_vector(0)); #reconstruct - projection = pca.apply_to_feature_vector(RealFeatures(imageAsRow) + projection = pca.apply_to_feature_vector(sg.RealFeatures(imageAsRow) .get_feature_vector(0)); reconstruction = np.asmatrix( np.asarray(projection, np.float64))* \