private void recognizeButton_Click(object sender, EventArgs e) { var bitmap = new Bitmap(charPictureBox.Image); var inputVector = new double[IMG_WIDHT * IMG_HEIGHT]; for (var x = 0; x < bitmap.Width; x++) { for (var y = 0; y < bitmap.Height; y++) { var pixel = bitmap.GetPixel(x, y); inputVector[y + x * IMG_HEIGHT] = Convert.ToDouble(pixel.R == 0 && pixel.G == 0 && pixel.B == 0); } } NumberRecognizerNeuralNetwork numberRecognizerNeuralNetwork = new NumberRecognizerNeuralNetwork(this.neuralNetwork); int result = numberRecognizerNeuralNetwork.GetNumberFromImgVector(inputVector); answerListBox.Items.Clear(); foreach (var neuron in numberRecognizerNeuralNetwork.GetNeuralNetwork().GetLastLayer().GetListNeurons()) { answerListBox.Items.Add(Math.Round(neuron.GetOutputData(), 5).ToString()); } if (result == -1) { MessageBox.Show("Can not recognize char."); } else { MessageBox.Show($"Char is: {result}."); } }
private void educateNetworkButton_Click(object sender, EventArgs e) { UncertaintyPropagationMethod uncertaintyPropagationMethod = new UncertaintyPropagationMethod(LEARNING_RATE); NumberRecognizerNeuralNetwork numberRecognizerNeuralNetwork = new NumberRecognizerNeuralNetwork(this.neuralNetwork); MachineLearning.NeuralNetwork.Report.Manager reportManager = new MachineLearning.NeuralNetwork.Report.Manager(); NeuralNetworkObj neuralNetworkObj = numberRecognizerNeuralNetwork.GetNeuralNetwork(); var prepareData = this.GetPrepareData(neuralNetworkObj.GetLastLayer().GetCountNeurons()); int countEpoch = Convert.ToInt16(educateNetworkNumericUpDown.Value); for (int epoch = 0; epoch < countEpoch; epoch++) { reportManager.AddDataBeforeEducate(neuralNetworkObj, prepareData); for (int iteration = 0; iteration < COUNT_ITERATION; iteration++) { foreach (var entity in prepareData) { double[] inputVector = entity.Key; double[] expectedResultVector = entity.Value; neuralNetworkObj = uncertaintyPropagationMethod.GetTaughtNeuralNetwork( numberRecognizerNeuralNetwork.GetNeuralNetwork(), inputVector, expectedResultVector ); } } educateNetworkProgressBar.Value = Convert.ToInt16((epoch + 1.0) / countEpoch * 100); reportManager.AddDataAfterEducate(neuralNetworkObj, prepareData); reportManager.SaveReport(neuralNetworkObj); neuralNetworkObj.EpochPassed(); } numberRecognizerNeuralNetwork.UpdateNeuralNetwork(neuralNetworkObj); }
private void generateButton_Click(object sender, EventArgs e) { //todo validation string name = newNetworkNameTextBox.Text; int countLayers = Convert.ToInt16(layersCountTextBox.Text); int[] neuronsInLayer = new int[countLayers]; for (int layerId = 0; layerId < countLayers; layerId++) { neuronsInLayer[layerId] = Convert.ToInt16( Interaction.InputBox($"Input count neuron in layer {layerId}?", "Configuration layers", "") ); } NumberRecognizerNeuralNetwork numberRecognizerNeuralNetwork = new NumberRecognizerNeuralNetwork(name, neuronsInLayer, IMG_HEIGHT, IMG_WIDHT); numberRecognizerNeuralNetwork.GenerateRandom(); this.LoadNetworks(); }