基於tensorflow的人臉識別技術(facenet)的測試
阿新 • • 發佈:2019-01-26
人臉識別的應用非常廣泛,而且進展特別快。如LFW的評測結果上已經都有快接近99.9%的。
0.9900 ± 0.0032 | |
FaceNet62 | 0.9963 ± 0.0009 |
Baidu64 | 0.9977 ± 0.0006 |
MMDFR67 | 0.9902 ± 0.0019 |
0.9950 ± 0.0022 | |
0.9967 ± 0.0007 | |
0.9887 ± 0.0016 | |
0.9955 ± 0.0014 | |
pose+shape+expression augmentation75 | 0.9807 ± 0.0060 |
0.9940 ± 0.0022 | |
0.9815 ± 0.0039 | |
0.9968 ± 0.0009 | |
0.9630 ± 0.0023 | |
0.9895 ± 0.0020 | |
dlib90 | 0.9938 ± 0.0027 |
0.9920 ± 0.0030 | |
0.9965 ± 0.0032 | |
0.9940 ± 0.0040 | |
0.9968 ± 0.0030 | |
0.9923 ± 0.0016 | |
0.9982 ± 0.0007 |
在上述模型中,有許多是商業公司的排名,所以呢,基本上很少有開源的東西。此處只對谷歌的facenet進行測試。
FaceNet的架構如下所示:
從上面可以看出,沒有使用softmax層,而直接利用L2層正則化輸出,獲取其影象表示,即特徵抽象層。而深度學習的框架可以使用現有的成熟模型,如tensorflow slim中的每一種模型。
而最後一個Triplet Loss則是採用了三元組的損失函式。其程式碼如下所示
def triplet_loss(anchor, positive, negative, alpha): """Calculate the triplet loss according to the FaceNet paper Args: anchor: the embeddings for the anchor images. positive: the embeddings for the positive images. negative: the embeddings for the negative images. Returns: the triplet loss according to the FaceNet paper as a float tensor. """ with tf.variable_scope('triplet_loss'): pos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, positive)), 1) neg_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, negative)), 1) basic_loss = tf.add(tf.subtract(pos_dist,neg_dist), alpha) loss = tf.reduce_mean(tf.maximum(basic_loss, 0.0), 0) return loss
從上面程式碼可以看出,三元組其實就是三個樣例,如(anchor, pos, neg),利用距離關係來判斷。即在儘可能多的三元組中,使得anchor和pos正例的距離,小於anchor和neg負例的距離。
其學習優化如下圖所示:
測試:(程式碼見:https://github.com/davidsandberg/facenet)
由於facenet無需限制人臉對齊,但是程式碼中提供了MTCNN的對齊,而且在LFW評分中也發現經過對齊的分數能夠提高一個檔次。
利用提供的程式碼,在LFW上進行EVAL,發現其精度高達99.2%
當然,還有更高的。
另外,程式中還提供了進行兩張圖片距離的比較的程式碼,進行除錯,結果如下: