【TensorFlow】人脸识别OpenFace、Face-recognition、Insightface和FaceNet源码运行

article/2025/9/24 17:52:54

比较人脸识别OpenFace、Face-recognition、Insightface:

FaceNet源码运行

https://github.com/davidsandberg/facenet

1、使用Anaconda安装TensorFlow;

2、更新scipy库;

3、添加os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.

4、下载模型:20180402-114759模型路径

python compare.py 20180402-114759 02.jpg 11.jpg
"""Performs face alignment and calculates L2 distance between the embeddings of images."""# MIT License
# 
# Copyright (c) 2016 David Sandberg
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.from __future__ import absolute_import
from __future__ import division
from __future__ import print_functionfrom 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
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"def main(args):images = load_and_align_data(args.image_files, args.image_size, args.margin, args.gpu_memory_fraction)with tf.Graph().as_default():with tf.Session() as sess:# Load the modelfacenet.load_model(args.model)# Get input and output tensorsimages_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")# Run forward pass to calculate embeddingsfeed_dict = { images_placeholder: images, phase_train_placeholder:False }emb = sess.run(embeddings, feed_dict=feed_dict)nrof_images = len(args.image_files)print('Images:')for i in range(nrof_images):print('%1d: %s' % (i, args.image_files[i]))print('')# Print distance matrixprint('Distance matrix')print('    ', end='')for i in range(nrof_images):print('    %1d     ' % i, end='')print('')for i in range(nrof_images):print('%1d  ' % i, end='')for j in range(nrof_images):dist = np.sqrt(np.sum(np.square(np.subtract(emb[i,:], emb[j,:]))))print('  %1.4f  ' % dist, end='')print('')def load_and_align_data(image_paths, image_size, margin, gpu_memory_fraction):minsize = 20 # minimum size of facethreshold = [ 0.6, 0.7, 0.7 ]  # three steps's thresholdfactor = 0.709 # scale factorprint('Creating networks and loading parameters')with tf.Graph().as_default():gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_memory_fraction)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)tmp_image_paths=copy.copy(image_paths)img_list = []for image in tmp_image_paths:img = misc.imread(os.path.expanduser(image), mode='RGB')img_size = np.asarray(img.shape)[0:2]bounding_boxes, _ = align.detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)if len(bounding_boxes) < 1:image_paths.remove(image)print("can't detect face, remove ", image)continuedet = np.squeeze(bounding_boxes[0,0:4])bb = np.zeros(4, dtype=np.int32)bb[0] = np.maximum(det[0]-margin/2, 0)bb[1] = np.maximum(det[1]-margin/2, 0)bb[2] = np.minimum(det[2]+margin/2, img_size[1])bb[3] = np.minimum(det[3]+margin/2, img_size[0])cropped = img[bb[1]:bb[3],bb[0]:bb[2],:]aligned = misc.imresize(cropped, (image_size, image_size), interp='bilinear')prewhitened = facenet.prewhiten(aligned)img_list.append(prewhitened)images = np.stack(img_list)return imagesdef parse_arguments(argv):parser = argparse.ArgumentParser()parser.add_argument('model', type=str, help='Could be either a directory containing the meta_file and ckpt_file or a model protobuf (.pb) file')parser.add_argument('image_files', type=str, nargs='+', help='Images to compare')parser.add_argument('--image_size', type=int,help='Image size (height, width) in pixels.', default=160)parser.add_argument('--margin', type=int,help='Margin for the crop around the bounding box (height, width) in pixels.', default=44)parser.add_argument('--gpu_memory_fraction', type=float,help='Upper bound on the amount of GPU memory that will be used by the process.', default=1.0)return parser.parse_args(argv)if __name__ == '__main__':main(parse_arguments(sys.argv[1:]))

运行结果: 

