天天看點

人臉識别之表情識别(二)--基于CNN分類

說白了,就是個分類任務,但是純粹的CNN分類,隻是對傳統方式的提升,本質思路沒有改變,效果也不是很明顯。

轉自:https://blog.csdn.net/walilk/article/details/58709611

前言

  [機器學習] 實驗筆記系列是以我在算法研究中的實驗筆記資料為基礎加以整理推出的。該系列内容涉及常見的機器學習算法理論以及常見的算法應用,每篇部落格都會介紹實驗相關的資料庫,實驗方法,實驗結果,評價名額和相關技術目前的應用情況。 

  本文主要整理自筆者在表情識别(emotion recognition)研究上的實驗筆記資料,給出了表情識别常用的資料庫,論文資料,識别方法,評價名額,以及筆者的實驗筆記和實驗結果。 

  文章小節安排如下:

  1)表情識别的意義

  2)表情識别的應用

  3)常用的資料庫及比賽

  4)實驗-算法說明

  5)實驗-效果展示

  6)結語 

一、表情識别的意義

1.1 什麼是表情?

  我們天天都在展示自己的表情并且看到其他人的表情,那麼表情到底是什麼?

  看看維基百科的定義: 

  面部表情是面部肌肉的一個或多個動作或狀态的結果。這些運動表達了個體對觀察者的情緒狀态。面部表情是非語言交際的一種形式。它是表達人類之間的社會資訊的主要手段,不過也發生在大多數其他哺乳動物和其他一些動物物種中。

  人類的面部表情至少有21種,除了常見的高興、吃驚、悲傷、憤怒、厭惡和恐懼6種,還有驚喜(高興+吃驚)、悲憤(悲傷+憤怒)等15種可被區分的複合表情。 

1.2 表情的意義?

  表情是人類及其他動物從身體外觀投射出的情緒名額,多數指面部肌肉及五官形成的狀态,如笑容、怒目等。也包括身體整體表達出的身體語言。

  

  參考:

  https://zh.wikipedia.org/wiki/%E9%9D%A2%E9%83%A8%E8%A1%A8%E6%83%85

  

  簡單來說,

  面部表情是人體(形體)語言的一部分,是一種生理及心理的反應,通常用于傳遞情感。 

1.3 表情的研究

  面部表情的研究始于 19 世紀,

  1872年,達爾文在他著名的論著《人類和動物的表情(The Expression of the Emotions in Animals and Man,1872)》中就闡述了人的面部表情和動物的面部表情之間的聯系和差別。 

  1971年,Ekman 和 Friesen 研究了人類的 6 種基本表情 (即高興、悲傷、驚訝、恐懼、憤怒、厭惡 ) ,并系統地建立了人臉表情圖象庫,細緻的描述了每一種表情所對應的面部變化,包括眉毛、眼睛、眼睑、嘴唇等等是如何變化的。 

人臉識别之表情識别(二)--基于CNN分類

  1978年,Suwa等人提出了在圖像序列中進行面部表情自動分析。

  從20世紀90年代開始,由Mase和Pentland提出的光流法進行面部表情識别之後,自動面部表情識别進入了新的時期。 

1.4 微表情

  随着研究的深入和應用的廣泛,人們逐漸開始研究一種更細微的表情:微表情。

  看維基百科的定義:

  微表情是一種人類在試圖隐藏某種情感時無意識做出的、短暫的面部表情。

  微表情的持續時間僅為 1/25 秒至 1/5 秒,表達的是一個人試圖壓抑與隐藏的真正情感。

  微表情的在自動謊言識别等衆多領域有巨大的潛在應用價值,比如那部著名的電視劇《Lie to Me》,卡爾·萊特曼博士就是利用“臉部動作編碼系統”(Facial Action Coding System)分析被觀察者的肢體語言和微表情,進而向他們的客戶(包括FBI等美國執法機構或聯邦機構)提供被觀測者是否撒謊等分析報告。 

  随着科技進步和心理學的不斷發展,對表情的研究越來越豐富,應用也越來越廣泛。有興趣的讀者可以Google一下人類表情的研究曆史,以及在心理學用的應用。 

