示例#1
0
        private void teachButton_Click(object sender, EventArgs e)
        {
            _terminate    = false;
            _error        = 1.0;
            _progress     = 0;
            _terminated   = false;
            _controlError = -1;
            _updateProgress();

            new Thread(() =>
            {
                var samples      = CaptchasLibrary.GetRecognizedCaptchas();
                var digitImages  = new List <Image>();
                var digitResults = new List <int>();

                int controlStart = (int)(samples.Count * 0.8);
                for (var i = 0; i < controlStart; i++)
                {
                    var recognizer = new CaptchaRecognizer(samples[i].Image);
                    var rectangles = recognizer.SplitDigits();

                    for (var j = 0; j < rectangles.Length; j++)
                    {
                        digitImages.Add(ImageHelper.Crop(recognizer.Target, rectangles[j]));
                        digitResults.Add(int.Parse(samples[i].Answer.Substring(j, 1)));
                    }
                }
                var teacher = new NeuralNetworkTrainer(digitImages.ToArray(), digitResults.ToArray());

                teacher.Run((net, data, epochs, reports, er, u, userData) =>
                {
                    _error    = net.MSE;
                    _progress = 1.0 * u / epochs;
                    if (_terminate)
                    {
                        return(-1);
                    }
                    return(0);
                });
                teacher.Network.Save(CaptchaRecognizer.NetworkPath);

                var controlTotal  = 0;
                var controlPasses = 0;
                for (var i = controlStart; i < samples.Count; i++)
                {
                    var rec = new CaptchaRecognizer(samples[i].Image);
                    var res = rec.Recognize();
                    controlTotal++;
                    if (res.Result == samples[i].Answer)
                    {
                        controlPasses++;
                    }
                }
                _controlError = 1.0 * controlPasses / controlTotal;
                _error        = teacher.Network.MSE;
                _terminate    = true;
                _terminated   = true;
                _progress     = 1;
            }).Start();
        }
示例#2
0
 private double[] _computeProbabs(Image image)
 {
     return(_network.Run(NeuralNetworkTrainer.GetRawData(image)));
 }