示例#1
0
N = input("Enter N value:")

############################################################################################
####################################  EIGEN FACES TRAINING AND TESTING #####################
############################################################################################

misrate = [[0.0 for x in xrange(3*N+1)] for x in xrange(10)]
total = [0.0 for x in xrange(10)]
percent = 0
for i in xrange(10) :
    tr,t = randomgenerator(N)    
    #print r,test
    Xtrain,ytrain = read_images(os.getcwd()+"\..\data", N, tr)
    Xtest,ytest = read_images(os.getcwd()+"\..\data", 11-N, t)    
    # Princical Component Analysis for feature reduction 
    eigenvectors, Z, mu = pca(vectorize(Xtrain), ytrain)
    l = 0
    for num_components in range(0,15*N+1,5):
        W,M = eigenface(eigenvectors,Z,num_components)            
        Wnew = test(vectorize(Xtest), ytest, W, M, mu)
        count = 0
        idx = knnsearch(W,Wnew)        
        idx = [k+1 for k in idx]                   
        idx.insert(0,0)
        count = 0
        for j in xrange(1,16) :
            for k in xrange(1,12-N) :
                if idx[(j-1)*(11-N)+k] < (j-1)*N+1 or idx[(j-1)*(11-N)+k] > j*N :
                    count = count+1
        misrate[i][l] = count/float(15*(11-N))
        l = l+1
示例#2
0
misrate = [[0.0 for x in xrange(3*N+1)] for x in xrange(10)]
misrate = np.asarray(misrate)
total = [0.0 for x in xrange(10)]
y = []
k = 1
for i in xrange(15):
    for j in xrange(N):
        y.append(k)
    k = k+1

percent = 0
for ei in xrange(10) :
    tr,t = randomgenerator(N)    
    x,yyy = read_images(os.getcwd()+"\..\data", N, tr)
    Xtest,ytest = read_images(os.getcwd()+"\..\data", 11-N, t)
    x = np.asarray(vectorize(x))
    y = np.asarray(y).reshape(-1,1)
    Xtest = np.asarray(vectorize(Xtest))
    x = x.T
    ii = 0
    for num_components in xrange(5,15) :
        [W,mu] = fisherfaces(x,y,num_components)
        #W = np.asarray(W)
        w = np.dot(x,W)
        wp = np.dot(Xtest.T,W)
        idx = ffknnsearch(w,wp)
        idx = [k+1 for k in idx]
        idx.insert(0,0)                 
        count = 0
        for j in xrange(1,16) :
            for k in xrange(1,12-N) :
示例#3
0
N = input("Enter N value:")

############################################################################################
####################################  EIGEN FACES TRAINING AND TESTING #####################
############################################################################################

misrate = [[0.0 for x in xrange(3 * N + 1)] for x in xrange(10)]
total = [0.0 for x in xrange(10)]
percent = 0
for i in xrange(10):
    tr, t = randomgenerator(N)
    #print r,test
    Xtrain, ytrain = read_images(os.getcwd() + "\..\data", N, tr)
    Xtest, ytest = read_images(os.getcwd() + "\..\data", 11 - N, t)
    # Princical Component Analysis for feature reduction
    eigenvectors, Z, mu = pca(vectorize(Xtrain), ytrain)
    l = 0
    for num_components in range(0, 15 * N + 1, 5):
        W, M = eigenface(eigenvectors, Z, num_components)
        Wnew = test(vectorize(Xtest), ytest, W, M, mu)
        count = 0
        idx = knnsearch(W, Wnew)
        idx = [k + 1 for k in idx]
        idx.insert(0, 0)
        count = 0
        for j in xrange(1, 16):
            for k in xrange(1, 12 - N):
                if idx[(j - 1) * (11 - N) +
                       k] < (j - 1) * N + 1 or idx[(j - 1) *
                                                   (11 - N) + k] > j * N:
                    count = count + 1