二、表情識别的應用

2.1 表情識别的應用場景

  面部表情識别技術主要的應用領域包括人機互動、智能控制、安全、醫療、通信等領域。筆者目前接觸過的兩個領域, 

  第一個是商場門店的顧客情緒分析。即通過攝像頭捕獲商場或門店的顧客畫面,分析其面部表情,再進一步解讀出客人的情緒資訊,進而分析顧客在商場的體驗滿意度。 

  第二個是人機互動。在筆者參與的一個教育輔助機器人項目中,負責視覺部分的研發工作,其中一項功能就是通過面部表情分析來判斷機器人眼前的使用者的情緒和心理。 

2.2 線上應用接口

  微軟提供了表情識别的API接口,并通過JSON傳回識别結果,如下:

  Cognitive Services APIs - Emotion Recognization 

人臉識别之表情識别(二)--基于CNN分類

  Face++也提供了接口,并通過JSON傳回識别結果,如下:

  人臉檢測 

人臉識别之表情識别(二)--基于CNN分類

三、常用的資料庫及比賽

3.1 表情識别常用資料庫

  1)The Japanese Female FacialExpression (JAFFE) Database

  釋出時間:1998

  詳細說明:

  The database contains 213 images of 7 facial expressions (6 basic facial expressions + 1 neutral) posed by 10 Japanese female models. Each image has been rated on 6 emotion adjectives by 60 Japanese subjects. The database was planned and assembled by Michael Lyons, Miyuki Kamachi, and Jiro Gyoba. We thank Reiko Kubota for her help as a research assistant. The photos were taken at the Psychology Department in Kyushu University.

  表情:sad, happy, angry, disgust,surprise, fear, neutral.

  位址:http://www.kasrl.org/jaffe.html 

  2)The Extended Cohn-Kanade Dataset(CK+) (這個資料庫有人有嗎?能共享下嗎?)

  釋出時間:2010

  詳細說明:

  The Cohn-Kanade AU-Coded Facial Expression Database is for research in automatic facial image analysis and synthesis and for perceptual studies. Cohn-Kanade is available in two versions and a third is in preparation.

  Version 1, the initial release, includes 486 sequences from 97 posers. Each sequence begins with a neutral expression and proceeds to a peak expression. The peak expression for each sequence in fully FACS (Ekman, Friesen, & Hager, 2002; Ekman & Friesen, 1979) coded and given an emotion label. The emotion label refers to what expression was requested rather than what may actually have been performed. For a full description of CK, see (Kanade, Cohn, & Tian, 2000).For validated emotion labels, please use version 2, CK+, as described below. 

  論文:P.Lucey, J. F. Cohn, T.Kanade, J. Saragih, Z. Ambadar, and I. Matthews, “TheExtended Cohn-KanadeDataset (CK+)_ A complete dataset for action unit andemotion-specifiedexpression,” inComputer Vision andPattern RecognitionWorkshops (CVPRW), 2010 IEEE Computer Society Conference on,2010, pp. 94-101.

  位址:http://www.pitt.edu/~emotion/ck-spread.htm 

  3)GEMEP-FERA 2011

  釋出時間:2011

  詳細說明:

  該庫是在 IEEE 的 Automatic Face & GestureRecognition and Workshops (FG 2011), 2011 IEEE International Conference on 上提供的一個資料庫,如果要擷取這個資料庫,需要簽署一個assignment,而且隻有學術界可以免費使用。

  論文:M.F. Valstar, M. Mehu, B.Jiang, M. Pantic, and K. Scherer, “Meta-Analysis ofthe First FacialExpression Recognition Challenge,”Systems,Man, andCybernetics, Part B: Cybernetics, IEEE Transactions on, vol. 42,pp. 966-979,2012.

  位址:https://gemep-db.sspnet.eu/ 

  4)AFEW_4_0_EmotiW_2014

  詳細說明:

  該資料庫用作 ACM 2014 ICMI TheSecond Emotion Recognition In The Wild Challenge and Workshop。資料庫中提供原始的video clips,都截取自一些電影,這些clips 都有明顯的表情,這個資料庫與前面的資料庫的不同之處在于,這些表情圖像是 in the wild, not inthe lab。是以一個比較困難的地方在于人臉的檢測與提取。

  論文:A.Dhall, R. Goecke, J. Joshi,M. Wagner, and T. Gedeon, “Emotion RecognitionIn The Wild Challenge2013,” inProceedings of the 15thACM on Internationalconference on multimodal interaction, 2013, pp.509-516.

  位址:https://cs.anu.edu.au/few/emotiw2014.html  

  5)GENKI-4K

  詳細說明:

  The MPLab GENKI Database is an expanding database of images containing faces spanning a wide range of illumination conditions, geographical locations, personal identity, and ethnicity. Each subsequent release contains all images from the previous release, and so is guaranteed to be backward compatible. The database of images is divided into overlapping subsets, each with its own labels and descriptions. For example, the GENKI-4K subset contains 4000 face images labeled as either “smiling” or “non-smiling” by human coders. The pose of the faces is approximately frontal as determined by our automatic face detector. The GENKI-SZSL subset contains 3500 images containing faces. They are labeled for the face location and size. The images are available for public use.

  The current release of the GENKI database is GENKI-R2009a. It contains 7172 unique image files, which combine to form these subsets:

  GENKI-4K: 4000 images, containing expression and head-pose labels.

  GENKI-SZSL: 3500 images, containing face position and size labels.

  論文:WhitehillJ, Littlewort G, Fasel I, et al. Toward practical smile detection[J]. PatternAnalysis and Machine Intelligence, IEEE Transactions on, 2009, 31(11):2106-2111.

  位址:http://mplab.ucsd.edu/wordpress/?page_id=398   

  6)The UNBC-McMaster shoulder painexpression archive database

  論文:Lucy,P., Cohn, J. F., Prkachin, K. M., Solomon, P., & Matthrews, I. (2011).Painful data: The UNBC-McMaster Shoulder Pain Expression Archive Database. IEEEInternational Conference on Automatic Face and Gesture Recognition (FG2011).

  位址:http://www.pitt.edu/~emotion/um-spread.htm 

