人臉識別

  人臉識別,基於人臉部特徵信息識別身份的生物識別技術。攝像機、攝像頭採集人臉圖像或視頻流,自動檢測、跟蹤圖像中人臉,作臉部相關技術處理,人臉檢測、人臉關鍵點檢測、人臉驗證等。《麻省理工科技評論》(MIT Technology Review),2017年全球十大突破性技術榜單,支付寶「刷臉支付」(Paying with Your Face)入圍。python

    人臉識別優點,非強制性(採集方式不容易被察覺,被識別人臉圖像可主動獲取)、非接觸性(用戶不須要與設備接觸)、併發性(可同時多人臉檢測、跟蹤、識別)。深度學習前,人臉識別兩步驟:高維人工特徵提取、降維。傳統人臉識別技術基於可見光圖像。深度學習+大數據(海量有標註人臉數據)爲人臉識別領域主流技術路線。神經網絡人臉識別技術,大量樣本圖像訓練識別模型,無需人工選取特徵,樣本訓練過程自行學習,識別準確率能夠達到99%。git

人臉識別技術流程。github

    人臉圖像採集、檢測。人臉圖像採集,攝像頭把人臉圖像採集下來,靜態圖像、動態圖像、不一樣位置、不一樣表情。用戶在採集設備拍報範圍內,採集設置自動搜索並拍攝。人臉檢測屬於目標檢測(object detection)。對要檢測目標對象機率統計,獲得待檢測對象特徵,創建目標檢測模型。用模型匹配輸入圖像,輸出匹配區域。人臉檢測是人臉識別預處理,準確標定人臉在圖像的位置大小。人臉圖像模式特徵豐富,直方圖特徵、顏色特徵、模板特徵、結構特徵、哈爾特徵(Haar-like feature)。人臉檢測挑出有用信息,用特徵檢測人臉。人臉檢測算法,模板匹配模型、Adaboost模型,Adaboost模型速度。精度綜合性能最好,訓練慢、檢測快,可達到視頻流實時檢測效果。算法

人臉圖像預處理數據庫

基於人臉檢測結果,處理圖像,服務特徵提取。系統獲取人臉圖像受到各類條件限制、隨機干擾,需縮放、旋轉、拉伸、光線補償、灰度變換、直方圖均衡化、規範化、幾何校訂、過濾、銳化等圖像預處理。安全

人臉圖像特徵提取網絡

人臉圖像信息數字化,人臉圖像轉變爲一串數字(特徵向量)。如,眼睛左邊、嘴脣右邊、鼻子、下巴位置,特徵點間歐氏距離、曲率、角度提取出特徵份量,相關特徵鏈接成長特徵向量。併發

人臉圖像匹配、識別dom

提取人臉圖像特徵數據與數據庫存儲人臉特徵模板搜索匹配,根據類似程度對身份信息進行判斷,設定閾值,類似度越過閾值,輸出匹配結果。確認,一對一(1:1)圖像比較,證實「你就是你」,金融覈實身份、信息安全領域。辨認,一對多(1:N)圖像匹配,「N人中找你」,視頻流,人走進識別範圍就完成識別,安防領域。性能

###########################################

人臉識別分類
*人臉檢測

*人臉關鍵點檢測

*人臉驗證

*人臉屬性檢測

人臉檢測

檢測、定位圖片人臉,返回高精度人臉框座標。對人臉分析、處理的第一步。「滑動窗口」,選擇圖像矩形區域做滑動窗口,窗口中提取特徵對圖像區域描述,根據特徵描述判斷窗口是否人臉。不斷遍歷須要觀察窗口。

人臉關鍵點檢測

定位、返回人臉五官、輪廓關鍵點座標位置。人臉輪廓、眼睛、眉毛、嘴脣、鼻子輪廓。Face++提供高達106點關鍵點。人臉關鍵點定位技術,級聯形迴歸(cascaded shape regression, CSR)。人臉識別,基於DeepID網絡結構。DeepID網絡結構相似卷積神經網絡結構,倒數第二層,有DeepID層,與卷積層4、最大池化層3相連,卷積神經網絡層數越高視野域越大,既考慮局部特徵,又考慮全局特徵。

 

