Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /******LOAD DATA******/
            List <TrainingItem> trainData =
                MnistReader.ConvertTrainingData(
                    MnistReader.ReadImages("train-images.idx3-ubyte", "train-labels.idx1-ubyte", 60000));

            /***Test form***/

            testForm = new TestingForm();

            /***Graph***/

            graphForm = new Graph();

            /*****Create Network Form*****/

            form = new NetworkForm();

            if (!TryLoadNetwork())
            {
                network = new NeuralNetwork(0.01, 0.9, new int[] { 196, 15, 4 });
            }

            form.DrawNetwork(network);

            form.startTrainingAction += () => network.Train(trainData, (i, cost) =>
            {
                form.SetProgress("Trained for " + TimeSpan.FromMilliseconds(network.TrainedMillis).ToString("c") + " - Gen " + i + " - Cost : " + cost);
                if (graphForm.Visible)
                {
                    graphForm.SetGraphData("Cost", network.Costs);
                }
            }, true, 10000);

            form.stopTrainingAction += network.StopTraining;

            form.toJsonAction += () =>
            {
                File.WriteAllText(networkDataPath, new NetworkInfos(network).GetJSON());
            };

            form.testNetworkAction += TestNetwork;

            form.costGraphAction += () =>
            {
                graphForm.SetGraphData("Cost", network.Costs);
                graphForm.Show();
            };

            form.FormClosed += (object o, FormClosedEventArgs a) => network.StopTraining();

            /*****END*****/

            /***RUN***/
            Application.Run(form);
        }
Beispiel #2
0
 private static void TestNetwork()
 {
     network.StopTraining();
     if (testingData == null)
     {
         testingData = MnistReader.ReadImages("t10k-images.idx3-ubyte", "t10k-labels.idx1-ubyte", 2000);
     }
     testForm.Show();
     testForm.Next();
 }