3.2 表情識别比賽

  1)The Third Emotion Recognition in the Wild Challenge

  這是ACM International Conference on Multimodal Interaction (ICMI 2015)舉辦的一個表情識别的競賽,每年都舉辦,感興趣的可以參加一下。

       https://cs.anu.edu.au/few/emotiw2014.html  

  https://cs.anu.edu.au/few/emotiw2015.html

  https://sites.google.com/site/emotiw2016/ 

    2)Challenges in Representation Learning: Facial Expression Recognition Challenge

    https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge

四、實驗-算法說明

4.1 表情資料庫

  Fer2013:Kaggle facial expression recognition challenge dataset

  詳細說明:

  The training set consists of 28,709 examples. The public test set used for the leaderboard consists of 3,589 examples. The final test set, which was used to determine the winner of the competition, consists of another 3,589 examples.

  表情分類:

  0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral

  資料分布:  

  ~/trainImg.zip     訓練集,28709

  ~/privateTestImg.zip  測試集,3589

  ~/publicTestImg.zip   測試集,3589

  

  資料分布(訓練集):

  Angry:3995

  Disgust:436

  Fear:4097

  Happy:7215

  Sad:4830

  Surprise:3171

  Neutral:4965

  

  資料分布(fer2013_privatetest.csv):

  Angry:3995

  Disgust:436

  Fear:4097

  Happy:7215

  Sad:4830

  Surprise:3171

  Neutral:4965

  

  關于fer2013資料檔案的使用:

  fer2013中的圖檔以“标簽 圖像向量”的形式儲存在.csv檔案中,即每一個列向量是一張圖檔,第一個數字是标簽,剩下的數字是圖檔資料(将圖檔矩陣按列展開存儲的),可以利用matlab的reshape函數将圖檔還原出來,圖像尺寸是48x48大小。 

