예제 #1
0
        void TrainWorks()
        {
            using (var ip = new ImageProvider())
            {
                var imageProvider = ip.ImageStream();
                List <(Vector <double>, int)> tmp = imageProvider
                                                    .Select(i => new { pixels = i.SampledPixels, i.Label })
                                                    .Select(i => (Vector <double> .Build.DenseOfEnumerable(i.pixels), i.Label)).ToList();
                var X = tmp.Select(i => i.Item1).ToList();
                var Y = tmp.Select(i => i.Item2).ToList();

                imageProvider.Select(i => i.Label).ToList();
                Random r   = new Random(1);
                var    net = new MatrixNetwork(784);
                net.AddLayer(200, r);
                net.AddLayer(10, r);
                net.Train(X, Y);

                int performance = 0;
                int total       = 0;
                foreach (var el in X.Zip(Y, (input, expected) => new { input, expected }))
                {
                    total++;
                    var result = net.Predict(el.input, out List <double> output);
                    if (el.expected == result)
                    {
                        performance++;
                    }
                }

                Assert.That(performance, Is.InRange(6000, total));
            }
        }
예제 #2
0
 public void InitialFileClamped0to256()
 {
     using (ImageProvider i = new ImageProvider())
     {
         foreach (var el in i.ImageStream())
         {
             foreach (var pixel in el.Pixels())
             {
                 Assert.That(pixel, Is.InRange(0, 255));
             }
         }
     }
 }
예제 #3
0
        public void ValidateDatabaseInput()
        {
            using (ImageProvider i = new ImageProvider())
            {
                var stream = i.ImageStream().GetEnumerator();

                stream.MoveNext();
                Assert.That(stream.Current.Label, Is.EqualTo(5));

                stream.MoveNext();
                Assert.That(stream.Current.Label, Is.EqualTo(0));

                stream.MoveNext();
                Assert.That(stream.Current.Label, Is.EqualTo(4));

                stream.MoveNext();
                Assert.That(stream.Current.Label, Is.EqualTo(1));

                stream.MoveNext();
                Assert.That(stream.Current.Label, Is.EqualTo(9));
            }
        }