forked from thibo73800/capsnet-traffic-sign-classifier
/
test_all_faces.py
62 lines (46 loc) · 1.44 KB
/
test_all_faces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Train the model.
Usage:
train.py [--ckpt=<ckpt>]
Options:
-h --help Show this help.
<ckpt> Path to the checkpoints to restore
"""
from keras.preprocessing.image import ImageDataGenerator
from PIL import Image
from PIL import Image, ImageEnhance
from docopt import docopt
from sklearn.model_selection import train_test_split
import tensorflow as tf
import numpy as np
import random
import pickle
import os
from model import FaceRec
from data_handler import get_face_data
def train(ckpt=None):
"""
Test the model
**input: **
*ckpt: (String) [Optional] Path to the ckpt file to restore
"""
X_train, _, X_test, y_test = get_face_data()
X_test = X_test / 255
# Utils method to print the current progression
def plot_progression(b, cost, acc, label):
print("[%s] Batch ID = %s, loss = %s, acc = %s" % (label, b, cost, acc))
# Init model
model = FaceRec("FaceRec", output_folder='/tmp')
if ckpt is None:
model.init()
else:
model.load(ckpt)
print("Loaded model. Beginning to test the entire test dataset")
print("Size of error dataset: %s/%s" %(X_test.shape[0], (X_test.shape[0]+X_train.shape[0])))
loss, acc, _ = model.evaluate_dataset(X_test, y_test)
plot_progression(0, loss, acc, "Total Test Validation")
if __name__ == '__main__':
arguments = docopt(__doc__)
train(arguments["--ckpt"])