輸入層 31x39x1、卷積層1 28x36x20(卷積核4x4x1)、最大池化層1 12x18x20(過濾器2x2)、卷積層2 12x16x20(卷積核3x3x20)、最大池化層2 6x8x40(過濾器2x2)、卷積層3 4x6x60(卷積核3x3x40)、最大池化層2 2x3x60(過濾器2x2)、卷積層42x2x80(卷積核2x2x60)、DeepID層 1x160、全鏈接層 Softmax。《Deep Learning Face Representation from Predicting 10000 Classes》 http://mmlab.ie.cuhk.edu.hk/pdf/YiSun_CVPR14.pdf。

人臉驗證

分析兩張人臉同一人可能性大小。輸入兩張人臉,獲得置信度分類、相應閾值,評估類似度。

人臉屬性檢測
人臉屬性辯識、人臉情緒分析。https://www.betaface.com/wpa/在線人臉識別測試。給出人年齡、是否有鬍子、情緒(高興、正常、生氣、憤怒)、性別、是否帶眼鏡、膚色。

人臉識別應用,美圖秀秀美顏應用、世紀佳緣查看潛在配偶「面相」類似度,支付領域「刷臉支付」,安防領域「人臉鑑權」。Face++、商湯科技,提供人臉識別SDK。

##############################################
下面進入正題!!!作一我的臉檢測。

1.獲取數據集(LFW)

Labeled Faces in the Wild Home Menu->Download->All images as gzipped tar file

或者直接點擊我是LFW 解壓放到datasets

2.下載facenet並配置(很重要)


 1)git clone --recursive https://github.com/davidsandberg/facenet.git
 2)cd facenet/
 3)pip install -r requirements.txt (這一步可能會把你的TF修改爲1.2.0)
 4)export PYTHONPATH=$(pwd)/src
注意文件放置的位置!
facenet所在路徑 /home/zhengxinxin/facenet

lfw解壓後所在路徑:/home/zhengxinxin/datasets/lfw

3.處理數據集(對齊數據集)
1)cd facenet
2)python src/align/align_dataset_mtcnn.py ~/datasets/lfw/raw ~/datasets/lfw/lfw_mtcnnpy_160 --image_size 160 --margin 32 --random_order --gpu_memory_fraction 0.25
圖片較多須要等一段時間(等了半個多小時。。。。),而後再這裏/home/zhengxinxin/datasets/lfw/lfw_mtcnnpy_160會有對齊以後的圖片了。

 

修改以後成這樣了。

4.下載模型文件

https://github.com/davidsandberg/facenet

選擇pre-trained models

下載20170512-110547(MS-Celeb-1M數據集訓練的模型文件,微軟人臉識別數據庫,名人榜選擇前100萬名人,搜索引擎採集每一個名人100張人臉圖片。預訓練模型準確率0.993+-0.004)

而後解壓

 

把它放在

放在一個文件夾下 mkdir ~/models以便後面路徑尋找

也就是說文件放在了/home/zhengxinxin/models

5.在lfw數據集上面進行驗證

1)cd facenet

2) python src/validate_on_lfw.py ~/datasets/lfw/lfw_mtcnnpy_160 ~/models/20170512-110547

#######################################

輸出:

2017-11-16 16:45:21.265525: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-11-16 16:45:21.265657: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-11-16 16:45:21.265667: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-11-16 16:45:21.265673: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-11-16 16:45:21.265677: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Model directory: /home/zhengxinxin/models/20170512-110547
Metagraph file: model-20170512-110547.meta
Checkpoint file: model-20170512-110547.ckpt-250000
Runnning forward pass on LFW images
Accuracy: 0.992+-0.005
Validation rate: 0.97600+-0.01405 @ FAR=0.00133
Area Under Curve (AUC): 1.000
Equal Error Rate (EER): 0.008


