字符识别使用Aforge.net Nural网络

时间:2014-06-07 14:56:50

标签: c# .net artificial-intelligence aforge

我正在尝试使用Aforge.net识别0到9位数字。我尝试了一切,但我仍然无法得到结果请查看我的程序以及为什么我无法识别数字。问题可能在于隐藏层数,学习率或输入数据,我通过改变隐藏层数和学习率来尝试它。请提出建议。

// opening file
OpenFileDialog open = new OpenFileDialog();
ActivationNetwork enactivation = new ActivationNetwork(new BipolarSigmoidFunction(1),  3886,10, 10);
double[][] input = new double[10][];
double[][] output = new double[10][];
//generating input data using Feature class -- which code is given below

Feature feature = new Feature();

//iterating for all 10 digits. 
for (int i = 0; i < 10; i++)
        {
           open.ShowDialog();
           Bitmap bitmap = new Bitmap(open.FileName);
          double[] features = feature.features(bitmap);
            input[i] = features;
             features = feature.features(bitmap);
            output[i] = feature.features(bitmap);
         }

enactivation.Randomize();
        BackPropagationLearning learn = new BackPropagationLearning(enactivation);
//learning 
        learn.LearningRate = 0.005f;
        learn.Momentum = 0.005f;
        double errora;
        int iteration = 0;

        while (true)
        {
            errora = learn.RunEpoch(input, output);
            if (errora < 0.0006)
                break;
            else if (iteration > 23000)
               break;
            iteration++;
           // Console.WriteLine("error {0} {1} ", errora, iteration);
       }
       double[] sample;
        open.ShowDialog();
        Bitmap temp = new Bitmap(open.FileName);
       // providing input for computation using feature class
        sample = feature.features(temp);
        foreach (double daa in enactivation.Compute(sample))
        {
            Console.WriteLine(daa);
        }

用于为训练神经网络提供输入的类功能 类功能     {

    public double[] features(Bitmap bitmap)
    {
        //feature 
        double[] feature = new double[bitmap.Width * bitmap.Height];
       int featurec = 0;
        for (int vert = 0; vert < bitmap.Height; vert++)
        {
            for (int horizantal = 0; horizantal < bitmap.Width; horizantal++)
            {
                feature[featurec] = bitmap.GetPixel(horizantal, vert).ToArgb();
                if (feature[featurec] < 1)
                {
                    feature[featurec] = -0.5;
                }
                else
                {
                    feature[featurec] = 0.5;
                }
                featurec++;
            }
        }
        return feature;
    }

}

1 个答案:

答案 0 :(得分:0)

我还没有使用过aforge,但重新开始。使用backprop神经网络解决这个问题:

  1. 您需要类似10x10输入网格的内容,网格中的每个单元格都会获得图像的1/100

  2. 您至少需要一个,可能是2个隐藏图层

  3. 对于每个单元格,网络将通过偏置输入(意味着固定值的来源)更快地训练(这样可以让单元格更快地训练:Role of Bias in Neural Networks

  4. 我从不以bp模式开始,但总是先运行统计退火。一旦找到Bp,Bp用于降低局部最小值

  5. 另外:

    • 您是否成功将aforge用于其他问题?

    • 当你尝试训练网时会发生什么?