static IEnumerable <double[]> GetAllImages(Image[] bigs) { int w = 28; int h = 28; int size = 2072; for (int y = 0; y < size - h - 2; y += h) { for (int x = 0; x < size - w - 2; x += w) { Rectangle rec = new Rectangle(x, y, w + 1, h + 1); foreach (Image img in bigs) { yield return(Digitalizer.GetInput((Bitmap)img, x, y, 29, 29, c => c.B > 100).ToArray()); } } } }
private void button2_Click(object sender, EventArgs e) { //recon if (!Loaded) { MessageBox.Show("Załaduj sieć neuronową!", "Warning"); } double[] input = null; using (Bitmap cropped = Digitalizer.AutoCrop(UserBitmap)) { using (Bitmap sized = Digitalizer.Resize(cropped, 17, 20)) { using (Bitmap bm = new Bitmap(29, 29)) { Graphics gr = Graphics.FromImage(bm); gr.Clear(Color.White); gr.DrawImage(sized, 4, 4); input = Digitalizer.GetInput(bm, 0, 0, bm.Width, bm.Height, x => x.Name == "ff000000").ToArray(); } } } double[] output = Network.Pulse(input); DrawReconResults(output); }
//util void StartLearning() { Stopped = false; Thread.CurrentThread.Priority = ThreadPriority.Lowest; Image[] bigimgs = Utility.Generate(i => Image.FromFile(@"mnist_train" + i.ToString() + ".jpg"), 10).ToArray(); int idx = 0, total = 0; List <TrainingData> trainingList = new List <TrainingData>(); foreach (double[] input in GetAllImages(bigimgs)) { if (Stopped) { return; } double[] output = Digitalizer.GetOutput(10, idx).ToArray(); Application.DoEvents(); trainingList.Add(new TrainingData(input, output)); GC.Collect(); GC.WaitForPendingFinalizers(); idx = (idx + 1) % 10; if (idx == 0) { total++; BPRequest request = new BPRequest(trainingList.ToArray(), 1) { ShuffleTrainingSet = true }; BPResponse response = Network.BP(request); double eps = response.Epochs[0].Epsilon; double ms = response.BPTime.TotalMilliseconds; trainingList.Clear(); } } StopLearning(); }