人脸检测:Viola-Jones
這篇論文是2001年投稿、2004年發(fā)表的,作者是Paul Viola和Michael J. Jones。有趣的是當年的論文需要兩年的審議時間,而如今兩個月前的論文就可能過時了,時代在變化。
這篇論文實現(xiàn)了實時的人臉檢測算法,是人臉檢測這一問題最重要的論文之一,現(xiàn)在的OpenCV中人臉檢測的方法就是基于這一論文。
概述
目標檢測任務框架中有三個問題:1、如何選擇待檢測區(qū)域;2、如何提取目標特征;3、如何判斷是不是指定目標。針對這三個問題,Viola-Jones給出的答案是:滑動窗口法,Haar-like特征和Cascading AdaBoost分類器。
人臉檢測
滑動窗口法
使用矩形框,依次滑動遍歷整個圖像,然后不斷增加矩形框的大小,繼續(xù)遍歷。這樣便可以檢測出不同大小的人臉區(qū)域,缺點是檢測的矩形框會有很多,影響速度。
Haar特征
Haar特征就是兩個矩形區(qū)域像素值和相減。如上圖所示,就是拿黑色區(qū)域的像素值和減去白色區(qū)域像素值的和。這樣的矩形窗選擇有很多種,最后得到的Haar特征非常的大,24*24的區(qū)域可以得到160000維特征。
積分圖
在Haar特征的計算中,主要就是求和并相減。如果每個窗口都這樣做,非常影響速度,其中的很多求和操作都是重復的。作者使用了積分圖加快求Haar特征這一操作。
(x,y)處積分圖的值就是該點左上角所有像素值的和。
當計算區(qū)域D的像素和時,只需要使用4+1-(2+3)即可,這樣就避免了多次的求和計算。
級聯(lián)Adaboost
AdaBoost
得到特征以后,如何判斷是不是人臉呢?這時候使用AdaBoost作為人臉的分類器。AdaBoost是一種用于分類的機器學習方法,它使用多個弱分類器組合形成一個強分類器,這部分具體內容可以看看維基百科或者李航的《統(tǒng)計學習方法》。 使用AdaBoost的意義在于:從大量的潛在的候選特征集合中選出少量的關鍵視覺特征。Haar特征維數(shù)龐大,必須借助AdaBoost選取其中最關鍵的一些特征。
級聯(lián)
作者使用多個AdaBoost分類器進行級聯(lián)來區(qū)分是否是人臉。這些分類器中,越往后越復雜,相應的計算時間也就越長。每一級的分類器都將本級分類器認為是圖像的背景區(qū)域(無人臉區(qū)域)丟棄掉, 以便下一級的分類器能夠將主要的計算力和精力放在更像是人臉的區(qū)域。只要前面任何一級認為該區(qū)域不是人臉,那么就停止檢測的過程,檢測窗口滑動到下一個矩形區(qū)域。 作者在論文中采用的分類器的個數(shù)為38個, 盡管分類器的數(shù)目很多, 但是由于采用了這種級聯(lián)的結構使得檢測速度得到提升。
綜合起來,看段視頻就清楚了:
http://weibo.com/tv/v/DnL35Ch2r?fid=1034:9fdac15750897f55067bc247c2c6c6c2
結果
這篇論文發(fā)表于2001年,在700 MHz Pentium III處理器上,384*288的圖片檢測時間為0.067s。
總結
這篇論文是人臉檢測的重要論文之一,它標志著人臉檢測問題達到實用。在OpenCV中的人臉檢測就是使用了這個算法。目標檢測問題框架中有三個問題:1、如何選擇待檢測區(qū)域;2、如何提取目標特征;3如何判斷是不是指定對象。這幾年流行的R-CNN方法也是這樣的框架,只是對其中的一些步驟進行了優(yōu)化。
<p style="letter-spacing:.5px;color:rgb(62,62,62);font-size:16px;margin-left:0em;"><span style="letter-spacing:.5px;"><span style="color:rgb(133,118,106);font-size:12.6316px;text-align:justify;"> 作者丨葛政</span><span style="color:rgb(133,118,106);font-size:12.6316px;"></span></span></p><p style="letter-spacing:0px;margin-left:0em;color:rgb(62,62,62);font-size:16px;line-height:1.5em;"><span style="color:rgb(133,118,106);font-size:12.6316px;letter-spacing:.5px;">學校丨<span style="color:rgb(133,118,106);font-size:12.6316px;letter-spacing:3px;text-align:justify;">早稻田大學碩士生</span></span></p><p style="letter-spacing:0px;margin-left:0em;color:rgb(62,62,62);font-size:16px;line-height:1.5em;"><span style="color:rgb(133,118,106);font-size:12.6316px;letter-spacing:.5px;">研究方向丨深度學習,計算機視覺</span></p><p style="letter-spacing:0px;margin-left:0em;color:rgb(62,62,62);font-size:16px;line-height:1.5em;"><span style="color:rgb(133,118,106);font-size:12.6316px;letter-spacing:.5px;"><span style="color:rgb(133,118,106);font-size:12.6316px;letter-spacing:.5px;">個人博客丨Xraft.Lab</span></span></p><p style="line-height:1.75em;"><br></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">相信做機器學習或深度學習的同學們回家總會有這樣一個煩惱:<strong>親朋好友詢問你從事什么工作的時候,如何通俗地解釋能避免尷尬?</strong></span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">我嘗試過很多名詞來形容自己的工作:機器學習,深度學習,算法工程師/研究員,搞計算機的,程序員…這些詞要么自己覺得不滿意,要么對方聽不懂。經歷無數(shù)次失敗溝通,<strong>最后總結了一個簡單實用的答案:“做人臉識別的”</strong>。</span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">為什么這個答案管用,因為人臉識別在深度學習相關領域的課題中屬于商業(yè)落地情景多,被普及率廣的一項技術,以至于誰說不出幾個人臉識別應用,都有那么點落后于時代的意思。</span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">今天出這篇人臉識別,是基于我過去三個月在人臉識別方向小小的探索,希望能<strong>為非技術從業(yè)者提供人臉識別的基本概念</strong>(第一部分),以及<strong>為人臉識別愛好者和入門人員提供儲備知識和實驗數(shù)據(jù)參考</strong>(第二、第三部分),也歡迎專業(yè)人士提供寶貴的交流意見。 </span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><strong><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">本文將從接下來三個方面介紹人臉識別</span></strong><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">,讀者可根據(jù)自身需求選擇性閱讀:</span></p><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;"><br></span></p><ul class="list-paddingleft-2" style="list-style-type:disc;"><li><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">Chapter 1:人臉識別是什么?怎么識別? </span></p></li><li><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">Chapter 2:科研領域近期進展 </span></p></li><li><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);line-height:1.75em;text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;text-align:justify;letter-spacing:.5px;">Chapter 3:實驗及細節(jié)</span></p></li></ul><p style="letter-spacing:.5px;font-size:16px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><br></p><h1 style="font-weight:bold;color:rgb(62,62,62);line-height:1.2;border-left-color:rgb(16,142,233);font-size:20px !important;border-left-width:6px !important;border-left-style:solid !important;letter-spacing:1px !important;word-spacing:1px !important;"><a name="t0"></a><span style="letter-spacing:.5px;">Chapter 1</span></h1><p style="text-align:justify;line-height:normal;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(51,51,51);letter-spacing:.5px;font-size:18px;">人臉識別是什么</span></strong><br></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">人臉識別問題宏觀上分為兩類:1. 人臉驗證(又叫人臉比對)2. 人臉識別。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">人臉驗證做的是 1 比 1 的比對,即判斷兩張圖片里的人是否為同一人。<strong>最常見的應用場景便是人臉解鎖</strong>,終端設備(如手機)只需將用戶事先注冊的照片與臨場采集的照片做對比,判斷是否為同一人,即可完成身份驗證。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">人臉識別做的是 1 比 N 的比對,即判斷系統(tǒng)當前見到的人,為事先見過的眾多人中的哪一個。比如<strong>疑犯追蹤,小區(qū)門禁,會場簽到,以及新零售概念里的客戶識別</strong>。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;">這些應用場景的共同特點是:人臉識別系統(tǒng)都事先存儲了大量的不同人臉和身份信息,系統(tǒng)運行時需要將見到的人臉與之前存儲的大量人臉做比對,找出匹配的人臉。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;">兩者在早期(2012年~2015年)是通過不同的算法框架來實現(xiàn)的,想同時擁有人臉驗證和人臉識別系統(tǒng),需要分開訓練兩個神經網絡。而 2015 年 Google 的 <strong>FaceNet</strong> <span style="color:rgb(136,136,136);font-size:15px;letter-spacing:.5px;text-align:justify;">[1]</span> 論文的發(fā)表改變了這一現(xiàn)狀,將兩者統(tǒng)一到一個框架里。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(51,51,51);letter-spacing:.5px;">人臉識別,怎么識別</span></strong></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">這部分只想闡明一個核心思想:<strong>不同人臉由不同特征組成</strong>。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">理解這個思想,首先需要引入的的是“特征”的概念。先看下面這個例子:</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/f39a94ac1ee6e9e9b7be8beb43d6e00b.png" alt="640"></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">假設這 5 個特征足夠形容一張人臉,那每張人臉都可表示為這 5 個特征的組合:</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:center;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"> (特征1,特征2,特征3,特征4,特征5)</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">一位雙眼皮,挺鼻梁,藍眼睛,白皮膚,瓜子臉的歐美系小鮮肉即可用特征表示為(見表格加粗項): </span></p><p style="letter-spacing:.5px;text-align:center;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:center;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">(1,1,0,1,0)</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">那么遍歷上面這張?zhí)卣鞅砀褚还部梢源?lt;/span><img src="https://img-blog.csdnimg.cn/img_convert/b355702d7f5632ffd1475c16f27a1b72.png" alt="640"><span style="color:rgb(51,51,51);font-size:15px;">張不同的臉。32 張臉可遠遠不夠覆蓋 70 多億的人口。為了讓不同特征組成的人臉能覆蓋足夠多人臉,我們需要擴充上面那張?zhí)卣鞅怼U張?zhí)卣鞅砜梢詮男小⒘袃蓚€角度展開。 </span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">列的角度很簡單,只需要增加特征數(shù)量:(特征6.臉型,特征7.兩眼之間距離,特征8.嘴唇厚薄…)實際應用中通常應用 128,256,512 或者 1024 個不同特征,<strong>這么多特征從哪來</strong>,該不會人為一個一個去設計吧?這個問題在后面會解答。 </span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">從行的角度擴充也很好理解,比如“特征3”,除了值 0 代表藍色,值 1 代表灰色,是不是可以增加一個值 2 代表黑色,值 3 代表沒有頭發(fā)呢?此外,除了這些離散的整數(shù),我們也可以取連續(xù)的小數(shù),比如特征 3 的值 0.1,代表“藍中略微帶黑”,值 0.9 代表“灰中帶藍”……</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">經過這樣的擴充,特征空間便會變得無限大。擴充后特征空間里的一張臉可能表示為: </span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:center;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">(0, 1, 0.3, 0.5, 0.1, 2, 2.3, 1.75,…)</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">之前提出的問題:<strong>用于表示人臉的大量特征從哪來?</strong>這便是深度學習(深度神經網絡)發(fā)揮作用的地方。它通過在千萬甚至億級別的人臉數(shù)據(jù)庫上學習訓練后,會自動總結出最適合于計算機理解和區(qū)分的人臉特征。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">算法工程師通常需要一定的可視化手段才能知道機器到底學習到了哪些利于區(qū)分不同人的特征,當然這部分不是本節(jié)重點。 </span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">闡明了<strong>不同人臉由不同特征組成</strong>后,我們便有了足夠的知識來分析人臉識別,到底怎么識別。 </span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">現(xiàn)在考慮最簡單最理想的情況,用于區(qū)分不同人的特征只有兩個:特征1和特征2。那么每一張臉都可以表示為一個坐標(特征1,特征2),即特征空間(這個例子里是二維空間)內的一個點。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">人臉識別基于一個默認成立的假設:<strong>同一個人在不同照片里的臉,在特征空間里非常接近</strong>。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">為什么這個假設默認成立,設想一下,一個棕色頭發(fā)的人,在不同光照,遮擋,角度條件下,發(fā)色看起來雖然有輕微的區(qū)別,但依然與真實顏色非常接近,反應在發(fā)色的特征值上,可能是 0 到 0.1 之間的浮動。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;">深度學習的另一任務和挑戰(zhàn)便是在各種極端復雜的環(huán)境條件下,精確的識別各個特征。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/c23a4f2a3998715da1afcaaa2949ef05.png" alt="640"></p><p style="text-align:center;"><br></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(51,51,51);letter-spacing:.5px;"></span><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">上圖是在熊本做大規(guī)模人臉數(shù)據(jù)集去噪演講時用的 PPT,三張山下智久的照片經過神經網絡提取出 128 維的特征后,變成了 3 個在 128 維空間中的點(紅色),石原里美的特征點為綠色。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">這張 PPT 想表達同樣的意思:<strong>同一人的不通照片提取出的特征,在特征空間里距離很近,不同人的臉在特征空間里相距較遠</strong>。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">再來考慮人臉識別領域的兩個問題:<strong>人臉驗證</strong>和<strong>人臉識別</strong>。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(51,51,51);letter-spacing:.5px;text-align:justify;">人臉驗證</span></strong></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">比如 FaceID 人臉解鎖,iPhone 事先存了一張用戶的照片(需要用戶注冊),這張照片變成了轉換成了一連串特征數(shù)值(即特征空間里的一個點),用戶解鎖時,手機只需要對比當前采集到的臉和事先注冊的臉在特征空間里的幾何距離,如果距離足夠近,則判斷為同一人,如果距離不夠近,則解鎖失敗。距離閾值的設定,則是算法工程師通過大量實驗得到的。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(51,51,51);letter-spacing:.5px;text-align:justify;">人臉識別</span></strong></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">同樣考慮一個場景,人臉考勤。公司 X 有員工 A,B,C,公司會要求三名員工在入職的時候各提供一張個人照片用于注冊在公司系統(tǒng)里,靜靜地躺在特征空間中。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">第二天早上員工 A 上班打卡時,將臉對準考勤機器,系統(tǒng)會把當前員工 A 的臉放到特征空間里,與之前特征空間里注冊好的臉一一對比,發(fā)現(xiàn)注冊的臉中距離當前采集到的臉最近的特征臉是員工 A,打卡完畢。</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">知道了人臉識別的基本原理,便能看清它的技術局限。下圖展示了一些容易識別失敗的案例:</span></p><p style="letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/1012c3d54b1c0dbbd993014f5c5d82f6.png" alt="640"></p><p style="text-align:center;"><br></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">在光照較差,遮擋,形變(大笑),側臉等諸多條件下,神經網絡很難提取出與“標準臉”相似的特征,<strong>異常臉在特征空間里落到錯誤的位置,導致識別和驗證失敗</strong>。這是現(xiàn)代人臉識別系統(tǒng)的局限,一定程度上也是深度學習(深度神經網絡)的局限。</span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">面對這種局限,<strong>通常采取三種應對措施,使人臉識別系統(tǒng)能正常運作</strong>:</span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;"><strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">1. 工程角度</span></strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">:</span><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">研發(fā)質量模型,對檢測到人臉質量進行評價,質量較差則不識別/檢驗。</span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;"><strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">2. 應用角度</span></strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">:施加場景限制,比如刷臉解鎖,人臉閘機,會場簽到時,都要求用戶在良好的光照條件下正對攝像頭,以避免采集到質量差的圖片。</span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;"><strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">3. 算法角度</span></strong><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">:提升人臉識別模型性能,在訓練數(shù)據(jù)里添加更多復雜場景和質量的照片,以增強模型的抗干擾能力。</span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;"><span style="color:rgb(51,51,51);font-size:15px;letter-spacing:.5px;text-align:justify;">總而言之,人臉識別/深度學習還遠未達到人們想象的那般智能。希望各位讀者看完第一節(jié)后,有能力分辨社交網絡,自媒體上的信息真?zhèn)?#xff0c;更理性的看待人工智能,給它時間和包容,慢慢成長。</span></p><h1 style="font-weight:bold;color:rgb(62,62,62);line-height:1.2;border-left-color:rgb(16,142,233);font-size:20px !important;border-left-width:6px !important;border-left-style:solid !important;letter-spacing:1px !important;word-spacing:1px !important;text-align:left;"><a name="t1"></a><span style="letter-spacing:.5px;">Chapter 2</span></h1><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:normal;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> 這部分將從兩個思路跟進現(xiàn)代人臉識別算法: </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">思路1</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">:Metric Learning: Contrastive Loss, Triplet loss 及相關 sampling method。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">思路2</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">:Margin Based Classification: 包含 Softmax with Center loss, Sphereface, NormFace, AM-softmax (CosFace) 和 ArcFace. </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">關鍵字</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">:DeepID2, Facenet, Center loss, Triplet loss, Contrastive Loss, Sampling method, Sphereface, Additive Margin Softmax (CosFace), ArcFace. </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(63,63,63);letter-spacing:.5px;"><br></span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="font-size:18px;color:rgb(63,63,63);letter-spacing:.5px;">思路1:Metric Learning </span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">Contrastive Loss</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">基于深度學習的人臉識別領域最先應用 Metric Learning 思想之一的便是 <strong>DeepID2</strong> </span><span style="font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);">[2]</span><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> 了,同 Chapter 1 的思想,“特征”在這篇文章中被稱為“DeepID Vector”。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">DeepID2 在同一個網絡同時訓練 Verification 和 Classification(即有兩個監(jiān)督信號)</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">。其中 Verification Loss 便在特征層引入了 Contrastive Loss。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">Contrastive Loss 本質上是使同一個人的照片在特征空間距離足夠近,不同人在特征空間里相距足夠遠直到超過某個閾值 m(聽起來和 Triplet Loss 很像)。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">基于這樣的 insight,DeepID2 在訓練的時候不是以一張圖片為單位了,而是以 Image Pair 為單位,每次輸入兩張圖片,為同一人則 Verification Label 為 1,不是同一人則 Label 為 -1,參數(shù)更新思路見下面公式(截自 DeepID2 論文):</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/f96d60a98de56cf9e9c005bb53f72c6d.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">DeepID2 在 14 年是人臉領域非常有影響力的工作,也掀起了在人臉領域引進 Metric Learning 的浪潮。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">Triplet Loss from FaceNet </span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">這篇 15 年來自 Google 的 FaceNet 同樣是人臉識別領域的分水嶺性工作。不僅僅因為他們成功應用了 Triplet Loss 在 benchmark 上取得 state-of-art 的結果,更因為他們<strong>提出了一個絕大部分人臉問題的統(tǒng)一解決框架</strong>,即:識別、驗證、搜索等問題都可以放到特征空間里做,需要專注解決的僅僅是如何將人臉更好的映射到特征空間。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">為此,Google 在 DeepID2 的基礎上,拋棄了分類層即 Classification Loss,將 Contrastive Loss 改進為 Triplet Loss,只為了一個目的:<strong>學到更好的 feature</strong>。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">Triplet Loss 的思想也很簡單,輸入不再是 Image Pair,而是三張圖片(Triplet),分別為 Anchor Face,Negative Face 和 Positive Face。Anchor 與 Positive Face 為同一人,與 Negative Face 為不同人。那么 Triplet Loss 的損失即可表示為:</span><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img src="https://img-blog.csdnimg.cn/img_convert/3c98f74d94515313ab9a609526fd9d4e.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"></span><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">直觀解釋為:在特征空間里 Anchor 與 Positive 的距離要小于 Anchor 與 Negative 的距離超過一個 Margin Alpha。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">有了良好的人臉特征空間,人臉問題便轉換成了 Chapter 1 末尾形容的那樣簡單直觀。附上一張我制作的 Contrastive Loss 和 Triplet Loss 的 PPT:</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/7b06d46afdad1dc58161f85191997964.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><strong><br></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(63,63,63);">Metric Learning 的問題 </span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">基于 Contrastive Loss 和 Triplet Loss 的 Metric Learning 符合人的認知規(guī)律,在實際應用中也取得了不錯的效果,但是它<strong>有非常致命的兩個問題</strong>,使應用它們的時候猶如 pain in the ass。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">1. 模型需要很很很很很很很很很很很很很很長時間才能擬合</span></strong><span style="color:rgb(63,63,63);font-size:15px;">(months mentioned in FaceNet paper),Contrastive Loss 和 Triplet Loss 的訓練樣本都基于 pair 或者 triplet 的,可能的樣本數(shù)是 O (N2) 或者 O (N3) 的。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">當訓練集很大時,基本不可能遍歷到所有可能的樣本(或能提供足夠梯度額的樣本),所以一般來說需要很長時間擬合。我在 10000 人,500,000 張左右的亞洲數(shù)據(jù)集上花了近一個月才擬合。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">2. 模型好壞很依賴訓練數(shù)據(jù)的 Sample 方式</span></strong><span style="color:rgb(63,63,63);font-size:15px;">,理想的 Sample 方式不僅能提升算法最后的性能,更能略微加快訓練速度。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">關于這兩個問題也有很多學者進行了后續(xù)研究,下面的內容作為 Metric Learning 的延伸閱讀,不會很詳細。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(63,63,63);">Metric Learning 延伸閱讀</span></strong></span><strong><span style="color:rgb(63,63,63);font-size:15px;"> </span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">1. Deep Face Recognition </span><span style="font-size:15px;color:rgb(136,136,136);">[3]</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;"><br></span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">為了加速 Triplet Loss 的訓練,這篇文章先用傳統(tǒng)的 softmax 訓練人臉識別模型</span></strong><span style="color:rgb(63,63,63);font-size:15px;">,因為 Classficiation 信號的強監(jiān)督特性,模型會很快擬合(通常小于 2 天,快的話幾個小時)。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">之后移除頂層的 Classificiation Layer,用 Triplet Loss 對模型進行特征層 finetune,取得了不錯的效果。<strong>此外這篇論文還發(fā)布了人臉數(shù)據(jù)集 VGG-Face</strong>。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;"><br></span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">2. In Defense of the Triplet Loss for Person Re-Identification </span><span style="font-size:15px;color:rgb(136,136,136);">[4]</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">這篇文章提出了三個非常有意思的觀點:</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><ul class="list-paddingleft-2" style="list-style-type:disc;"><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">作者說實驗中,平方后的歐幾里得距離(Squared Euclidean Distance)表現(xiàn)不如開方后的真實歐幾里得距離(Non-squared Euclidean Distance),直白來說就是把下圖公式中的平方摘掉。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p></li><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">提出了 Soft-Margin 損失公式替代原始的 Triplet Loss 表達式。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p></li><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"> 引進了 Batch Hard Sampling。</span><br></p></li></ul><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img src="https://img-blog.csdnimg.cn/img_convert/a4c1dddeaf5b96d49ddcb2144711a57b.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">3. Sampling Matters in Deep Embedding Learning </span></strong><span style="color:rgb(136,136,136);"><strong><span style="font-size:15px;letter-spacing:.5px;">[5]</span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">這篇文章提出了兩個有價值的點:</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><ul class="list-paddingleft-2" style="list-style-type:disc;"><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> 從導函數(shù)角度解釋了為什么第 2 點中提到的 <span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">Non-squared Distance</span> 比 Squared-distance 好,并在這個 insight 基礎上提出了 Margin Based Loss(本質還是 Triplet Loss 的 variant,見下圖,圖片取自原文)。</span></p><p style="line-height:1.75em;"><br></p></li><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">提出了 Distance Weighted Sampling。文章說 FaceNet 中的 Semi-hard Sampling,Deep Face Recognition</span><span style="font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);"> [3]</span><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> 中的 Random Hard 和 </span><span style="font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);">[4] </span><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">中提到的 Batch Hard 都不能輕易取到會產生大梯度(大 loss,即對模型訓練有幫助的 triplets),然后從統(tǒng)計學的視角使用了 Distance Weighted Sampling Method。</span></p></li></ul><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/a952d319548e938ab562c9777e89bba2.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"> <br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">4. 我的實驗感想</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><ul class="list-paddingleft-2" style="list-style-type:disc;"><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">2、3 點中提到的方式在試驗中都應用過,直觀感受是 Soft-Margin 和Margin Based Loss 都比原始的 Triplet Loss 好用,但是 Margin Based Loss 實驗中更優(yōu)越。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p></li><li><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">Distance Weighted Sampling Method 沒有明顯提升。 </span></p></li></ul><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;">延伸閱讀中有提到大家感興趣的論文,可參考 reference 查看原文。最后,值得注意的是,<strong>Triplet Loss 在行人重識別領域也取得了不錯的效果</strong>,雖然很可能未來會被 Margin Based Classfication 打敗。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:left;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(63,63,63);">思路2:Margin Based Classification </span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">顧名思義,Margin Based Classficiation 不像在 feature 層直接計算損失的 Metric Learning 那樣,對 feature 加直觀的強限制,而是<strong>依然把人臉識別當 classification 任務進行訓練</strong>,通過對 softmax 公式的改造,間接實現(xiàn)了對 feature 層施加 margin 的限制,使網絡最后得到的 feature 更 discriminative。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">這部分先從 <strong>Sphereface</strong></span><span style="font-size:15px;color:rgb(136,136,136);"> [6] </span><span style="color:rgb(63,63,63);font-size:15px;">說起。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">Sphereface </span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">先跟隨作者的 insight 理下思路(圖截自原文):</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/e44f9dc2d085c496632aeb8d2f860eec.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">圖 (a) 是用原始 softmax 損失函數(shù)訓練出來的特征,圖 (b) 是歸一化的特征。不難發(fā)現(xiàn)在 softmax 的特征從角度上來看有 latent 分布。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">那么為何不直接去優(yōu)化角度呢?<strong>如果把分類層的權重歸一化</strong>,并且不考慮偏置的話,就得到了改進后的損失函數(shù):</span><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/49782f9d6a1562b5692932b5d5d63f6d.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">不難看出,對于特征 x_i,該損失函數(shù)優(yōu)化的方向是使得其向該類別 y_i 中心靠近,并且遠離其他的類別中心。這個目標跟人臉識別目標是一致的,最小化類內距離并且最大化類間距離。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">然而為了保證人臉比對的正確性,還要保證最大類內距離還要小于最小類間距離。上面的損失函數(shù)并不能保證這一點。所以作者引入了 margin 的思想,這跟 Triples Loss 里面引入 Margin Alpha 的思想是一致的。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">那么作者是如何進一步改進上式,引入 margin 的呢?</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">上式紅框中是樣本特征與類中心的余弦值,我們的目標是縮小樣本特征與類中心的角度,即增大這個值。換句話說,如果這個值越小,損失函數(shù)值越大,即我們對偏離優(yōu)化目標的懲罰越大。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">也就是說,這樣就能進一步的縮小類內距離和增大類間距離,達到我們的目標。基于這樣的思想最終的損失函數(shù)為如下:</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/b00095bf8e065591e754d1054de6ea3a.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">原始的 cos(θ) 被換成了 phi(θ),phi(θ) 的最簡單形式其實是 cos(mθ),之所以在原文中變得復雜,只是為了將定義域擴展到 [0,2π] 上,并保證在定義域內單調遞減。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">而這個 m 便是增加的 margin 系數(shù)。當 m=1 時,phi(θ) 等于 cos(θ),當 m>1 時,phi 變小,損失變大。超參 m 控制著懲罰力度,m 越大,懲罰力度越大。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">為計算方便,m 一般設為整數(shù)。作者從數(shù)學上證明了,m>=3 就能保證最大類內距離小于最小類間距離。實現(xiàn)的時候使用倍角公式。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">另外:Sphereface 的訓練很 tricky,關于其訓練細節(jié),這篇文章并沒有提到,而是參考了作者前一篇文章 </span><span style="font-size:15px;color:rgb(136,136,136);">[10]</span><span style="color:rgb(63,63,63);font-size:15px;">。有關訓練細節(jié)讀者也可以去作者 Github 上去尋找,issues 里面有很多討論。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;"><br></span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;">Normface</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">Sphereface 效果很好,但是它不優(yōu)美。在測試階段,Sphereface 通過特征間的余弦值來衡量相似性,即以角度為相似性的度量。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">但在訓練階段,不知道讀者有沒有注意到,其實 Sphereface 的損失函數(shù)并不是在直接優(yōu)化特征與類中心的角度,而是優(yōu)化特征與類中心的角度在乘上一個特征的長度。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">也就是說,我在上文中關于 Sphereface 損失函數(shù)優(yōu)化方向的表述是不嚴謹?shù)?#xff0c;其實優(yōu)化的方向還有一部分是去增大特征的長度去了。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">我在 MNIST 數(shù)據(jù)集上做過實驗,以下圖片分別為 m=1 和 m=4 時的特征可視化,注意坐標的尺度,就能驗證上述觀點。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/ac0a2bbd4c66c614dca63ae3eef5cdfa.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">然而特征的長度在我們使用模型的時候是沒有幫助的。這就造成了 training 跟 test 之間目標不一致,按照 Normface 作者原話說就是存在一個 gap。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;">于是 Normface 的核心思想就出來了:<strong>為何在訓練的時候不把特征也做歸一化處理?</strong>相應的損失函數(shù)如下:</span><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/eaeef829594306b906bf36bd374ee383.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">其中 W 是歸一化的權重,f_i 是歸一化的特征,兩個點積就是角度余弦值。參數(shù) s 的引入是因為數(shù)學上的性質,保證了梯度大小的合理性,原文中有比較直觀的解釋,這里不是重點。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">如果沒有 s 訓練將無法收斂。關于 s 的設置,可以把它設為可學習的參數(shù)。但是作者更推薦把它當做超參數(shù),其值根據(jù)分類類別多少有相應的推薦值,這部分原文 appendix 里有公式。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">文章中還有指出一點,<strong>FaceNet 中歸一化特征的歐式距離,和余弦距離其實是統(tǒng)一的</strong>。還有關于權重與特征的歸一化,這篇文章有很多有意思的探討,有興趣的讀者建議閱讀原文。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">AM-softmax </span></strong><span style="color:rgb(136,136,136);"><strong><span style="font-size:15px;letter-spacing:.5px;text-align:justify;">[11]</span></strong></span><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"> / CosFace </span></strong><span style="color:rgb(136,136,136);"><strong><span style="font-size:15px;letter-spacing:.5px;text-align:justify;">[12]</span></strong></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">這兩篇文章是同一個東西。Normface 用特征歸一化解決了 Sphereface 訓練和測試不一致的問題。但是卻沒有了 margin 的意味。AM-softmax 可以說是在 Normface 的基礎上引入了 margin。直接上損失函數(shù):</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/1f7270c855a16fd2af0cdce0f5d0adab.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">其中這里的權重和特征都是歸一化的。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">直觀上來看,cos(θ)-m 比 cos(θ) 更小,所以損失函數(shù)值比 Normface 里的更大,因此有了 margin 的感覺。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">m 是一個超參數(shù),控制懲罰的力度,m 越大,懲罰越強。作者推薦 m=0.35。這里引入 margin 的方式比 Sphereface 中的‘溫柔’,不僅容易復現(xiàn),沒有很多調參的 tricks,效果也很好。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">ArcFace </span><span style="font-size:15px;letter-spacing:.5px;text-align:justify;color:rgb(136,136,136);">[13]</span><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"> </span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">與 AM-softmax 相比,區(qū)別在于 Arcface 引入 margin 的方式不同,損失函數(shù):</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/0f55c8103d4db4ee79930576ffe243e6.png" alt="640"></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"></span><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">乍一看是不是和 AM-softmax一樣?注意 m 是在余弦里面。文章指出基于上式優(yōu)化得到的特征間的 boundary 更為優(yōu)越,具有更強的幾何解釋。 </span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">然而這樣引入 margin 是否會有問題?仔細想 cos(θ+m) 是否一定比 cos(θ) 小?</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">最后我們用文章中的圖來解釋這個問題,并且也由此做一個本章 Margin-based Classification 部分的總結。</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><br></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong style="font-size:18px;letter-spacing:.5px;text-align:justify;"><span style="color:#3f3f3f;">小結</span></strong></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><strong style="font-size:18px;letter-spacing:.5px;text-align:justify;"><span style="color:#3f3f3f;"><br></span></strong></p><p style="text-align:justify;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/441380fd74c1e730d528de770438e98a.png" alt="640"></p><p style="text-align:justify;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">這幅圖出自于 Arcface,橫坐標為 θ 為特征與類中心的角度,縱坐標為損失函數(shù)分子指數(shù)部分的值(不考慮 s),其值越小損失函數(shù)越大。 </span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">看了這么多基于分類的人臉識別論文,相信你也有種感覺,大家似乎都在損失函數(shù)上做文章,或者更具體一點,大家都是在討論如何設計上圖的 Target logit-θ 曲線。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">這個曲線意味著你要如何優(yōu)化偏離目標的樣本,或者說,根據(jù)偏離目標的程度,要給予多大的懲罰。兩點總結: </span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">1. 太強的約束不容易泛化</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">。例如 Sphereface 的損失函數(shù)在 m=3 或 4 的時候能滿足類內最大距離小于類間最小距離的要求。此時損失函數(shù)值很大,即 target logits 很小。但并不意味著能泛化到訓練集以外的樣本。施加太強的約束反而會降低模型性能,且訓練不易收斂。 </span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">2. 選擇優(yōu)化什么樣的樣本很重要</span></strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">。Arcface 文章中指出,給予 θ∈[60° , 90°] 的樣本過多懲罰可能會導致訓練不收斂。優(yōu)化 θ ∈ [30° , 60°] 的樣本可能會提高模型準確率,而過分優(yōu)化 θ∈[0° , 30°] 的樣本則不會帶來明顯提升。至于更大角度的樣本,偏離目標太遠,強行優(yōu)化很有可能會降低模型性能。</span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">這也回答了上一節(jié)留下的疑問,上圖曲線 Arcface 后面是上升的,這無關緊要甚至還有好處。因為優(yōu)化大角度的 hard sample 可能沒有好處。這和 FaceNet 中對于樣本選擇的 semi-hard 策略是一個道理。 </span></p><p style="text-align:justify;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="color:rgb(63,63,63);letter-spacing:.5px;text-align:justify;"><br></span></strong></span></p><p style="text-align:left;line-height:1.75em;"><span style="font-size:18px;"><strong><span style="font-size:18px;color:rgb(63,63,63);letter-spacing:.5px;text-align:justify;">Margin based classification 延伸閱讀 </span></strong></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><strong><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">1. A discriminative feature learning approach for deep face recognition </span></strong><span style="color:rgb(136,136,136);"><strong><span style="font-size:15px;letter-spacing:.5px;text-align:justify;">[14]</span></strong></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">提出了 center loss,加權整合進原始的 softmax loss。通過維護一個歐式空間類中心,縮小類內距離,增強特征的 discriminative power。 </span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><strong> </strong><strong>2. Large-margin softmax loss for convolutional neural networks </strong></span><span style="font-size:15px;letter-spacing:.5px;text-align:justify;color:rgb(136,136,136);"><strong>[10]</strong></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;">Sphereface 作者的前一篇文章,未歸一化權重,在 softmax loss 中引入了 margin。里面也涉及到 Sphereface 的訓練細節(jié)。 </span></p><p style="text-align:justify;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:15px;letter-spacing:.5px;text-align:justify;"><br></span></p><p style="text-align:justify;line-height:1.75em;"><em><span style="letter-spacing:.5px;text-align:justify;color:rgb(136,136,136);font-size:12px;">注:思路二由陳超撰寫</span></em></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:normal;"><br></p><h1 style="font-weight:bold;color:rgb(62,62,62);line-height:1.2;border-left-color:rgb(16,142,233);font-size:20px !important;border-left-width:6px !important;border-left-style:solid !important;letter-spacing:1px !important;word-spacing:1px !important;"><a name="t2"></a><span style="letter-spacing:.5px;">Chapter 3</span></h1><p style="margin-left:0em;line-height:normal;"><span style="color:rgb(136,136,136);font-size:12px;text-align:justify;letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">基于前兩章的知識,我在 lfw 上取得了 99.47% 的結果,這個結果訓練在 Vggface2 上,未與 lfw 去重,也沒經歷很痛苦的調參過程,算是 AM-softmax 損失函數(shù)直接帶來的收益吧。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">過程中踩了很多坑,這一章將把前段時間的實驗結果和心得做一個整理,此外也將回答絕大部分工程師在做人臉識別時最關心的一些問題。やりましょう! </span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><blockquote><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="text-align:justify;letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);">項目地址:</span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="text-align:justify;letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);"><br></span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="text-align:justify;letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);text-decoration:underline;">https://github.com/Joker316701882/Additive-Margin-Softmax </span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="text-align:justify;letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);text-decoration:underline;"><br></span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="color:rgb(136,136,136);font-size:12px;text-align:justify;">包含代碼可以復現(xiàn)所有實驗結果 </span><br></p></blockquote><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><strong><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">一個標準的人臉識別系統(tǒng)包含這幾個環(huán)節(jié)</span></strong><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">:人臉檢測及特征點檢測->人臉對齊->人臉識別。</span></p><p style="text-align:justify;margin-left:0em;line-height:1.75em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:18px;"><strong><span style="text-align:justify;color:rgb(63,63,63);letter-spacing:.5px;">人臉檢測 & Landmark檢測</span></strong></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">目前最流行的人臉及 Landmark 檢測是 <strong>MTCNN</strong> </span><span style="text-align:justify;font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);">[7]</span><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">,但是 MTCNN 一方面偶爾檢測不到 face,一方面 Landmark 檢測不夠精準。這兩點都會給后續(xù)的對齊和識別帶來不利影響。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">另外在 COCO Loss </span><span style="color:rgb(136,136,136);text-align:justify;font-size:15px;letter-spacing:.5px;">[8</span><span style="text-align:justify;font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);">]</span><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"> 論文里提到:好的檢測和對齊方法,僅用 softmax 就能達到 99.75%,秒殺目前大多數(shù)最新論文的結果。COCO Loss 的 Github issue </span><span style="text-align:justify;font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);">[16]</span><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"> 里提到了更多細節(jié)。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">此外,因為 alignment 算法性能的區(qū)別,2017 年及以后的論文更加注重相對實驗結果的比較,以排除 alignment 算法引入的優(yōu)劣勢,方便更直觀比較各家的人臉識別算法,lfw 上輕松能達到 99% 以上也是現(xiàn)在更傾向于采用相對結果的原因。 </span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:18px;"><strong><span style="text-align:justify;color:rgb(63,63,63);letter-spacing:.5px;">人臉對齊 </span></strong></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">人臉對齊做的是將檢測到的臉和 Landmark 通過幾何變換,將五官變換到圖中相對固定的位置,提供較強的先驗。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">廣泛使用的對齊方法為 Similarity Transformation。更多對其變換方法和實驗可以參考這篇知乎文章 <span style="color:rgb(136,136,136);font-size:15px;letter-spacing:.5px;text-align:justify;">[17]</span>。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><blockquote><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);"><span style="font-size:12px;text-align:justify;letter-spacing:.5px;">作者代碼實現(xiàn):</span></span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);"><span style="font-size:12px;text-align:justify;letter-spacing:.5px;"><br></span></span></p><p style="text-align:left;margin-left:0em;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);"><span style="font-size:12px;text-decoration:underline;">https://github.com/Joker316701882/Additive-Margin-Softmax/blob/master/align/align_lfw.py</span></span></p></blockquote><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><strong><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">值得探討的一個問題是:人臉檢測和對齊真的有必要嗎?</span></strong><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">現(xiàn)實應用中常出現(xiàn)人臉 Landmark 無法檢測的情況,沒有 Landmark 就無法使用 Similarity Transoformation。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">針對這個問題也有相關研究,通過使用 <strong>Spatial Transform Network</strong></span><span style="text-align:justify;font-size:15px;letter-spacing:.5px;color:rgb(136,136,136);"> [9]</span><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"> “讓網絡自己學習 alignment”,論文參考 <strong>End-to-End Spatial Transform Face Detection and Recognition</strong>。這方面的研究進展還不充分,所以實際系統(tǒng)中多數(shù)情況下還是使用了 detection->alignment 這套流程。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:18px;"><strong><span style="text-align:justify;color:rgb(63,63,63);letter-spacing:.5px;">人臉識別</span></strong></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">可以說人臉識別的項目中絕大部分問題都是人臉檢測和對齊的問題。識別模型之間的差距倒沒有那么明顯。不過訓練 AM-softmax 過程中依然碰到了些值得注意的問題。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">Spheraface 里提出的 Resface20,AM-softmax 中也同樣使用,一模一樣復現(xiàn)情況下在 lfw 上只能達到 94%。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">TensorFlow 中能擬合的情況為如下配置:</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><blockquote><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><em><span style="text-align:justify;letter-spacing:.5px;color:rgb(136,136,136);font-size:12px;">Adam, no weight decay, use batch normalization.</span></em></p></blockquote><p style="text-align:justify;margin-left:0em;line-height:1.75em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"> <br></span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(63,63,63);">對應原文配置:</span></p><p style="margin-left:0em;letter-spacing:.5px;text-align:justify;line-height:1.75em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><blockquote style="letter-spacing:.5px;"><p style="margin-left:0em;text-align:justify;line-height:1.75em;"><em><span style="color:rgb(136,136,136);font-size:12px;">Momentum, weight decay, no batch normalization.</span></em></p></blockquote><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">以及在實驗中發(fā)現(xiàn)的: 除了 Adam 以外的任何一個 optimizer 都達不到理想效果,這可能是不同框架底層實現(xiàn)有所區(qū)別的原因,Sphereface,、AM-softmax都是基于 Caffe,本文所有實驗全使用 TensorFlow,結論有區(qū)別也算正常。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">另一點,Sandberg FaceNet 中的 resnet-inception-v1 搬過來套用 AM-softmax 在 lfw 上的結果達不到 97%,這是過程中不太理解的點。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">從其他論文里看,如果 loss 選的沒問題,那諸如 resnet-inception,不同深度的 Resnet,甚至 Mobile-net,Squeezenet 等結構的表現(xiàn)也不該有明顯差距(AM-softmax 的情況下至少也該達到99%)。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">此外,直接套用 Arcface 也無法擬合,需要進一步實驗。 </span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">最后,關于 Sandberg 的 code 中一個值得關注的點,他將 train_op 定義在了 facenet.train() 函數(shù)里,仔細閱讀這個函數(shù)會發(fā)現(xiàn),Sandberg 的代碼中所有網絡參數(shù)并不是采用每次更新梯度后的值,而是采用滑動平均值作為網絡實際的參數(shù)值。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">也正是因為這個原因,解釋了 Sandberg 在 batch_norm 的參數(shù) configuration中,甚至沒把”is_training”的值交給 placeholder,而是默認 train 和 test 時都采用 local statistics 的模式。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">如果不是因為所有參數(shù)都用了滑動平均,那么這種使用 batch_norm 的做法其實是錯誤的。Sandberg 這樣實現(xiàn)的好壞只能交給實驗結果來評判了。</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="font-size:15px;color:rgb(63,63,63);">如果想正常使用網絡參數(shù)和 batch norm,而不是用滑動平均參數(shù)和全程開著“is_training”,只需要將 facenet.train() 函數(shù)替換成普通的 Optimizer,然后將 batch_norm的“is_training”交給 placeholder 處理,詳細可以參考我的 AM-softmax 實現(xiàn)。</span></p><p style="text-align:justify;margin-left:0em;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/d190e1a6af76674a09532bf4e8600782.png" alt="640"></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;">感謝大家堅持閱讀到最后,以 TensorBoard 的 plot 作為結尾吧!</span></p><p style="text-align:justify;line-height:1.75em;margin-left:0em;"><span style="text-align:justify;font-size:15px;color:rgb(63,63,63);letter-spacing:.5px;"><br></span></p><p style="text-align:center;"><img class="img_loading" src="https://img-blog.csdnimg.cn/img_convert/4501cee825a4ed007756dd4f441491e1.png" alt="640"></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><br></p><h1 style="font-weight:bold;color:rgb(62,62,62);line-height:1.2;border-left-color:rgb(16,142,233);font-size:20px !important;border-left-width:6px !important;border-left-style:solid !important;letter-spacing:1px !important;word-spacing:1px !important;"><a name="t3"></a><span style="letter-spacing:.5px;">參考文獻</span></h1><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="color:rgb(63,63,63);font-size:15px;"><br></span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[1] F. Schroff, D. Kalenichenko, and J. Philbin. Facenet: A unified embedding for face recognition and clustering. In Proc. CVPR, 2015. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[2] Y. Sun, X. Wang, and X. Tang. Deep learning face representation by joint identification-verification. CoRR, abs/1406.4773, 2014. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[3] O. M. Parkhi, A. Vedaldi, and A. Zisserman. Deep face recognition. In BMVC, 2015 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[4] A. Hermans, L. Beyer, and B. Leibe. In defense of the triplet loss for person re-identification. arXiv preprint arXiv:1703.07737, 2017 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[5] Wu, C. Manmatha, R. Smola, A. J. and Krahenb uhl, P. 2017. Sampling matters in deep embedding learning. arXiv preprint arXiv:1706.07567 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[6] W. Liu, Y. Wen, Z. Yu, M. Li, B. Raj, and L. Song. Sphereface: Deep hypersphere embedding for face recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, 2017 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[7] Zhang, K., Zhang, Z., Li, Z., Qiao, Y.: Joint face detection and alignment using multi-task cascaded convolutional networks. arXiv preprint, 2016 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[8] Yu Liu, Hongyang Li, and Xiaogang Wang. 2017. Learning Deep Features via Congenerous Cosine Loss for Person Recognition. arXiv preprint arXiv:1702.06890, 2017 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[9] M. Jaderberg, K. Simonyan, A. Zisserman, and K. Kavukcuoglu. Spatial transformer networks. In NIPS, 2015. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[10] W. Liu, Y. Wen, Z. Yu, and M. Yang. Large-margin softmax loss for convolutional neural networks. In ICML, 2016. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[11] F. Wang, W. Liu, H. Liu, and J. Cheng. Additive margin softmax for face verification. In arXiv:1801.05599, 2018. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[12] CosFace: Large Margin Cosine Loss for Deep Face Recognition </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[13] Deng, J., Guo, J., Zafeiriou, S.: Arcface: Additive angular margin loss for deep face recognition. In: Arxiv preprint. 2018 </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[14] Y. Wen, K. Zhang, Z. Li, and Y. Qiao. A discriminative feature learning approach for deep face recognition. In ECCV, 2016. </span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[15] Y. Liu, H. Li, and X. Wang. Rethinking feature discrimination and polymerization for large-scale recognition. arXiv:1710.00870, 2017.</span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[16] https://github.com/sciencefans/coco_loss/issues/9</span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><span style="font-size:12px;color:rgb(136,136,136);">[17] https://zhuanlan.zhihu.com/p/29515986</span></p><p style="margin-left:0em;font-size:16px;letter-spacing:.5px;color:rgb(62,62,62);text-align:justify;line-height:normal;"><br></p><p style="margin-left:0em;font-size:16px;color:rgb(51,51,51);text-align:center;line-height:normal;"><br></p><p style="margin-left:0em;font-size:16px;color:rgb(51,51,51);text-align:center;line-height:normal;"><span style="font-size:18px;letter-spacing:.5px;"></span></p><p style="color:rgb(62,62,62);font-size:16px;letter-spacing:.5px;"><img class="img_loading" style="visibility:visible !important;" src="https://img-blog.csdnimg.cn/img_convert/fc634de9b35b6643faf20a094ea48c1f.png" alt="640?"></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;letter-spacing:.5px;text-align:center;line-height:2em;"><br></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;letter-spacing:.5px;text-align:center;"><strong style="font-family:'Optima-Regular', 'PingFangTC-light';font-size:14px;"><img class="__bg_gif img_loading" style="visibility:visible !important;" src="https://img-blog.csdnimg.cn/img_convert/c5d7acc30176dd2e68007cbc7ac14e00.gif" alt="640?"></strong><span style="font-family:'Optima-Regular', 'PingFangTC-light';font-size:14px;"><strong>#</strong></span><span style="font-family:'Optima-Regular', 'PingFangTC-light';font-size:14px;color:rgb(214,168,65);"><strong>作 者 招 募<span style="color:rgb(0,0,0);">#</span></strong></span></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;letter-spacing:.5px;text-align:center;line-height:normal;"><span style="font-family:'Optima-Regular', 'PingFangTC-light';font-size:14px;color:rgb(214,168,65);"><strong><span style="color:rgb(0,0,0);"><br></span></strong></span></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;letter-spacing:.5px;text-align:center;line-height:1.75em;"><span style="text-decoration:underline;"><strong><span style="font-family:'Optima-Regular', 'PingFangTC-light';"><strong><span style="font-size:12px;"><a href="http://mp.weixin.qq.com/s?__biz=MzIwMTc4ODE0Mw==&mid=2247487954&idx=1&sn=d247e5b99ecb2c37e85d962d7f93d7d7&chksm=96e9ce52a19e474457e04affae41dc6b6fe521154f95ae7122260b46ec91f55ae7c8fb472c3c&scene=21#wechat_redirect" rel="nofollow" target="_blank">讓你的文字被很多很多人看到,喜歡我們不如加入我們</a></span></strong></span></strong></span></p><p style="margin-left:0em;font-size:16px;color:rgb(51,51,51);text-align:center;line-height:1.75em;"><span style="font-size:18px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;font-size:16px;color:rgb(51,51,51);text-align:center;line-height:1.75em;"><span style="font-size:18px;letter-spacing:.5px;"> </span></p><p style="margin-left:0em;font-size:16px;color:rgb(51,51,51);text-align:center;line-height:1.75em;"><span style="letter-spacing:.5px;"><span style="letter-spacing:.5px;font-size:18px;"> </span><span style="color:rgb(51,51,51);font-size:18px;letter-spacing:.5px;">我是彩蛋</span></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);letter-spacing:.5px;"><strong> 解鎖新功能:熱門職位推薦!</strong></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:normal;"><br></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="font-size:12px;color:rgb(63,63,63);letter-spacing:.5px;">PaperWeekly小程序升級啦</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:normal;"><br></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);letter-spacing:.5px;"><strong><span style="letter-spacing:.5px;color:rgb(51,51,51);">今日arXiv√猜你喜歡√<strong style="color:rgb(71,168,218);font-size:16px;text-align:justify;"><span style="color:rgb(63,63,63);letter-spacing:.5px;font-size:14px;">熱門職位</span></strong><strong style="color:rgb(63,63,63);"><span style="letter-spacing:.5px;color:rgb(51,51,51);">√</span></strong></span></strong></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:normal;"><br></p><p style="margin-left:0em;letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);letter-spacing:.5px;">找全職找實習都不是問題</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="letter-spacing:.5px;"> </span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="letter-spacing:.5px;"><strong><span style="letter-spacing:.5px;color:rgb(255,255,255);"> 解鎖方式 </span></strong></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:12px;letter-spacing:.5px;">1. 識別下方二維碼打開小程序</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:12px;letter-spacing:.5px;">2. 用PaperWeekly社區(qū)賬號進行登陸</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:12px;letter-spacing:.5px;">3. 登陸后即可解鎖所有功能</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><br></p><p style="margin-left:0em;letter-spacing:0px;color:rgb(51,51,51);line-height:1.75em;"><span style="letter-spacing:.5px;"><strong><span style="letter-spacing:.5px;color:rgb(255,255,255);"> 職位發(fā)布 </span></strong></span></p><p style="margin-left:0em;letter-spacing:0px;color:rgb(51,51,51);line-height:1.75em;"><span style="color:rgb(63,63,63);font-size:12px;letter-spacing:.5px;">請?zhí)砑有≈治⑿?#xff08;<strong><span style="font-size:12px;letter-spacing:.5px;color:rgb(136,136,136);">pwbot02</span></strong>)進行咨詢</span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="letter-spacing:.5px;"> <br></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="color:rgb(63,63,63);letter-spacing:.5px;"><strong>長按識別二維碼,使用小程序</strong></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:1.75em;"><span style="letter-spacing:.5px;"><span style="letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);"></span><span style="letter-spacing:.5px;color:rgb(136,136,136);font-size:12px;text-align:center;">*點擊閱讀原文即可注冊</span><span style="letter-spacing:.5px;font-size:12px;color:rgb(136,136,136);text-decoration:underline;"></span></span></p><p style="margin-left:0em;color:rgb(51,51,51);letter-spacing:0px;line-height:normal;"><br></p><p style="margin-left:0em;display:inline-block;width:180px;"><img border="0" class="img_loading" style="visibility:visible !important;" title="" width="180" src="https://img-blog.csdnimg.cn/img_convert/c9c5398fdbd47c722d4b63b3fbcc5066.png" alt="640?"></p><p style="margin-left:0em;display:inline-block;width:180px;line-height:normal;"><br></p><p><br></p><p style="margin-left:0em;letter-spacing:.5px;line-height:1.75em;"><br></p><p><span style="color:rgb(71,168,218);letter-spacing:.5px;"><strong><span style="color:rgb(71,168,218);letter-spacing:.5px;font-size:14px;">關于PaperWeekly</span></strong><br></span></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;text-align:justify;letter-spacing:.5px;line-height:normal;"><span style="color:rgb(63,63,63);font-size:14px;letter-spacing:.5px;"><br></span></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;text-align:justify;line-height:1.5em;letter-spacing:.5px;"><span style="color:rgb(136,136,136);font-size:14px;letter-spacing:.5px;">PaperWeekly 是一個推薦、解讀、討論、報道人工智能前沿論文成果的學術平臺。如果你研究或從事 AI 領域,歡迎在公眾號后臺點擊<strong>「交流群」</strong>,小助手將把你帶入 PaperWeekly 的交流群里。</span></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;text-align:justify;letter-spacing:.5px;line-height:1.75em;"><br></p><p style="text-align:center;"><img class="img_loading __bg_gif" src="https://img-blog.csdnimg.cn/img_convert/6d4111a55af741ef1c54858739e14e7b.gif" alt="640?"></p><p style="margin-left:0em;color:rgb(62,62,62);font-size:16px;text-align:justify;letter-spacing:.5px;"><span style="letter-spacing:.5px;"><span style="letter-spacing:1px;text-align:justify;font-size:13px;color:rgb(63,63,63);">▽ 點擊 | </span><span style="color:rgb(62,62,62);letter-spacing:1px;text-align:justify;font-size:13px;"><span style="letter-spacing:.5px;color:rgb(171,25,66);">閱讀原文</span> <span style="letter-spacing:.5px;color:rgb(63,63,63);">| 進入作者博客</span></span></span></p></div></div></div>總結
以上是生活随笔為你收集整理的人脸检测:Viola-Jones的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 经典残局html,微信欢乐斗地主3月残局
- 下一篇: CentOS7 中没有显示 ip 地址