【问题标题】:Implementing a neural network for smile detection in images实现用于图像中微笑检测的神经网络
【发布时间】:2014-04-26 03:32:00
【问题描述】:

在解释问题之前,让我先解释一下问题的背景。我的任务是拍摄一张标有“不”的微笑的图像。带有微笑的文件被标记,例如 100a.jpg 和 100b.jpg。其中“a”用于表示没有微笑的图像,“b”用于表示带有微笑的图像。因此,我正在寻找一个 3 层网络,即第 1 层 = 输入节点,第 2 层 = 隐藏层和第 3 层 = 输出节点。

一般算法是:

  1. 获取图像并将其重新调整为 x 24x20 的大小。
  2. 应用从输入节点到隐藏层的前向传播。
  3. 从隐藏层向输出节点应用前向传播。
  4. 然后应用从输出节点到隐藏层的反向传播。 (公式1)
  5. 然后应用从隐藏层到输入节点的反向传播。 (公式2)

一级方程式:

公式 2:

现在问题很简单......我的代码永远不会收敛,因此我没有可用于测试网络的权重向量。问题是我不知道为什么会这样......这是我显示的错误,显然没有收敛:

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

任何帮助将不胜感激!!!!

【问题讨论】:

    标签: matlab neural-network


    【解决方案1】:

    训练任何机器学习算法的成功很大程度上取决于您用于训练算法的训练示例的数量。您从未确切说明您有多少训练示例,但在人脸检测的情况下,可能需要大量示例(如果可以的话)。

    这样想,计算机科学家向您展示了两个像素强度值数组。他告诉你哪个有明喻,哪个没有。比他多给你看两个,让你告诉他哪一个有明喻。

    幸运的是,我们可以在一定程度上解决这个问题。您可以使用自动编码器或字典学习器(如稀疏编码)来查找数据中更高级别的结构。他可以向您展示边缘甚至身体部位,而不是计算机科学家显示您的像素强度。然后,您可以将其用作神经网络的输入,但可能仍需要大量训练示例(但比以前少)。

    Stanford Ng 教授关于无监督特征学习的演讲启发了类比。

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 2021-12-25
      • 2017-08-06
      • 1970-01-01
      • 2016-12-23
      • 2015-09-22
      • 1970-01-01
      • 2017-11-22
      • 2017-12-28
      相关资源
      最近更新 更多