LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

深層学習で顔の感情分析について

Last updated at Posted at 2017-05-18

Emotion Recognition in the Wild via Convolutional Neural Networks and Mapped Binary Patterns
論文:2015年11月
http://www.openu.ac.il/home/hassner/projects/cnn_emotions/LeviHassnerICMI15.pdf
https://gilscvblog.com/2017/01/31/emotion-recognition-in-the-wild-via-convolutional-neural-networks-and-mapped-binary-patterns/
プロジェクト
http://www.openu.ac.il/home/hassner/projects/cnn_emotions/

局所バイナリパターン(Local Binary Patterns)を深い畳み込みニューラルネットワークの微調整に適した3D空間にマッピングすることに基づく新しい画像表現をも使用しています。
局所2値パターン[11,12,13]の概念に基づいて、画像強度から照明不変の3次元空間への新規なマッピングを提示する。
通常のLBPコードとは異なり、私たちのマッピングは、既存のRGB畳み込みニューラルネットワークを精緻化するために使用できるメトリック空間で値を生成します(下の図を参照)。

スクリーンショット 2017-05-27 10.46.14.png

We apply our LBP mapping with various LBP parameters to the CASIA WebFace collection [14] and use the mapped images (along with the original RGB images) to train an ensemble of CNN models with different architecture.This allows our models to learn general face representations. We then use the pretrained models to finetune on a much smaller set of emotion labels face images. We demonstrate our method on the Emotion Recognition in the Wild Challenge (EmotiW 15), Static Facial Expression Recognition sub-challenge (SFEW) [15]. Our method achieves an accuracy of 54.5%, which is a 15.3% improvement over the baseline provided by the challenge authors (40% gain in performance).

さまざまなLBPパラメータを用いたLBPマッピングをCASIA WebFaceコレクション[14]に適用し、マッピングされたイメージ(元のRGBイメージとともに)を使用して、異なるアーキテクチャのCNNモデルのアンサンブルを訓練する。これにより、私たちのモデルは一般的な顔表現を学ぶことができます。次に、あらかじめ訓練されたモデルを使用して、はるかに小さい感情ラベルの顔画像セットを微調整します。我々は、野生の挑戦(EmotiW 15)、静的な表情認識サブチャレンジ(SFEW)[15] における感情認識について我々の方法を示す 。私たちの方法は54.5%の精度を達成しています。これは、チャレンジ筆者が提供したベースライン(パフォーマンスで40%の向上)よりも15.3%改善されています。

1.まず、各ピクセルから8ビットバイナリベクトルとしてLBP [11,12,13]コードを抽出する。
2.次に、Earth Mover's Distanceを距離メトリックとして使用してMulti-Dimensional Scaling(MDS)を適用することにより、LBPコードを3D空間に変換します。
3.マッピングされた画像は、元のRGB画像と共に、深畳み込みニューラルネットワークのアンサンブルを訓練するために使用される。最後の予測は、別々のネットワークのそれぞれの予測の加重和です。

ローカルバイナリパターン

ローカルバイナリパターン[11,12,13]は、ローカル画像の類似性を考慮してローカルテクスチャをキャプチャします。特定のピクセル位置にLBPコードを生成するために、8個の隣接するピクセルの強度値は、中心ピクセル強度によって閾値処理される。これは、対応する隣接画素の強度が中心画素の強度よりも大きい場合は各ビットが1であり、そうでない場合は0である8ビットのバイナリベクトルを生成する。このプロセスを次の図に示します。
スクリーンショット 2017-05-27 11.01.31.png

共通のLBPパイプラインでは、LBPコードが各ピクセル位置で抽出され、10進値に変換されます。画像は次に領域に分割され、各領域について、LBPコードのヒストグラムが作成される。最後に、異なるヒストグラムを連結して、画像の単一のグローバル記述子を生成する。ここでは代わりに、各画像の8ビットバイナリベクトルを計算し、後で3次元空間にマップします。

多次元尺度とEMD(Multidimensional Scaling and the Earth Mover’s Distance)

結果

スクリーンショット 2017-05-27 12.15.52.png

元のRGB画像でトレーニングされたネットワークが最良の結果をもたらさなかったことです。マップされたLBP画像で訓練されたネットワークによって最高の精度が得られました。スクリーンショット 2017-05-27 12.17.18.png


LBPとは

論文でのLBPと一般的な意味とで差がないかを調べる。
http://compsci.world.coocan.jp/OUJ/2012PR/pr_15_a.pdf
中心画素と周辺画素を比べて0,1に変換するみたいだ。多分論文も同じ説明をしてる部分がある。

スクリーンショット 2017-05-27 11.04.39.png
スクリーンショット 2017-05-27 11.06.28.png
スクリーンショット 2017-05-27 11.07.17.png
スクリーンショット 2017-05-27 11.07.45.png

ヒストグラム比較すると画像分類もできる
スクリーンショット 2017-05-27 11.09.05.png

スクリーンショット 2017-05-27 11.09.10.png

スクリーンショット 2017-05-27 11.09.17.png

ハミング距離

ハミング距離は、ある文字列を別の文字列に変形する際に必要な置換回数を計測。
スクリーンショット 2017-05-27 11.24.18.png

caffeで動かす

環境設定は下記参照
http://qiita.com/miyamotok0105/items/61efc0f5d7fc6656ad98

学習済みモデルやパラメータ(deploy.txt)は下記
https://gist.github.com/GilLevi/54aee1b8b0397721aa4b#file-deploy-txt

# -*- coding: utf-8 -*-
import os
import time
import fnmatch
import numpy as np
import matplotlib.pyplot as plt
import shutil
import logging
import glob
import sys
import caffe

plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

cur_net_dir = './'
output_emotion_folder=""
categories = [ 'Angry' , 'Disgust' , 'Fear' , 'Happy'  , 'Neutral' ,  'Sad' , 'Surprise']

mean_filename=os.path.join(cur_net_dir,'mean.binaryproto')
proto_data = open(mean_filename, "rb").read()
a = caffe.io.caffe_pb2.BlobProto.FromString(proto_data)
mean  = caffe.io.blobproto_to_array(a)[0]
net_pretrained = os.path.join(cur_net_dir,'EmotiW_VGG_S.caffemodel')
net_model_file = os.path.join(cur_net_dir,'deploy.prototxt')
VGG_S_Net = caffe.Classifier(net_model_file, net_pretrained,
                             mean=mean,
                             channel_swap=(2,1,0),
                             raw_scale=255,
                             image_dims=(256, 256))

file_list = glob.glob(os.path.join(os.path.dirname(os.path.abspath(__file__)), "emotion", "*.png"))
for file_ in file_list:
    print(file_)    
    input_image = caffe.io.load_image(file_)
    prediction = VGG_S_Net.predict([input_image],oversample=False)
    print(prediction[0][prediction.argmax()])
    print 'predicted category is {0}'.format(categories[prediction.argmax()])

Earth Mover's Distance (EMD)

http://aidiary.hatenablog.com/entry/20120804/1344058475
特徴量がベクトルのときはユークリッド距離、特徴量が確率分布のときはカルバック・ライブラー距離(情報量)など。EMDは、特徴量の集合が2つ与えられたときに、1個1個の特徴量間の距離をもとに、特徴量集合間の距離を求められる。

スクリーンショット 2017-05-27 11.33.20.png

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up