日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

项目总结二:人脸识别项目(Face Recognition for the Happy House)

發(fā)布時間:2025/4/14 pytorch 75 豆豆
生活随笔 收集整理的這篇文章主要介紹了 项目总结二:人脸识别项目(Face Recognition for the Happy House) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、人臉驗證問題(face verification)與人臉識別問題(face recognition)

1、人臉驗證問題(face verification): ??????????輸入?????????????????????? 數(shù)據(jù)庫

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Image???????????????????? Image

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ID??????????????????????????? ID?

通過輸入的ID找到數(shù)據(jù)庫里的Image,然后將Image與輸入的Image比較,判斷圖片是不是同一個人。一對一問題,通過監(jiān)督學習即可解決。例如高鐵站的門禁系統(tǒng)。

?2、人臉識別問題(face recognition):?????????? 輸入???????????????????????? 數(shù)據(jù)庫

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Image? ? ? ? ? ? ? ? ? ? ? ? ?Image *100

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ID? * 100

假設(shè)數(shù)據(jù)庫里有100張圖片,通過分別計算輸入圖片與數(shù)據(jù)庫里所有圖片 的d函數(shù)的的值,即如果d>閾值τ,則不是同一個人;如果d<閾值τ,則是同一個人。1對k的問題,需要解決一次學習問題(One-shot learning problem),這意味著在大多數(shù)人臉識別應(yīng)用中,你需要通過單單一張圖片或者單單一個人臉樣例就能去識別這個人。例如Andrew NG展示的百度員工上班的門禁系統(tǒng)。

?

二、模型

By using a 128-neuron fully connected layer as its last layer, the model ensures that the output is an encoding vector of size 128.By computing a distance between two encodings and thresholding(0.7), you can determine if the two pictures represent the same person.

?

1、Siamese 網(wǎng)絡(luò)(Siamese network)

對于兩個不同的輸入,運行相同的卷積神經(jīng)網(wǎng)絡(luò),然后比較它們,這一般叫做Siamese網(wǎng)絡(luò)架構(gòu)。怎么訓練這個Siamese神經(jīng)網(wǎng)絡(luò)呢?不要忘了這兩個網(wǎng)絡(luò)有相同的參數(shù),所以你實際要做的就是訓練一個網(wǎng)絡(luò),它計算得到的編碼(encoding)可以用于計算距離,它可以告訴你兩張圖片是否是同一個人。

?

2、Inception?模型

(1)Inception 模塊

?

將學這些模塊組合起來,構(gòu)筑就可以構(gòu)建Inception網(wǎng)絡(luò)。

?

?

(2)實現(xiàn)Inception Network的代碼

