Beispiel #1
0
        private async void BtnTrainNN_Click(object sender, EventArgs e)
        {
            int epochSize = 0;

            //These will be our hard-coded file names. We do this for now because program doesnt work with other files yet.
            string strTrainingInFile  = "train-images.idx3-ubyte";
            string strTrainingLblFile = "train-labels.idx1-ubyte";


            //Obtain Hyper Parameters from GUI
            dblEta          = double.Parse(txtEta.Text);
            intNeuronCnt    = int.Parse(txtNeuronCnt.Text);
            intMiniBatchCnt = int.Parse(txtMiniBatch.Text);
            dblEpochCount   = double.Parse(txtEpoch.Text);
            actFunc         = txtActFunc.Text;

            //Declare tempNeuralNetwork class(C++) and set all the hyper parameters
            MnistWrapper.MnistWrapperClass tempNeuralNetwork = new MnistWrapper.MnistWrapperClass();
            tempNeuralNetwork.SetActFunc(actFunc);
            tempNeuralNetwork.SetEpochCount(dblEpochCount);
            tempNeuralNetwork.SetNeuronCount(intNeuronCnt);
            tempNeuralNetwork.SetEta(dblEta);
            tempNeuralNetwork.SetBatchSize(intMiniBatchCnt);

            //Obtain the images and labels from the given file names
            Task <bool> gettingImagesTask = new Task <bool>(() => { return(tempNeuralNetwork.ReadImages(strTrainingInFile)); });
            Task <bool> gettingLabelsTask = new Task <bool>(() => { return(tempNeuralNetwork.ReadLabels(strTrainingLblFile)); });

            gettingImagesTask.Start();
            gettingLabelsTask.Start();

            Cursor.Current = Cursors.WaitCursor;

            DisableActions();
            GenerateLoadingImgTxt(ref tempNeuralNetwork);

            Cursor.Current = Cursors.Default;

            epochSize   = tempNeuralNetwork.GetEpochSize();
            totalImages = tempNeuralNetwork.GetTotalImages();

            Task trainingTask = new Task(() => { tempNeuralNetwork.TrainNetwork(); });

            trainingTask.Start();

            //While the Network is training with read inputs and labels, display a loading screen
            LoadingScreen currLoadingScreen = new LoadingScreen();

            currLoadingScreen.Show(this);

            while (!(tempNeuralNetwork.FinishedTraining()))
            {
                currLoadingScreen.AdjustLoadBar(tempNeuralNetwork.GetImagesRead(), totalImages, tempNeuralNetwork.GetEpochIterator(), epochSize, Mode.TRAINING);
            }
            await trainingTask;

            currLoadingScreen.Close();
            EnableActions();
            PrimeNeuralNetwork = tempNeuralNetwork;
        }
Beispiel #2
0
        private void GenerateLoadingImgTxt(ref MnistWrapper.MnistWrapperClass currNetwork)
        {
            int counter = 0;

            while (!currNetwork.FinishedReadingImages() || !currNetwork.FinishedReadingLabels())
            {
                switch (counter)
                {
                case 0:
                    WaitingLabel.Text = "Loading images and labels from local folder.";
                    counter++;
                    break;

                case 1:
                    WaitingLabel.Text = "Loading images and labels from local folder..";
                    counter++;
                    break;

                case 2:
                    WaitingLabel.Text = "Loading images and labels from local folder...";
                    counter           = 0;
                    break;
                }
                Application.DoEvents();
                Thread.Sleep(1000);
            }
            WaitingLabel.Text = "";
        }