mtcnn加facenet实现一张照片就能实时识别人脸

本文介绍了一种方法,通过结合mtcnn和facenet模型,仅需一张照片即可实现实时的人脸识别。代码实现包括创建mtcnn网络、加载参数、进行人脸检测与特征提取,然后利用facenet获取128维特征向量,通过计算欧式距离判断是否为同一人。详细代码和模型下载地址在文章中提供。
摘要由CSDN通过智能技术生成

自己写的代码懒得解释了,看的懂就看,代码是没有任何问题的,只有创建一个个人文件夹,在个人文件夹里面放一张照片,就可以进行实时人脸识别了。我会在最后附上github或者gitee地址,gitee和github的readme里面我给了facenet模型下载地址,facenet是用了构建mtcnn的模型,构建mtcnn后在运用mtcnn得到人脸的128特征向量,在判断欧式距离看是不是同一个人,好了我就解释这么多了。。
先运行untitled里面的代码
from future import absolute_import
from future import division
from future import print_function

import cv2
import csv
from os.path import join as pjoin
import matplotlib.pyplot as plt

import sklearn
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.externals import joblib

from scipy import misc
import tensorflow as tf
import numpy as np
import sys
import os
import copy
import argparse
import facenet
import align.detect_face

minsize = 20 # minimum size of face
threshold = [ 0.6, 0.7, 0.7 ] # three steps’s threshold
factor = 0.709 # scale factor

创建mtcnn网络,并加载参数

print(‘Creating networks and loading parameters’)
with tf.Graph().as_default():
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
with sess.as_default():
pnet, rnet, onet = align.detect_face.create_mtcnn(sess, None)

def load_and_align_data(image, image_size, margin, gpu_memory_fraction):

# 读取图片 
img = image
# 获取图片的shape
img_size = np.asarray(img.shape)[0:2]
# 返回边界框数组 (参数分别是输入图片 脸部最小尺寸 三个网络 阈值 factor不清楚)
bounding_boxes, _ = align.detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)

# 如果检测出图片中不存在人脸 则直接返回,return 0(表示不存在人脸,跳过此图)
if len(bounding_boxes) < 1:
    return 0,0,0
else:
    crop=[]
    det=bounding_boxes

    det[:,0]=np.maximum(det[:,0], 0)
    det[:,1]=np.maximum(det[:,1], 0)
    det[:,2]=np.minimum(det[:,2], img_size[1])
    det[:,3]=np.minimum(det[:,3], img_size[0])

    # det[:,0]=np.maximum(det[:,0]-margin/2, 0)
    # det[:,1]=np.maximum(det[:,1]-margin/2, 0)
    # det[:,2]=np.minimum(det[:,2]+margin/2, img_size[1])
    # det[:,3]=np.minimum(det[:,3]+margin/2, img_size[0])

    det=det.astype(int)

    for
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值