import tensorflow as tf import numpy as np import os from numpy import genfromtxt from keras import backend as K 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 import fr_utils from keras.layers.core import Lambda, Flatten, Densedef inception_block_1a(X):"""Implementation of an inception block"""X_3x3 = Conv2D(96, (1, 1), data_format='channels_first', name ='inception_3a_3x3_conv1')(X)X_3x3 = BatchNormalization(axis=1, epsilon=0.00001, name = 'inception_3a_3x3_bn1')(X_3x3)X_3x3 = Activation('relu')(X_3x3)X_3x3 = ZeroPadding2D(padding=(1, 1), data_format='channels_first')(X_3x3)X_3x3 = Conv2D(128, (3, 3), data_format='channels_first', name='inception_3a_3x3_conv2')(X_3x3)X_3x3 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3a_3x3_bn2')(X_3x3)X_3x3 = Activation('relu')(X_3x3)X_5x5 = Conv2D(16, (1, 1), data_format='channels_first', name='inception_3a_5x5_conv1')(X)X_5x5 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3a_5x5_bn1')(X_5x5)X_5x5 = Activation('relu')(X_5x5)X_5x5 = ZeroPadding2D(padding=(2, 2), data_format='channels_first')(X_5x5)X_5x5 = Conv2D(32, (5, 5), data_format='channels_first', name='inception_3a_5x5_conv2')(X_5x5)X_5x5 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3a_5x5_bn2')(X_5x5)X_5x5 = Activation('relu')(X_5x5)X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)X_pool = Conv2D(32, (1, 1), data_format='channels_first', name='inception_3a_pool_conv')(X_pool)X_pool = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3a_pool_bn')(X_pool)X_pool = Activation('relu')(X_pool)X_pool = ZeroPadding2D(padding=((3, 4), (3, 4)), data_format='channels_first')(X_pool)X_1x1 = Conv2D(64, (1, 1), data_format='channels_first', name='inception_3a_1x1_conv')(X)X_1x1 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3a_1x1_bn')(X_1x1)X_1x1 = Activation('relu')(X_1x1)# CONCATinception = concatenate([X_3x3, X_5x5, X_pool, X_1x1], axis=1)return inceptiondef inception_block_1b(X):X_3x3 = Conv2D(96, (1, 1), data_format='channels_first', name='inception_3b_3x3_conv1')(X)X_3x3 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_3x3_bn1')(X_3x3)X_3x3 = Activation('relu')(X_3x3)X_3x3 = ZeroPadding2D(padding=(1, 1), data_format='channels_first')(X_3x3)X_3x3 = Conv2D(128, (3, 3), data_format='channels_first', name='inception_3b_3x3_conv2')(X_3x3)X_3x3 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_3x3_bn2')(X_3x3)X_3x3 = Activation('relu')(X_3x3)X_5x5 = Conv2D(32, (1, 1), data_format='channels_first', name='inception_3b_5x5_conv1')(X)X_5x5 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_5x5_bn1')(X_5x5)X_5x5 = Activation('relu')(X_5x5)X_5x5 = ZeroPadding2D(padding=(2, 2), data_format='channels_first')(X_5x5)X_5x5 = Conv2D(64, (5, 5), data_format='channels_first', name='inception_3b_5x5_conv2')(X_5x5)X_5x5 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_5x5_bn2')(X_5x5)X_5x5 = Activation('relu')(X_5x5)X_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3), data_format='channels_first')(X)X_pool = Conv2D(64, (1, 1), data_format='channels_first', name='inception_3b_pool_conv')(X_pool)X_pool = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_pool_bn')(X_pool)X_pool = Activation('relu')(X_pool)X_pool = ZeroPadding2D(padding=(4, 4), data_format='channels_first')(X_pool)X_1x1 = Conv2D(64, (1, 1), data_format='channels_first', name='inception_3b_1x1_conv')(X)X_1x1 = BatchNormalization(axis=1, epsilon=0.00001, name='inception_3b_1x1_bn')(X_1x1)X_1x1 = Activation('relu')(X_1x1)inception = concatenate([X_3x3, X_5x5, X_pool, X_1x1], axis=1)return inceptiondef inception_block_1c(X):X_3x3 = fr_utils.conv2d_bn(X,layer='inception_3c_3x3',cv1_out=128,cv1_filter=(1, 1),cv2_out=256,cv2_filter=(3, 3),cv2_strides=(2, 2),padding=(1, 1))X_5x5 = fr_utils.conv2d_bn(X,layer='inception_3c_5x5',cv1_out=32,cv1_filter=(1, 1),cv2_out=64,cv2_filter=(5, 5),cv2_strides=(2, 2),padding=(2, 2))X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)X_pool = ZeroPadding2D(padding=((0, 1), (0, 1)), data_format='channels_first')(X_pool)inception = concatenate([X_3x3, X_5x5, X_pool], axis=1)return inceptiondef inception_block_2a(X):X_3x3 = fr_utils.conv2d_bn(X,layer='inception_4a_3x3',cv1_out=96,cv1_filter=(1, 1),cv2_out=192,cv2_filter=(3, 3),cv2_strides=(1, 1),padding=(1, 1))X_5x5 = fr_utils.conv2d_bn(X,layer='inception_4a_5x5',cv1_out=32,cv1_filter=(1, 1),cv2_out=64,cv2_filter=(5, 5),cv2_strides=(1, 1),padding=(2, 2))X_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3), data_format='channels_first')(X)X_pool = fr_utils.conv2d_bn(X_pool,layer='inception_4a_pool',cv1_out=128,cv1_filter=(1, 1),padding=(2, 2))X_1x1 = fr_utils.conv2d_bn(X,layer='inception_4a_1x1',cv1_out=256,cv1_filter=(1, 1))inception = concatenate([X_3x3, X_5x5, X_pool, X_1x1], axis=1)return inceptiondef inception_block_2b(X):#inception4eX_3x3 = fr_utils.conv2d_bn(X,layer='inception_4e_3x3',cv1_out=160,cv1_filter=(1, 1),cv2_out=256,cv2_filter=(3, 3),cv2_strides=(2, 2),padding=(1, 1))X_5x5 = fr_utils.conv2d_bn(X,layer='inception_4e_5x5',cv1_out=64,cv1_filter=(1, 1),cv2_out=128,cv2_filter=(5, 5),cv2_strides=(2, 2),padding=(2, 2))X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)X_pool = ZeroPadding2D(padding=((0, 1), (0, 1)), data_format='channels_first')(X_pool)inception = concatenate([X_3x3, X_5x5, X_pool], axis=1)return inceptiondef inception_block_3a(X):X_3x3 = fr_utils.conv2d_bn(X,layer='inception_5a_3x3',cv1_out=96,cv1_filter=(1, 1),cv2_out=384,cv2_filter=(3, 3),cv2_strides=(1, 1),padding=(1, 1))X_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3), data_format='channels_first')(X)X_pool = fr_utils.conv2d_bn(X_pool,layer='inception_5a_pool',cv1_out=96,cv1_filter=(1, 1),padding=(1, 1))X_1x1 = fr_utils.conv2d_bn(X,layer='inception_5a_1x1',cv1_out=256,cv1_filter=(1, 1))inception = concatenate([X_3x3, X_pool, X_1x1], axis=1)return inceptiondef inception_block_3b(X):X_3x3 = fr_utils.conv2d_bn(X,layer='inception_5b_3x3',cv1_out=96,cv1_filter=(1, 1),cv2_out=384,cv2_filter=(3, 3),cv2_strides=(1, 1),padding=(1, 1))X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)X_pool = fr_utils.conv2d_bn(X_pool,layer='inception_5b_pool',cv1_out=96,cv1_filter=(1, 1))X_pool = ZeroPadding2D(padding=(1, 1), data_format='channels_first')(X_pool)X_1x1 = fr_utils.conv2d_bn(X,layer='inception_5b_1x1',cv1_out=256,cv1_filter=(1, 1))inception = concatenate([X_3x3, X_pool, X_1x1], axis=1)return inceptiondef faceRecoModel(input_shape):"""Implementation of the Inception model used for FaceNetArguments:input_shape -- shape of the images of the datasetReturns:model -- a Model() instance in Keras"""# Define the input as a tensor with shape input_shapeX_input = Input(input_shape)# Zero-PaddingX = ZeroPadding2D((3, 3))(X_input)# First BlockX = Conv2D(64, (7, 7), strides = (2, 2), name = 'conv1')(X)X = BatchNormalization(axis = 1, name = 'bn1')(X)X = Activation('relu')(X)# Zero-Padding + MAXPOOLX = ZeroPadding2D((1, 1))(X)X = MaxPooling2D((3, 3), strides = 2)(X)# Second BlockX = Conv2D(64, (1, 1), strides = (1, 1), name = 'conv2')(X)X = BatchNormalization(axis = 1, epsilon=0.00001, name = 'bn2')(X)X = Activation('relu')(X)# Zero-Padding + MAXPOOLX = ZeroPadding2D((1, 1))(X)# Second BlockX = Conv2D(192, (3, 3), strides = (1, 1), name = 'conv3')(X)X = BatchNormalization(axis = 1, epsilon=0.00001, name = 'bn3')(X)X = Activation('relu')(X)# Zero-Padding + MAXPOOLX = ZeroPadding2D((1, 1))(X)X = MaxPooling2D(pool_size = 3, strides = 2)(X)# Inception 1: a/b/cX = inception_block_1a(X)X = inception_block_1b(X)X = inception_block_1c(X)# Inception 2: a/bX = inception_block_2a(X)X = inception_block_2b(X)# Inception 3: a/bX = inception_block_3a(X)X = inception_block_3b(X)# Top layerX = AveragePooling2D(pool_size=(3, 3), strides=(1, 1), data_format='channels_first')(X)X = Flatten()(X)X = Dense(128, name='dense_layer')(X)# L2 normalizationX = Lambda(lambda x: K.l2_normalize(x,axis=1))(X)# Create model instancemodel = Model(inputs = X_input, outputs = X, name='FaceRecoModel')return model

  