4.3 參考論文

  論文:

  Jeon, Jinwoo, et al. “A Real-time Facial Expression Recognizer using Deep Neural Network.” International Conference on Ubiquitous Information Management and Communication ACM, 2016:94.

  基本方法:

  采用深度神經網絡算法,其網絡結構是在AlexNet上修改得到,減少了3個卷積層,示意如下: 

人臉識别之表情識别(二)--基于CNN分類

  網絡結構:

  

人臉識别之表情識别(二)--基于CNN分類

  實驗結果:

  The average accuracy for all categories was 70.74%. Accuracy for the happy and surprise category was higherthan the others, but accuracy for the fear category was poor. 

  混淆矩陣:

  

人臉識别之表情識别(二)--基于CNN分類

4.3 實驗環境

  深度學習架構:caffe

  GPU卡:GeForce GTX TITAN Black 

4.4 訓練配置檔案(solver.prototxt)

  net: “./train_val_rferdnn.prototxt”

  test_iter: 1200

  test_interval: 1000

  base_lr: 0.001

  lr_policy: “fixed”

  display: 500

  max_iter: 100000

  momentum: 0.9

  weight_decay: 0.0005

  snapshot: 20000

  snapshot_prefix: “./models/rt_exprec”

  solver_mode: GPU 

4.5 實驗重制

  經過不斷的調整參數和資料處理方法,筆者最後基本複現了論文中的實驗結果,達到 70.2% 的準确率。 

  具體如下:

  average accuracy:

  70.2%

  confusion matrix:

  

人臉識别之表情識别(二)--基于CNN分類

4.6 資料擴充方法 

  論文《A Real-time Facial Expression Recognizer using Deep Neural Network》中采用的是随機crop出5個圖像,說是可以 spatial invariance is induced。但文中的配圖看起來并不像是随機采樣的,如下:

  

人臉識别之表情識别(二)--基于CNN分類

  這裡是直接按照四個角+中間進行采樣的,不過這也可以看做是随機的一種吧。我在實驗中也是這麼采樣的,然後再mirror一下,這樣就将訓練資料量擴大了10倍。 

4.7 預測方法 

  1)規則擴充測試圖像,即crop測試圖像四個corner區域+一個center區域,再做鏡像(mirror),也就是每個原始樣本擴充出10個crop_image;

  2)得分融合:averaging method,即計算原始圖像的10個擴充的預測結果的均值作為最終得分。 

  測試集:fer2013_privatetest.csv(我記得應該是這個,還有一個,還有一個fer2013_publictest.csv我忘記測試了沒有了(⊙﹏⊙)) 

4.8 模型下載下傳 

  http://pan.baidu.com/s/1jI1kwya,這是私有連結,需要下載下傳的朋友請私信我。我希望各位同學能夠自己琢磨算法、訓練模型,這樣才能有進步,而不是直接拿來用。 

4.9 訓練過程 

  為了更好的展示實驗,這裡給出我當時的訓練輸出。不過我的硬碟裡隻找到了一部分輸出和最終訓練結果,非常抱歉!

Iteration 0

I0421 08:09:17.860702 27484 solver.cpp:341] Iteration 0, Testing net (#0)

I0421 08:10:26.924216 27484 solver.cpp:409] Test net output #0: accuracy = 0.142594

I0421 08:10:26.924386 27484 solver.cpp:409] Test net output #1: loss = 1.94273 (* 1 = 1.94273 loss)

I0421 08:10:27.081188 27484 solver.cpp:237] Iteration 0, loss = 1.94555

