---
# System prepended metadata

title: '**Face Recgonizer**'

---

# **Face Recgonizer**
## Purpose
Design a face recognizer using any technique taught in the classes.
## Method
I create these three python program to accomplish this assighment.
1. [FaceModel.py](https://docs.google.com/document/d/1O0s2ZuGRNlDYLljtFkqLpomcFzwqHwuNvZu64XrhPno/edit?usp=sharing)
2. [FacePredict.py](https://docs.google.com/document/d/1mmsjTx8opkcHKx1clKCJjmsKebZ0CCdPKiMUaUGRT2M/edit?usp=sharing)
3. [FaceGUI.py](https://docs.google.com/document/d/12BshrtNbrmKZJKp45IJkXw64wPEtxKbhGIw2sxPgmsQ/edit?usp=sharing)

(the above are the links of source code) 
### **FaceModel** - build and train a model
#### Step1. Import the Module in Need
Import numpy,tensorflow,keras,os,cv2 pandas and so on......
#### Step2. Image Data Pre-Processing for Neural Networks
The following are some pictures in the train_folder and some informations in the train_label.csv.
![](https://i.imgur.com/Ah6BG12.jpg =70%x )![](https://i.imgur.com/5WY3Of4.jpg =30%x )
The number between 'trn_img' and '.jpg' is the file_id,and every number mapped to its label.
There are 1398 file_ids and labels(39 categories i.e., several file_ids maybe mapped to the same label) in our training data. In this step,I added the picture paths and labels to my program's arrays,then do the pre-processing.
#### Step3. Divide the Dataset into Training Data and Validation Data
`x_train, x_val, y_train, y_val = train_test_split(imgs, labels, test_size=0.2)`
training data : validation data = 0.8 : 0.2
#### Step4. Build a Model
model.summary()
![](https://i.imgur.com/X0Ds1Bg.jpg =70%x )
#### Step5. Train Model
```
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
train_history = model.fit(x=x_train, y=y_train, validation_data=(x_val, y_val), epochs=100, batch_size=32, verbose=1)
```
#### Step6. Show the Train History and Save the Trained Model
With the following two pictures,left is the model's accuracy rate(increased as the epoch increased),right is the model's loss(decreased as the epoch increased).
![](https://i.imgur.com/DlRzpR0.jpg =50%x )![](https://i.imgur.com/j4QTPhx.jpg =50%x )

### **FacePredict** - prediction and create a CSV file based on the kaggle
#### Step1. Import the Module in Need
Import numpy,cv2,os,keras and csv
#### Step2. Image Data Pre-Processing for Neural Networks
Same as the **FaceModel**'s step2
#### Step3. Load the Trained Model and Start to Predict
```
model = load_model('model.h5')
prediction = model.predict_classes(imgs)
````
#### Step4. Open the CSV File then Write the Prediction into the File
**Outcome** : The following is some of the information in CSV File
![](https://i.imgur.com/taj5ojD.jpg =60%x )

### **FaceGUI** - design a simple GUI program
#### Designed with Tkinter
Here is the video demonstrating how my program works on GUI program.
[Youtube Link](https://www.youtube.com/watch?v=v3hhUfrK6Ps&feature=youtu.be)
{%youtube v3hhUfrK6Ps %}
## Problems During Development
My independent study is also doing deep learning,so the difficult thing is not finishing this assignment but doing it better. My score on the kaggle is 0.75343.
At first,I guessed there were some errors in my code. After checked several times,I thought that the problem is caused by dataset.Not only training dataset but test dataset contained several pictures are too dim.For example :
![](https://i.imgur.com/aTohmqk.jpg =15%x )![](https://i.imgur.com/EG4AyPt.jpg =16%x )![](https://i.imgur.com/ZW1WObo.jpg =15%x )
I also adjusted parameter and number of CNN layer many times in my code,but still unable to improve the accuracy rate. So I supposed that the low accuracy rate result from dusky light in the pictures.
## Summary
Other than designing face recognizer,I learned how to create a simple GUI program and use HackMD after this assignment. I also understood that HackMD is a very convenient software,so I will use HackMD to take notes that from previous program assignment in the future.
## Reference
[CSV File Read Specific Column](https://ithelp.ithome.com.tw/articles/10193421)
[Tkinter 1](https://blog.techbridge.cc/2019/09/21/how-to-use-python-tkinter-to-make-gui-app-tutorial/)
[Tkinter 2](https://www.itread01.com/content/1547705544.html)
[HackMD](https://hackmd.io/@wootu/SkY0M5wsZ?type=view)
