Home > other >  Great god help, run wrong
Great god help, run wrong

Time:09-20

code below
The from tkinter import *
The from tkinter. Tix import Tk, Control, ComboBox # upgrade package
the Control groupThe from tkinter. Messagebox import showinfo showwarning, showerror # various types of prompt box
The from tkinter import filedialog
The from PIL import Image, ImageTk
The from tkinter. Messagebox import *

The import OS
The import operator
The from numpy import *
The import cv2
The from sklearn. Decomposition import PCA
The from sklearn. Linear_model import LogisticRegression
The from sklearn. Externals import joblib


Part # algorithm
# loading data set
Def loadDataSet (k) : # k represents in 10 pictures chose a few pieces as training set
DataSetDir='E: \ \ matlab renlian'
# display content folder
Choose=random permutation (10) + 1 # random sort 1-10 (0-9) + 1
Train_face=zeros ((40 * k, 112 * 92))
Train_face_number=zeros (40 * k)
Test_face=zeros ((40 * (10 - k), 112 * 92))
Test_face_number=zeros (40 * (10 - k))
For I in range (40) : # 40 people
People_num=I + 1
For j in range (10) : # everyone has 10 different face
If j & lt; K: # test set
Filename=dataSetDir + '/' + STR (people_num) + '/0 + STR (choose [j]) +' PNG '
Img=img2vector (filename)
Train_face [I * k + j:]=img
Train_face_number [I * k + j]=people_num
The else:
Filename=dataSetDir + '/' + STR (people_num) + '/0 + STR (choose [j]) +' PNG '
Img=img2vector (filename)
Test_face [I * (10 - k) + (j-k) :]=img
Test_face_number [I * (10 - k) + (j-k)]=people_num
Return train_face, train_face_number test_face, test_face_number


# convert images into matrix
Def img2vector (filename) :
Img=cv2. Imread (filename, 0) # read in grey value
Rows, cols=img. Shape
ImgVector=zeros ((1, rows * cols))
ImgVector=reshape (img, (1, rows * cols)) # 2 d to 1 d
Return imgVector


Def facefind () :
# get training set
Train_face train_face_number, test_face, test_face_number=loadDataSet (3)
# PCA training training set, the data with PCA to 30 d
Pca=pca (n_components=30) fit (train_face)
# to return to the test set and data set after the training set dimension reduction
X_train_pca=pca transform (train_face)
X_test_pca=pca transform (test_face)
# logistic regression training
Classirfier=LogisticRegression ()
Lr=classirfier. Fit (x_train_pca train_face_number)

# save the model
Joblib. Dump (lr, 'lr. The model')
# calculation precision and recall rate
Accuray=classirfier. Score (x_test_pca test_face_number)
Recall=accuray * 0.7

Return accuray, recall, pca


Part # interface
Def choosepic () : # choose picture function
File_path=filedialog. Askopenfilename () # load file
Path. The set (file_path)
Img_open=Image. Open (the file. The get ())
Img=ImageTk. PhotoImage (img_open)
Pic_label. Config (image=img)
Pic_label. Image=img

String=STR (file. The get ())

# predict
Predict=img2vector (string)
# loading model
LR. LR=joblib. Load (' model ')
Predict_people=LR. Predict (pca) transform (predict))

String1=STR (" precision number: % s: % f the recall rate: % f "% (predict_people accuray, recall))
Showinfo (title='image analysis, message=string1)


# Tk to initialize ()
Accuray, recall, pca=facefind ()
Root=Tk () # root is the root node of the layout, you after the layout on it
Root. Geometry (' 260 x140 ')
Root. Title (" face recognition system ") # set the window title
Root. The resizable (width=False, height=False) # Settings window whether variable
Root. Tk. Eval (' package require Tix ') # updates are introduced, so as to use the combination of the upgrade controls
Path=StringVar (#) to monitor the changes of the value of the variable

='select images' Button (root, the text, the command=choosepic, width=1, height=1). The grid (row=1, the column=1, sticky=W + E + N + S, padx=40,
# pady=20) command to specify the callback function
The file=Entry (root, state='readonly', the text=path)
File. The grid (row=0, the column=1, sticky=W + E + S + N, padx=6, pady=20) # used for text entry with

Pic_label=Label (root, text='images' padx=30, pady=10)
Pic_label. The grid (row=0, the column=2, rowspan=4, sticky=W + E + N + S)
Root. Mainloop ()

error
Traceback (the most recent call last) :
The File "C:/Users/PLAY/PycharmProjects/untitled2/test/set py", line 12, the in & lt; module>
The from sklearn. Decomposition import PCA
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages \ sklearn \ set py", line 82, in & lt; module>
From the base import clone
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages \ sklearn \ base py", line 20, in & lt; module>
From the utils import _IS_32BIT
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages \ sklearn \ utils \ set py", line 20, in & lt; module>
The from scipy. Sparse import issparse
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages \ scipy \ set py", line 156, in & lt; module>
From the import FFT
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages, scipy, FFT, set py", line 76, in & lt; module>
From the _basic import (
The File "C: \ Users \ PLAY \ PycharmProjects \ untitled2 \ venv \ lib \ site - packages \ scipy \ FFT \ _basic py", line 1, the in & lt; module>
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related