I0421 08:10:27.081243 27484 solver.cpp:253] Train net output #0: loss = 1.94555 (* 1 = 1.94555 loss)

I0421 08:10:27.081269 27484 sgd_solver.cpp:106] Iteration 0, lr = 0.001

I0421 08:11:52.943675 27484 solver.cpp:237] Iteration 500, loss = 1.81799

I0421 08:11:52.943876 27484 solver.cpp:253] Train net output #0: loss = 1.81799 (* 1 = 1.81799 loss)

I0421 08:11:52.943889 27484 sgd_solver.cpp:106] Iteration 500, lr = 0.001

I0421 08:13:20.381688 27484 solver.cpp:237] Iteration 1000, loss = 1.73778

I0421 08:13:20.381914 27484 solver.cpp:253] Train net output #0: loss = 1.73778 (* 1 = 1.73778 loss)

I0421 08:13:20.381924 27484 sgd_solver.cpp:106] Iteration 1000, lr = 0.001

Iteration 5000

I0421 08:24:59.778053 27484 solver.cpp:341] Iteration 5000, Testing net (#0)

I0421 08:26:16.136390 27484 solver.cpp:409] Test net output #0: accuracy = 0.562633

I0421 08:26:16.136633 27484 solver.cpp:409] Test net output #1: loss = 1.15914 (* 1 = 1.15914 loss)

I0421 08:26:16.282253 27484 solver.cpp:237] Iteration 5000, loss = 1.20592

I0421 08:26:16.282282 27484 solver.cpp:253] Train net output #0: loss = 1.20592 (* 1 = 1.20592 loss)

I0421 08:26:16.282294 27484 sgd_solver.cpp:106] Iteration 5000, lr = 0.001

I0421 08:27:43.646217 27484 solver.cpp:237] Iteration 5500, loss = 1.18084

I0421 08:27:43.646412 27484 solver.cpp:253] Train net output #0: loss = 1.18084 (* 1 = 1.18084 loss)

I0421 08:27:43.646425 27484 sgd_solver.cpp:106] Iteration 5500, lr = 0.001

Iteration 10000

0421 08:40:47.484722 27484 solver.cpp:341] Iteration 10000, Testing net (#0)

I0421 08:42:00.271831 27484 solver.cpp:409] Test net output #0: accuracy = 0.665208

I0421 08:42:00.272018 27484 solver.cpp:409] Test net output #1: loss = 0.891976 (* 1 = 0.891976 loss)

I0421 08:42:00.417796 27484 solver.cpp:237] Iteration 10000, loss = 0.875526

I0421 08:42:00.417830 27484 solver.cpp:253] Train net output #0: loss = 0.875526 (* 1 = 0.875526 loss)

I0421 08:42:00.417840 27484 sgd_solver.cpp:106] Iteration 10000, lr = 0.001

Iteration 15000

I0421 08:56:28.140434 27484 solver.cpp:341] Iteration 15000, Testing net (#0)

I0421 08:57:43.430665 27484 solver.cpp:409] Test net output #0: accuracy = 0.780628

I0421 08:57:43.430855 27484 solver.cpp:409] Test net output #1: loss = 0.612954 (* 1 = 0.612954 loss)

I0421 08:57:43.581197 27484 solver.cpp:237] Iteration 15000, loss = 0.656312

I0421 08:57:43.581219 27484 solver.cpp:253] Train net output #0: loss = 0.656312 (* 1 = 0.656312 loss)

I0421 08:57:43.581230 27484 sgd_solver.cpp:106] Iteration 15000, lr = 0.001

Iteration 20000

I0421 09:12:06.863005 27484 solver.cpp:341] Iteration 20000, Testing net (#0)

I0421 09:13:22.342000 27484 solver.cpp:409] Test net output #0: accuracy = 0.865189

I0421 09:13:22.342190 27484 solver.cpp:409] Test net output #1: loss = 0.389436 (* 1 = 0.389436 loss)

