2014-06-07 27 views
0

我想使用Aforge.net識別0到9位數字。我嘗試了一切,但我仍然無法獲得結果,請看我的程序,爲什麼我無法識別數字。問題可能在於隱藏層數,學習率或輸入數據,我已經通過改變隱藏層數和學習率來嘗試它。請提出建議。使用Aforge.net的字符識別Nural網絡

// 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); 
     } 

類別特徵用於訓練nural網絡 類特徵 {

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; 
    } 

}

+0

我建議你看看[Accord.NET](http://accord-framework.net/),它實際上是AForge.NET Framework的擴展。在[樣本庫](http://accord-framework.net/samples.html)中,您還可以找到許多手寫字符識別應用程序和類似程序。 –

回答

0

我沒有使用aforge,但重新提供輸入。使用backprop神經網絡對這個問題:

  1. 你需要的東西像網格獲取圖像

  2. 你至少需要一個,可能是2的1/100每一個小區的10×10輸入網格,隱藏層

  3. 淨將訓練用更快的偏置輸入 - 這意味着一個固定值的源 - 針對每個小區(這讓細胞培養更快:Role of Bias in Neural Networks

  4. 我從未š以bp模式開始,但總是先運行統計退火。 BP是局部極小內下降,一旦找到一個

另外:

  • 你是否成功使用aforge其他問題?

  • 當你試圖訓練網時會發生什麼?

+0

你好,謝謝你的回答。是的,我用於計算機視覺。我第一次使用神經網絡,當我訓練輸入和輸出數據並且稍後嘗試識別任何字符時,它會給出錯誤的答案。假設我餵它1並且它識別它8。你可以測試上面的代碼,請讓我知道哪裏是問題。 – user3292157