/// <summary> /// Determine the drawn image and determine the output /// </summary> /// <param name="sender">sender object</param> /// <param name="e">event</param> private void aiDetermineButton_Click(object sender, EventArgs e) { if (digitNN != null) { double[] input = DigitNN.transformBitmapdata(B); byte result = digitNN.determine(input); if (aiTextBox.Lines.Length == 6) { NeuralNetwork.CustomTextBox temp = new NeuralNetwork.CustomTextBox(); for (int i = 1; i < aiTextBox.Lines.Length; i++) { temp.Text += aiTextBox.Lines[i] + "\n"; } temp.Text += "I think it is a " + result + " :)"; aiTextBox.Text = temp.Text; } else { aiTextBox.Text += "\nI think it is a " + result + " :)"; } } if (letterNN != null) { double[] input = LetterNN.transformBitmapdata(B); char result = letterNN.determine(input); if (aiTextBox.Lines.Length == 6) { NeuralNetwork.CustomTextBox temp = new NeuralNetwork.CustomTextBox(); for (int i = 1; i < aiTextBox.Lines.Length; i++) { temp.Text += aiTextBox.Lines[i] + "\n"; } if (result != 0) { temp.Text += "I think it is a " + result + " :)"; } else { temp.Text += "I'm not sure :("; } aiTextBox.Text = temp.Text; } else { if (result != 0) { aiTextBox.Text += "\nI think it is a " + result + " :)"; } else { aiTextBox.Text += "\nI'm not sure :("; } } } }
/// <summary> /// Thread for digit training /// </summary> private void trainDigitThread() { double[][] transformedData = DigitNN.transformBitmapdata(data); int epochs = 30; int batchSize = 10; double[][] trainData = null; double[][] validset = null; byte[] trainLabels = null; byte[] validsetLabels = null; if (labelsDigit.Length == 10000) { DigitNN.splitIntoTrainAndValidset(transformedData, out trainData, out validset, labelsDigit.Length - labelsDigit.Length / 10); DigitNN.splitIntoTrainAndValidsetLabels(labelsDigit, out trainLabels, out validsetLabels, labelsDigit.Length - labelsDigit.Length / 10); } if (labelsDigit.Length == 60000) { DigitNN.splitIntoTrainAndValidset(transformedData, out trainData, out validset, labelsDigit.Length - labelsDigit.Length / 6); DigitNN.splitIntoTrainAndValidsetLabels(labelsDigit, out trainLabels, out validsetLabels, labelsDigit.Length - labelsDigit.Length / 6); } Train <byte> .trainNetwork(digitNN, trainData, validset, labelsDigit, validsetLabels, epochs, batchSize, aiTextBox); pictureBoxAI.Image = Properties.Resources.ai; }