I0421 09:13:22.488214 27484 solver.cpp:237] Iteration 20000, loss = 0.539341

I0421 09:13:22.488237 27484 solver.cpp:253] Train net output #0: loss = 0.539341 (* 1 = 0.539341 loss)

I0421 09:13:22.488248 27484 sgd_solver.cpp:106] Iteration 20000, lr = 0.001

Iteration 25000

I0421 09:27:55.352700 27484 solver.cpp:341] Iteration 25000, Testing net (#0)

I0421 09:29:10.297168 27484 solver.cpp:409] Test net output #0: accuracy = 0.914303

I0421 09:29:10.297345 27484 solver.cpp:409] Test net output #1: loss = 0.256905 (* 1 = 0.256905 loss)

I0421 09:29:10.442956 27484 solver.cpp:237] Iteration 25000, loss = 0.365221

I0421 09:29:10.442978 27484 solver.cpp:253] Train net output #0: loss = 0.365221 (* 1 = 0.365221 loss)

I0421 09:29:10.442988 27484 sgd_solver.cpp:106] Iteration 25000, lr = 0.001

Iteration 100000

accuracy = 0.996794

loss = 0.010607 (* 1 = 0.010607 loss) 

五、實驗-效果展示

  基于訓練好的模型做了一些測試,效果如下:

  

人臉識别之表情識别(二)--基于CNN分類

     

人臉識别之表情識别(二)--基于CNN分類

  

人臉識别之表情識别(二)--基于CNN分類

     

人臉識别之表情識别(二)--基于CNN分類

 

人臉識别之表情識别(二)--基于CNN分類

     

人臉識别之表情識别(二)--基于CNN分類

  

人臉識别之表情識别(二)--基于CNN分類

 

人臉識别之表情識别(二)--基于CNN分類

六、結語

  現在人臉分析技術火遍大江南北,Microsoft,Face++,Linkface等都提供了表情識别技術,但從該技術的難度和現階段的準确度來看,表情識别還隻能用于那些對準确率要求不高的場景下,做一些輔助分析的工作。 

  那麼表情識别技術是否就不那麼重要了呢???不是!如同筆者在文章開頭所說,表情是人内心的直覺反應,是以表情識别技術是人機互動技術的重要元件。未來機器人想要更懂人類更好的跟人類互動,那麼表情識别技術是必不可少的。 

參考

維基百科-表情

人臉表情識别常用的幾個資料庫

Emotient 的表情識别技術的門檻是什麼,有哪些應用場景?

微軟研究院大咖為你科普人臉表情識别技術  

參考論文:

Jeon, Jinwoo, et al. “A Real-time Facial Expression Recognizer using Deep Neural Network.” International Conference on Ubiquitous Information Management and Communication ACM, 2016:94.

其實FER2013測試級有很多标簽錯誤,能做到70%不錯了,看2013比賽的排名:

人臉識别之表情識别(二)--基于CNN分類

之後就沒有更新了。

2013-fer2013第一名71.2%:損失函數為L2-SVM的表情分類《Deep Learning using Linear Support Vector Machines》

  • 将損失函數Softmax改為L2-SVM,相比L1-SVM,它具有可微,并且對誤分類有更大的懲罰。
  • SVM限制函數如右公式4。改寫為無限制優化問題如公式5,即為L1-SVM的最初形式。公式6為L2-SVM的形式。
人臉識别之表情識别(二)--基于CNN分類
人臉識别之表情識别(二)--基于CNN分類
人臉識别之表情識别(二)--基于CNN分類
  • L2-svm通過 argtmax(wTx)t(tn∈{−1,+1})來判斷x的類别。
  • 在反向傳播需要對其求導。如公式10為L1-SVM的,它是不可微。而公式11是L2-SVM的且是可微的。 且L2-SVM比L1-SVM效果好些。
  • Softmax和L2-SVM在FER2013中的效果如圖:
人臉識别之表情識别(二)--基于CNN分類

繼續閱讀