1. 程式人生 > >Fisher Vector Encoding and Gaussian Mixture Model

Fisher Vector Encoding and Gaussian Mixture Model

ica 數據 最重要的 似然函數 可能 ons ssi 語言學 生成

一、背景知識

1. Discriminant Learning Algorithms(判別式方法) and Generative Learning Algorithms(生成式方法)

現在常見的模式識別方法有兩種,一種是判別式方法;一種是生成式方法。可以這樣理解生成式方法主要是數據是如何生成的,從統計學的角度而言就是模擬數據的分布distribution;而判別式方法,不管數據是如何生成而是通過數據內在的差異直接進行分類或者回歸。舉個例子你現有的task是去識別一段語音屬於哪一種語言。那麽生成式模型就是你先讓你的model先去學習各種可能性的語言,然後使用你學到的知識來對你要識別的語音做分類;而判別式模型是根據語音中的lingustic characteristic語言學特點來識別這段語音。July_Zh1博文認為生成式方法主要反映同類數據之間的相似度,判別式方法反映數據之間的的差異度。Fihser Kernel結合了二者的差異。PRML中有更加理論的闡述,有興趣可以參考。

2. Fisher Information matrix

設一隨機變量$x$

如果$x$ 為連續型隨機變量,那麽$x$的分布$p(x|\theta)$可以用正態分布模擬: $p(x|\theta) = \frac{1}{\sqrt{2\pi\sigma^2}}exp\left\{-\frac{(x-u)^2}{2\sigma^2}\right\}$

如果$x$是離散型隨機變量,那麽$x$的分布可以可以用類別分布categorical distribution模擬: $p(x|\theta) = \prod_{k=1}^{K}\theta_k^{x_k}$

式中: $0 \leq \theta_k \geq 1, \sum_k \theta_k = 1$

定義Fisher Score 為: $g(\theta,x) = \triangledown_\theta ln(p|\mathbf{\theta}) $

定義Fisher Information Matrirx 為: $ F = E_x\left[g(\theta,x),g(\theta,x)^T\right] $

二、 Fisher Kernel Methods

假設我們訓練數據集為 $ X_t$,對應的Label 為 $S_t $(±1)(先考慮只有兩類樣本的情況) 。設 $X$ 為測試樣本,$\hat{S} $為對測試樣本預測值。

我們有:$\hat{S}$ = $sign\left (\sum_t S_t\lambda_t K(X_t,X)\right )$;

而對核函數有以下形式: $ K(X_i,X_i) = \phi_{X_i}^T \phi_{X_j} $.

對於每一個新樣本的預測值$\hat{S}$是由原來樣本的Label $S_t$ ”加權”得到。而“加權”由兩部分組成:1)$\lambda_t$ 2) $K(X_t,X) $

這個Kernel描述的是訓練樣本$X_t$ 和測試樣本$X$之間的相似度,Kernel有很多種,這裏選擇的是Fisher Kernel. 使用$U_x$代表Fisher Score, $F_\lambda$ 代表 Fisher Information Matrix。

如果將函數數看作一種映射方式,那麽這個等式代表著我們不需要將每個樣本真的映射到核空間進行計算,而只要確定核函數對應的$\phi_x$直接對函數進行計算就可以得到將樣本映射到核空間的效果。(這也是支持向量機最重要的trick之一)

$\phi_x$ 就是我們定義的Fisher Vector

對於Fisher Kernel我們有: $\phi_x = F_\lambda^{-\frac{1}{2}}U_x$

對應的樣本生成模型為:GMM(Gaussian Mixture Model) 即$X$服從的分布為GMM模型。此時$X = x_1,...,x_N$ 代表GMM中一系列變量。

二、對圖像使用Fisher Encoding

Fisher encoding 的基本思想就是用GMM去構建一個視覺字典,本質上是用似然函數的梯度來表達一幅圖像。

1. GMM構建視覺詞典

對於圖像而言$x$可以代表圖像的特征(比如SIFT特征),一幅圖像有很多特征$X = x_1,...x_T$

對於GMM model $X$的分布為:

$$p(X|\omega,\mu,\sum)$$

$\omega,\mu,\sum$分別為GMM中每個特征的權重,均值,協方差。

2. 計算Fisher Vector

首先定義:

$$L(X|\lambda) = logp(X|\lambda) = \sum_{t=1}^{T} logp(x_t|\lambda)$$.

圖像中每個特征都是相互獨立的:

$$p(x_t|\lambda) = \sum_{i=1}^{N}w_ip_i(x_t|\lambda)$$.

$p_i$位GMM中第i個component的pdf,$w_i$為其權值, $\sum_{i=1}^Nw_i=1$.

每個component $p_i$是多元高斯函數,期pdf如下:

技術分享

D是特征向量的維數,$\sum_i^-1位協方差矩陣

再定義特征$x_t$由第i個Gaussian component生成概率,這裏使用了貝葉斯公式:

$$\gamma_t(i) = p(i|x_t,\lambda) = \frac{w_ip_i(x_t|\lambda)}{\sum_{j=1}^Nw_jp_j(x_t|\lambda)}$$

然後對各個參數求偏導:

$$U_x = \left[ \frac{\partial L(X|\lambda)}{\partial{\omega_i}}, \frac{\partial{L(X|\lambda)}}{\partial{\mu_i^d}}, \frac{\partial{L(X|\lambda)}}{\partial{\sigma_i^d}} \right]$$

技術分享

這裏i是指第i個component,d是指特征$x_t$的維度,偏導是對每個componnet求,每個特征的維度都要計算,$U_X$維度是(2*D+1)*N,又由於$\omega_i$有約束$\sum_i \omega_i=1$,所以會少一個自由變量,所以$U_x$ 最終的維度是(2D+1)*N-1.

對上面的三個公式分別引入三個對應的fisher matrix:

$$ f_{w_i} = T\left(\frac{1}{w_i} + \frac{1}{w_1} \right) $$

$$ f_{u_i^d} = \frac{Tw_i}{\sigma_i^d)^2} $$

$$ f_{\sigma_i^d} = \frac{2T\omega_i}{(\sigma_i^d)^2}$$

之後便可求得歸一化的fisher vector.

三、如何使用vl_feat進行fisher kernel encoding

參考資料:

1. 【Paper】: The Devil is in the details: an evaluation of recent feature encoding methods

比較了在目標識別領域不同encoding feature 的效果

2. 如何使用vl_feat計算Fisher Vectors:

http://www.vlfeat.org/overview/encodings.html

3. 如何使用vl_feat實現GMM

http://www.vlfeat.org/overview/gmm.html

4. Fisher information matrix for Gaussian and categorical distributions

https://www.ii.pwr.edu.pl/~tomczak/PDF/%5bJMT%5dFisher_inf.pdf

5. Fisher Vector Encoding

http://www.cs.ucf.edu/courses/cap6412/spr2014/papers/Fisher-Vector-Encoding.pdf

6. 【Paper】: Exploiting generative models in discriminative classifiers

Fisher Kerner 的推導和闡述

7【Paper】: Fisher Kernels on Visual Vocabularies for Image Categorization

http://www.cs.ucf.edu/courses/cap6412/spr2014/papers/2006-034.pdf

8. 【Paper】: Improving the Fisher Kernel for Large-Scale Image Classification

Fisher Kernel的優化

7. Fisher Vector and Fisher Score

http://blog.csdn.net/happyer88/article/details/46576379

Fisher Vector Encoding and Gaussian Mixture Model