资源简介

人脸识别Python代码人脸识别Python代码人脸识别Python代码人脸识别Python代码人脸识别Python代码

资源截图

代码片段和文件信息

from keras.models import Sequential
from keras.layers import Conv2D ZeroPadding2D Activation Input concatenate
from keras.models import Model
from keras.layers.normalization import BatchNormalization
from keras.layers.pooling import MaxPooling2D AveragePooling2D
from keras.layers.merge import Concatenate
from keras.layers.core import Lambda Flatten Dense
from keras.initializers import glorot_uniform
from keras.engine.topology import layer
from keras import backend as K
K.set_image_data_format(‘channels_first‘)
import cv2
import os
import numpy as np
from numpy import genfromtxt
import pandas as pd
import tensorflow as tf
from FaceRecognitionForTheHappyHouse.fr_utils import *
from FaceRecognitionForTheHappyHouse.inception_blocks import *

np.set_printoptions(threshold=np.nan)

FRmodel = faceRecoModel(input_shape=(3 96 96))

# print(“Total Params:“ FRmodel.count_params())


def triplet_loss(y_true y_pred alpha = 0.2):
    anchor positive negative = y_pred[0] y_pred[1] y_pred[2]

    pos_dist = tf.reduce_sum(tf.square(tf.subtract(y_pred[0] y_pred[1])))

    neg_dist = tf.reduce_sum(tf.square(tf.subtract(y_pred[0] y_pred[2])))

    basic_loss = tf.add(tf.subtract(pos_dist neg_dist) alpha)

    loss = tf.reduce_sum(tf.maximum(basic_loss 0.0))

    return loss


# with tf.Session() as test:
#     tf.set_random_seed(1)
#     y_true = (None None None)
#     y_pred = (tf.random_normal([3 128] mean=6 stddev=0.1 seed=1)
#               tf.random_normal([3 128] mean=1 stddev=1 seed=1)
#               tf.random_normal([3 128] mean=3 stddev=4 seed=1))
#     loss = triplet_loss(y_true y_pred)
#
#     print(“loss = “ + str(loss.eval()))

FRmodel.compile(optimizer=‘adam‘ loss = triplet_loss metrics = [‘accuracy‘])
load_weights_from_FaceNet(FRmodel)

database = {}
database[“danielle“] = img_to_encoding(“images/danielle.png“ FRmodel)
database[“younes“] = img_to_encoding(“images/younes.jpg“ FRmodel)
database[“tian“] = img_to_encoding(“images/tian.jpg“ FRmodel)
database[“andrew“] = img_to_encoding(“images/andrew.jpg“ FRmodel)
database[“kian“] = img_to_encoding(“images/kian.jpg“ FRmodel)
database[“dan“] = img_to_encoding(“images/dan.jpg“ FRmodel)
database[“sebastiano“] = img_to_encoding(“images/sebastiano.jpg“ FRmodel)
database[“bertrand“] = img_to_encoding(“images/bertrand.jpg“ FRmodel)
database[“kevin“] = img_to_encoding(“images/kevin.jpg“ FRmodel)
database[“felix“] = img_to_encoding(“images/felix.jpg“ FRmodel)
database[“benoit“] = img_to_encoding(“images/benoit.jpg“ FRmodel)
database[“arnaud“] = img_to_encoding(“images/arnaud.jpg“ FRmodel)



def verify(image_path identity database model):
    encoding = img_to_encoding(image_path model)

    dist = np.linalg.norm(encoding - database[identity])

    if dist < 0.7:
        print(“It‘s “ + str(identity) + “ welcome home!“)
        door_open = True
    else:
        print(“It‘s not “ 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-25 07:51  FaceRecognition\
     文件        3942  2018-06-09 03:11  FaceRecognition\face_recognition-v1.py
     文件        7106  2018-06-09 03:09  FaceRecognition\face_recognition-v3.py
     文件       11324  2018-04-09 07:55  FaceRecognition\inception_blocks.py
     文件        8538  2018-04-09 09:46  FaceRecognition\fr_utils.py
     目录           0  2018-06-09 03:08  FaceRecognition\images\
     文件        9780  2017-12-20 07:39  FaceRecognition\images\benoit.jpg
     文件        2519  2017-12-20 07:40  FaceRecognition\images\tian.jpg
     文件        9970  2017-12-20 07:39  FaceRecognition\images\camera_2.jpg
     文件        9799  2017-12-20 07:39  FaceRecognition\images\camera_0.jpg
     文件       22832  2017-12-20 07:39  FaceRecognition\images\danielle.png
     文件        4415  2017-12-20 07:39  FaceRecognition\images\andrew.jpg
     文件        9669  2017-12-20 07:40  FaceRecognition\images\younes.jpg
     文件       10274  2017-12-20 07:39  FaceRecognition\images\bertrand.jpg
     文件       13097  2017-12-20 07:40  FaceRecognition\images\kian.jpg
     文件       10108  2017-12-20 07:40  FaceRecognition\images\sebastiano.jpg
     文件        8517  2017-12-20 07:39  FaceRecognition\images\felix.jpg
     文件        3356  2017-12-20 07:40  FaceRecognition\images\kevin.jpg
     文件        9760  2017-12-20 07:39  FaceRecognition\images\arnaud.jpg
     文件        9350  2017-12-20 07:39  FaceRecognition\images\dan.jpg
     目录           0  2018-05-27 14:13  FaceRecognition\__pycache__\
     文件        7579  2018-04-09 09:16  FaceRecognition\__pycache__\inception_blocks_v2.cpython-36.pyc
     文件        7076  2018-04-09 09:52  FaceRecognition\__pycache__\fr_utils.cpython-36.pyc
     文件       11302  2018-04-09 08:42  FaceRecognition\inception_blocks_v2.py
     目录           0  2018-05-27 14:13  FaceRecognition\weights\
     文件        1626  2017-12-20 07:41  FaceRecognition\weights\inception_5b_3x3_bn1_w.csv
     文件        2172  2017-12-20 07:40  FaceRecognition\weights\inception_3c_3x3_bn1_w.csv
     文件        6518  2017-12-20 07:41  FaceRecognition\weights\inception_5b_3x3_bn2_w.csv
     文件        1095  2017-12-20 07:40  FaceRecognition\weights\inception_3c_5x5_bn2_v.csv
     文件        2077  2017-12-20 07:41  FaceRecognition\weights\inception_4a_pool_bn_v.csv
     文件         596  2017-12-20 07:40  FaceRecognition\weights\inception_3c_5x5_conv1_b.csv
............此处省略220个文件信息

评论

共有 条评论