3、損失函數(shù):The Triplet Loss

raining will use triplets of images?(A,P,N):

  • A is an "Anchor" image--a picture of a person.
  • P is a "Positive" image--a picture of the same person as the Anchor image.
  • N is a "Negative" image--a picture of a different person than the Anchor image.

These triplets are picked from our training dataset. We will write?(A(i),P(i),N(i))?to denote the?i-th training example.?

?You'd like to make sure that an image?A(i)of an individual is closer to the Positive?P(i)?than to the Negative image?N(i)?by at least a margin?α:

?

You would thus like to minimize the following "triplet cost":

Here, we are using the notation "[z]+" to denote?max(z,0).

Notes:

  • The term (1) is the squared distance between the anchor "A" and the positive "P" for a given triplet; you want this to be small.
  • The term (2) is the squared distance between the anchor "A" and the negative "N" for a given triplet, you want this to be relatively large, so it thus makes sense to have a minus sign preceding it.
  • α?is called the margin. It is a hyperparameter that you should pick manually. We will use?α=0.2.

?Most implementations also normalize the encoding vectors to have norm equal one (i.e.,?f(img)2=1); you won't have to worry about that here.

?

4、model compile

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

?The pretrained model we use is inspired by Victor Sy Wang's implementation and was loaded using his code:?https://github.com/iwantooxxoox/Keras-OpenFace.