(py27tf) bash-3.2$ python compare.py 20180402-114759 02.jpg 11.jpg
Creating networks and loading parameters
2019-01-15 17:11:02.874055: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-01-15 17:11:02.874720: I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance.
Model directory: 20180402-114759
Metagraph file: model-20180402-114759.meta
Checkpoint file: model-20180402-114759.ckpt-275
WARNING:tensorflow:From /anaconda2/envs/py27tf/lib/python2.7/site-packages/tensorflow/python/training/queue_runner_impl.py:391: __init__ (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
Images:
0: 02.jpg
1: 11.jpgDistance matrix0         1     
0    0.0000    0.4207  
1    0.4207    0.0000

MTCNN实时检测人脸:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from six import string_types, iteritemsimport sys
import os
import numpy as np
import tensorflow as tf
#from math import floor
import cv2
import detect_face
import random
from time import sleep
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"video = cv2.VideoCapture(0)print('Creating networks and loading parameters')with tf.Graph().as_default():gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=1.0)sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))with sess.as_default():pnet, rnet, onet = detect_face.create_mtcnn(sess, None)
minsize = 20
threshold = [0.6, 0.7, 0.7]
factor = 0.709
while True:ret, frame = video.read()bounding_boxes, _ = detect_face.detect_face(frame, minsize, pnet, rnet, onet, threshold, factor)nrof_faces = bounding_boxes.shape[0]print('face number :{}'.format(nrof_faces))for face_position in bounding_boxes:face_position = face_position.astype(int)cv2.rectangle(frame, (face_position[0], face_position[1]), (face_position[2], face_position[3]), (0, 255, 0), 2)cv2.imshow('show', frame)if cv2.waitKey(5) & 0xFF == ord('q'):break
video.release()
cv2.destroyAllWindows()

 


http://chatgpt.dhexx.cn/article/OBEKV0vf.shtml

相关文章

windows下OpenFace安装及测试

想使用openface来实现以下视线估计的内容&#xff0c;但是搜了好多都没有具体的使用方案&#xff0c;于是经历了半周&#xff0c;仔细阅读官方文档和参考了一些大佬的经验&#xff0c;终于运行成功了&#xff0c;在此记录一下&#xff0c;嘻嘻 安装 openceface安装官方文档&…

Ubuntu 14.04下openface的环境搭建

如需转载请标明出处&#xff1a;http://blog.csdn.net/itas109 QQ技术交流群&#xff1a;129518033 一、什么是openface&#xff1f; openface是一个基于深度神经网络的开源人脸识别系统。该系统基于谷歌的文章FaceNet: A Unified Embedding for Face Recognition and Clust…

Windows 11 下 OpenFace 2.2.0 的安装

写在前面 最近需要做关于面部的东西&#xff0c;所以需要使用到OpenFace这个工具&#xff0c;本文仅用来记录本人安装过程以供后续复现&#xff0c;如果可以帮助到读者也是非常荣幸。 安装过程 不编译直接使用 这种方法可以直接从官方下载下来编译好的exe以及gui进行使用&a…

Openface人脸识别的原理与过程

Openface人脸识别的原理与过程&#xff1a; https://zhuanlan.zhihu.com/p/24567586 原理可参考如下论文&#xff1a; 《OpenFace: A general-purpose face recognition library with mobile applications》 第一步&#xff1a;找出所有的面孔 我们流水线的第一步是人脸检测。…

openface在pycharm上的安装

1、下载openface相关文件 链接&#xff1a;下载openface:GitHub - cmusatyalab/openface: Face recognition with deep neural networks. 下载后得到一个openface-master的文件夹 2、输入cmd&#xff0c;进入命令提示符&#xff0c;找到自己保存的openface-master文件夹路径。 …

OpenFace使用OpenFace进行人脸识别

1.OpenFace简介 http://cmusatyalab.github.io/openface/ 安装就按照官方教程来就好了 装完各种依赖之后运行一下命令 https://github.com/cmusatyalab/openface.git --recursive cd openface sudo python setup.py install sh modles/get-models.sh 2.素材准备 准备两…

【OpenFace】

OpenFace&#xff1a; http://cmusatyalab.github.io/openface/ 一、什么是Openface&#xff1f; Openface是一个基于深度神经网络的开源人脸识别系统。该系统基于谷歌的文章FaceNet: A Unified Embedding for Face Recognition and Clustering。Openface是卡内基梅隆大学的 B…

OpenFace

OpenFace是一个包含了landmark&#xff0c;head pose&#xff0c;Actionunions&#xff0c;eye gaze等功能&#xff0c;并包含训练和检测所有源码的开源人脸框架&#xff0c;论文为&#xff0c;OpenFace: an open source facial behavior analysis toolkit OpenFace所用到的库包…

win10下openface快速安装与使用

win10下openface快速安装与使用 情况说明环境下载openface下载模型openface的简单使用 情况说明 我发现openface的安装方法五花八门&#xff0c;大多都比较复杂&#xff0c;而openface分很多版本&#xff0c;很多安装教程混在一起&#xff0c;导致我自己安装时下载下混了。 本…

Windows系统下的Openface安装及使用--亲测有效

一、配置openface所需环境 openface主要依赖于opencv和dlib等工具包&#xff0c;工具包安装可winr进入用户终端下载安装&#xff08;需要先下载python&#xff09;&#xff0c;或者下载ananconda&#xff0c;创建anaconda虚拟环境安装&#xff1a; pip install opencv-python…

OpenFace简介

推荐 如下博文 https://blog.csdn.net/qq_14845119/article/details/53994607 OpenFace是一个包含了landmark&#xff0c;head pose&#xff0c;Actionunions&#xff0c;eye gaze等功能&#xff0c;并包含训练和检测所有源码的开源人脸框架&#xff0c;论文为&#xff0c;Ope…

Openface的安装和使用

openface的安装与使用 环境&#xff1a;我的电脑是笔记本电脑&#xff0c;win10系统&#xff0c;用的是pycharm和annaconda。 一、首先下载openface安装包&#xff0c;并且安装 1.下载地址&#xff1a;https://codeload.github.com/cmusatyalab/openface/zip/master 2.下载后…

OpenFace学习(1):安装配置及人脸比对

前言 前几天在网上看到了openface&#xff08;链接&#xff09;&#xff0c;觉得挺有趣就下载配置了一下&#xff0c;稍微修改了一下跑了个demo&#xff0c;效果还是很不错的。这里分享下安装配置的过程以及demo。 简介 openface是一个基于深度神经网络的开源人脸识别系统&a…

“H5移动端App—数据统计分析”项目展示

1、具有切换商城展示功能 2、通过不同的统计图样式分别展示不同的数据

Vant简单H5 web app【小试牛刀】

index.html <!DOCTYPE html> <html><head><meta charset"utf-8"><!--谷歌浏览器&#xff08;手机端&#xff09;顶部颜色--><meta name"msapplication-TileColor" content"#4183fd"><meta name"the…

推荐几个H5、app制作开发工具

我们已经进入移动互联网时代&#xff0c;而app是移动互联网的载体。传统app开发面临成本高、周期长等问题&#xff0c;因此各类快速生成app的工具层出不穷。企业拥有了app才能实现互联网营销和互联网推广。中国有近7000万传统中小型企业&#xff0c;app会帮助这些企业实现互联网…

直接复制php代码制作app,一套免费无代码在线制作APP工具,将APP打包带走

线上营销的火爆离不开人们对APP的依赖&#xff0c;许多小商户已经从很早的时候就开始萌芽出制作APP来为实体店增加生意的想法&#xff0c;然后开发APP对中型企业都是一件成本极高的事情&#xff0c;即便小商户请外包团队需求降到最低&#xff0c;也会产生十几万的费用&#xff…

如何快速成为APP制作、H5制作高手?

App、H5无疑是移动互联网时代的宠儿&#xff0c;无数社交、商业、宣传都在App、H5上实现。掌握App、H5制作技能&#xff0c;无论工作、学习&#xff0c;更胜人一筹。 那么&#xff0c;什么是App呢&#xff1f; App(application的缩写)&#xff0c;即安装在手机上的软件。早期的…

uni-app跨端开发实现APP与H5之间的通讯和交互

最近在研究uni-app跨端开发APP和H5的通讯和交互&#xff0c;比如H5调用APP的方法&#xff0c;APP往H5里面传参&#xff0c;H5往app外面传参。话不多说&#xff0c;上代码&#xff01; html文件放本地的话必须放在项目根目录下的static文件夹 H5调用APP的方法 <!DOCTYPE ht…

利用H5+实现APP在线更新

1 在APP首页添加以下js代码 // 获取本地应用资源版本号 plus.runtime.getProperty(plus.runtime.appid,function(inf){wgtVer inf.version; // mui.toast("当前应用版本&#xff1a;"wgtVer);// 检测更新checkUpdate(); });// 检测更新 var checkUrl "能够返…