private void ProcessNetwork() { app.WriteLine("Downsampling images..."); foreach (ImagePair pair in imageList) { IMLData ideal = new BasicMLData(outputCount); int idx = pair.Identity; for (int i = 0; i < outputCount; i++) { if (i == idx) { ideal.Data[i] = 1; } else { ideal.Data[i] = -1; } } try { var img = new Bitmap(pair.File); var data = new ImageMLData(img); training.Add(data, ideal); } catch (Exception e) { app.WriteLine("Error loading: " + pair.File + ": " + e.Message); } } String strHidden1 = GetArg("hidden1"); String strHidden2 = GetArg("hidden2"); if (training.Count == 0) { app.WriteLine("No images to create network for."); return; } training.Downsample(downsampleHeight, downsampleWidth); int hidden1 = int.Parse(strHidden1); int hidden2 = int.Parse(strHidden2); network = EncogUtility.SimpleFeedForward(training .InputSize, hidden1, hidden2, training.IdealSize, true); app.WriteLine("Created network: " + network); }
private void Learn_Click(object sender, RoutedEventArgs e) { var downsample = new Downsampler(); var training = new ImageMLDataSet(downsample, true, 1, -1); for (var i = 0; i < Images.Count; ++i) { var ideal = new BasicMLData(DIGITS_COUNT); for (int j = 0; j < DIGITS_COUNT; ++j) { if (j == i) { ideal[j] = 1; } else { ideal[j] = -1; } } foreach (var img in Images[i]) { MemoryStream stream = new MemoryStream(); BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(img)); encoder.Save(stream); var bitmap = new Drawing.Bitmap(stream); var data = new ImageMLData(bitmap); training.Add(data, ideal); } } training.Downsample(DIGIT_HEIGHT, DIGIT_WIDTH); network = EncogUtility.SimpleFeedForward(training.InputSize, 35, 0, training.IdealSize, true); double strategyError = 0.01; int strategyCycles = 2000; var train = new ResilientPropagation(network, training); //train.AddStrategy(new ResetStrategy(strategyError, strategyCycles)); EncogUtility.TrainDialog(train, network, training); EncogDirectoryPersistence.SaveObject(new FileInfo("network.eg"), network); }