?

5、輸入輸出數(shù)據(jù)類型

(1)輸入數(shù)據(jù):This network uses 96x96 dimensional RGB images as its input. Specifically, inputs a face image (or batch of?m?face images) as a tensor of shape?(m,nC,nH,nW)=(m,3,96,96)

(2)輸出數(shù)據(jù):It outputs a matrix of shape?(m,128)?that encodes each input face image into a 128-dimensional vector

?

6、總結(jié)

  • Face verification solves an easier 1:1 matching problem; face recognition addresses a harder 1:K matching problem.
  • The triplet loss is an effective loss function for training a neural network to learn an encoding of a face image.
  • The same encoding can be used for verification and recognition. Measuring distances between two images' encodings allows you to determine whether they are pictures of the same person.

?

轉(zhuǎn)載于:https://www.cnblogs.com/hezhiyao/p/8653081.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的项目总结二:人脸识别项目(Face Recognition for the Happy House)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久一区国产 | 成人av教育 | 亚洲特黄视频 | 欧美日本中文字幕 | japanese在线观看 | 欧美日韩a√| 激情毛片视频 | 国产欧美亚洲精品 | 黄色片网站免费在线观看 | 人妻无码中文字幕 | 久久亚洲精品无码va白人极品 | 色欲狠狠躁天天躁无码中文字幕 | 欧美美女一区二区三区 | 海角社区id:1220.7126,10. | aaa亚洲| 色婷亚洲| 国产香蕉视频在线观看 | 激情五月婷婷网 | 天天爱综合网 | 日韩一级 | 国产无码精品合集 | 俺去日 | 狠狠噜噜 | 高潮一区二区 | 免费无遮挡无码永久在线观看视频 | 葵司有码中文字幕二三区 | 亚洲成人91 | 免费av的网站 | 国产成人精品久久二区二区 | 亚洲自拍激情 | 东京干手机福利视频 | 亚洲免费成人在线 | 日韩精品123 | 亚洲美女福利视频 | 天天摸日日干 | 中国美女乱淫免费看视频 | 欧美一区二区黄片 | 国产视频1区2区 | 国产专区一区 | 久久久久久爱 | 久久xx | 国产制服av | 一区二区国产精品精华液 | 国产成人专区 | 国产农村妇女毛片精品久久麻豆 | 91久久精品www人人做人人爽 | 无码人妻精品中文字幕 | 九色视频91 | 在线免费91| 中文字幕免费一区二区 | 一级大片免费观看 | 欧美大色网 | 亚洲天堂2013 | 成人一级片视频 | 欧美日韩成人一区二区 | 黄色片女人 | 日韩激情文学 | 亚洲av成人无码久久精品 | 亚洲综合网址 | 牲欲强的熟妇农村老妇女视频 | 国产a网| 伊人国产视频 | 国产成人久久精品麻豆二区 | 最新av电影网站 | 七月婷婷综合 | 亚洲a色| 午夜鲁鲁| 麻豆三级在线观看 | 青青草激情视频 | 国产一级片精品 | 国产亚洲av在线 | 久久极品 | 欧美激情国产一区 | 欧美日韩一二三四区 | 天天射日日干 | 天天舔天天射天天干 | 久久综合一区二区三区 | 欧美高清一区二区 | 一个色综合网 | 涩涩国产| 欧美日韩在线视频观看 | 久久久精品99| 午夜视频一区二区三区 | jizz亚洲女人高潮大叫 | 黄a网站| 亚洲一区二区国产精品 | 女仆裸体打屁屁羞羞免费 | 朝桐光av一区二区三区 | 国产免费a级片 | 国语对白久久 | 在线国产网站 | 手机在线亚洲 | 日本va欧美va欧美va精品 | 亚洲综合一区二区 | 超碰免费视 | 久久免费国产视频 | 亚洲av无码乱码国产麻豆 | 中文字幕无线精品亚洲乱码一区 | 中文字幕第一区综合 |