爲了和基準比較,採用facenet/data/pairs.txt,官方隨機生成數據,裏面包含匹配和不匹配人名和圖片編號。

#######################################

下面看一下validate_on_lfw.py文件:


    這裏採用十折交叉驗證的方法來測試算法的準確。十折交叉驗證是經常使用的精度測試方法,具體策略是:數據集分紅10份,輪流將其中9份作訓練集,1份作測試保,10次結果均值做算法精度估計。通常須要屢次10折交叉驗證求均值。

"""Validate a face recognizer on the "Labeled Faces in the Wild" dataset (http://vis-www.cs.umass.edu/lfw/).Embeddings are calculated using the pairs from http://vis-www.cs.umass.edu/lfw/pairs.txt and the ROC curveis calculated and plotted. Both the model metagraph and the model parameters need to existin the same directory, and the metagraph should have the extension '.meta'."""# 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_importfrom __future__ import divisionfrom __future__ import print_function import tensorflow as tfimport numpy as npimport argparseimport facenetimport lfwimport osimport sysimport mathfrom sklearn import metricsfrom scipy.optimize import brentqfrom scipy import interpolate def main(args): with tf.Graph().as_default(): with tf.Session() as sess: # Read the file containing the pairs used for testing pairs = lfw.read_pairs(os.path.expanduser(args.lfw_pairs)) # Get the paths for the corresponding images paths, actual_issame = lfw.get_paths(os.path.expanduser(args.lfw_dir), pairs, args.lfw_file_ext) # Load the model facenet.load_model(args.model) # Get input and output tensors images_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") #image_size = images_placeholder.get_shape()[1] # For some reason this doesn't work for frozen graphs image_size = args.image_size embedding_size = embeddings.get_shape()[1] # Run forward pass to calculate embeddings print('Runnning forward pass on LFW images') batch_size = args.lfw_batch_size nrof_images = len(paths) nrof_batches = int(math.ceil(1.0*nrof_images / batch_size)) emb_array = np.zeros((nrof_images, embedding_size)) for i in range(nrof_batches): start_index = i*batch_size end_index = min((i+1)*batch_size, nrof_images) paths_batch = paths[start_index:end_index] images = facenet.load_data(paths_batch, False, False, image_size) feed_dict = { images_placeholder:images, phase_train_placeholder:False } emb_array[start_index:end_index,:] = sess.run(embeddings, feed_dict=feed_dict) tpr, fpr, accuracy, val, val_std, far = lfw.evaluate(emb_array, actual_issame, nrof_folds=args.lfw_nrof_folds) print('Accuracy: %1.3f+-%1.3f' % (np.mean(accuracy), np.std(accuracy))) print('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val, val_std, far)) auc = metrics.auc(fpr, tpr) print('Area Under Curve (AUC): %1.3f' % auc) eer = brentq(lambda x: 1. - x - interpolate.interp1d(fpr, tpr)(x), 0., 1.) print('Equal Error Rate (EER): %1.3f' % eer) def parse_arguments(argv): parser = argparse.ArgumentParser() parser.add_argument('lfw_dir', type=str, help='Path to the data directory containing aligned LFW face patches.') parser.add_argument('--lfw_batch_size', type=int, help='Number of images to process in a batch in the LFW test set.', default=100) 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_size', type=int, help='Image size (height, width) in pixels.', default=160) parser.add_argument('--lfw_pairs', type=str, help='The file containing the pairs to use for validation.', default='data/pairs.txt') parser.add_argument('--lfw_file_ext', type=str, help='The file extension for the LFW dataset.', default='png', choices=['jpg', 'png']) parser.add_argument('--lfw_nrof_folds', type=int, help='Number of folds to use for cross validation. Mainly used for testing.', default=10) return parser.parse_args(argv) if __name__ == '__main__': main(parse_arguments(sys.argv[1:]))————————————————版權聲明:本文爲CSDN博主「HelloZEX」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。原文連接:https://blog.csdn.net/HelloZEX/article/details/78551974

相關文章
相關標籤/搜索