2014-03-19 50 views
2
笑臉檢測神經網絡

讓我解釋一下後臺的問題之前,我解釋這個問題。我的任務是採取一個標有笑容不是的圖像。有微笑的文件被標記,例如100a.jpg和100b.jpg。 'a'用於表示沒有微笑的圖像,'b'用於用微笑表示圖像。因此,我正在尋找一個3層網絡,即層1 =輸入節點,層2 =隱藏層和層3 =輸出節點。實現在圖像

的一般算法是:在圖像中

  1. 取和它重新大小爲x 24x20的大小。
  2. 應用從輸入節點到隱藏層的前向傳播。
  3. 應用從隱藏層到輸出節點的前向傳播。
  4. 然後應用從輸出節點向隱藏層的反向傳播。 (一級方程式)
  5. 然後從隱藏層施加一個向後傳播到輸入節點。 (Formula2)

公式1:

enter image description here

配方2:

enter image description here

現在的問題很簡單,就是...我的代碼永遠不會收斂,因此我沒有可用於測試網絡的權重向量。問題是我不知道爲什麼會這樣...這裏是我顯示,顯然不是收斂的錯誤:

Training done full cycle 
    0.5015 

Training done full cycle 
    0.5015 

Training done full cycle 
    0.5015 

Training done full cycle 
    0.5038 

Training done full cycle 
    0.5038 

Training done full cycle 
    0.5038 

Training done full cycle 
    0.5038 

Training done full cycle 
    0.5038 

這裏是我的MATLAB代碼:

function [thetaLayer12,thetaLayer23]=trainSystem() 

%This is just the directory where I read the images from 
files = dir('train1/*jpg'); 
filelength = length(files); 

%Here I create my weights between input layer and hidden layer and then 
%from the hidden layer to the output node. The reason the value 481 is used 
%is because there will be 480 input nodes + 1 bias node. The reason 200 is 
%used is for the number of hidden layer nodes 
thetaLayer12 = unifrnd (-1, 1 ,[481,200]); 
thetaLayer23 = unifrnd (-1, 1 ,[201,1]); 

%Learning Rate value 
alpha = 0.00125; 

%Initalize Convergence Error 
globalError = 100; 

while(globalError > 0.001) 
    globalError = 0; 

    %Run through all the files in my training set. 400 Files to be exact. 
    for i = 1 : filelength 
     %Here we find out if the image has a smile in it or not. If there 
     %Images are labled 1a.jpg, 1b.jpg where images with an 'a' in them 
     %have no smile and images with a 'b' in them have a smile. 
     y = isempty(strfind(files(i).name,'a')); 

     %We read in the image 
     imageBig = imread(strcat('train1/',files(i).name)); 

     %We resize the image to 24x20 
     image = imresize(imageBig,[24 20]); 

     %I then take the 2D image and map it to a 1D vector 
     inputNodes = reshape(image,480,1); 

     %A bias value of 1 is added to the top of the vector 
     inputNodes = [1;inputNodes]; 

     %Forward Propogation is applied the input layer and the hidden 
     %layer 
     outputLayer2 = logsig(double(inputNodes')* thetaLayer12); 

     %Here we then add a bias value to hidden layer nodes 
     inputNodes2 = [1;outputLayer2']; 

     %Here we then do a forward propagation from the hidden layer to the 
     %output node to obtain a single value. 
     finalResult = logsig(double(inputNodes2')* thetaLayer23); 

     %Backward Propogation is then applied to the weights between the 
     %output node and the hidden layer. 
     thetaLayer23 = thetaLayer23 - alpha*(finalResult - y)*inputNodes2; 

     %Backward Propogation is then applied to the weights between the 
     %hidden layer and the input nodes. 
     thetaLayer12 = thetaLayer12 - (((alpha*(finalResult-y)*thetaLayer23(2:end))'*inputNodes2(2:end))*(1-inputNodes2(2:end))*double(inputNodes'))'; 

     %I sum the error across each iteration over all the images in the 
     %folder 
     globalError = globalError + abs(finalResult-y); 

     if(i == 400) 
      disp('Training done full cycle'); 
     end 
    end 

    %I take the average error 
    globalError = globalError/filelength; 
    disp(globalError); 
end 

end 

任何幫助將認真領會!!!!

回答

0

的任何訓練機器學習算法的成功在很大程度上取決於你用它來訓練你的算法訓練樣本量。你從來沒有確切地說過你有多少個訓練樣例,但是在面部檢測的情況下,可能需要大量的例子(如果它能工作的話)。

認爲它這樣,計算機科學家告訴您像素強度值的兩個數組。他告訴你哪一個有明示,哪一個不明確。然後他再向你展示兩個,並要求你告訴他哪一個人有一個明喻。

幸運的是我們可以解決此有一定關係。您可以使用自編碼器或像稀疏編碼這樣的字典學習器來查找數據中的更高級別結構。而不是計算機科學家顯示你的像素強度,他可以顯示你的邊緣甚至身體部位。然後,您可以將其用作神經網絡的輸入,但仍可能需要大量的訓練樣例(但比以前少)。

比類似於由斯坦福大學教授伍無監督功能學習給予了談話的啓發。