示例#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;
        }
示例#2
0
        private async void BtnTestNeuralNetwork_Click(object sender, EventArgs e)
        {
            //This function will only be called if a neural network has been trained.
            //Now we want to train a set of images
            bool gotImages = false;
            bool gotLabels = false;

            string strTestingInFile  = "t10k-images.idx3-ubyte";
            string strTestinglblFile = "t10k-labels.idx1-ubyte";

            PrimeNeuralNetwork.ResetMNIST();
            PrimeNeuralNetwork.SetEpochCount(1);
            Task <bool> gettingImagesTask = new Task <bool>(() => { return(PrimeNeuralNetwork.ReadImages(strTestingInFile)); });
            Task <bool> gettingLabelsTask = new Task <bool>(() => { return(PrimeNeuralNetwork.ReadLabels(strTestinglblFile)); });

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

            Cursor.Current = Cursors.WaitCursor;

            DisableActions();

            //NOTE: the following function will only end when Images and Labels are done being read
            GenerateLoadingImgTxt(ref PrimeNeuralNetwork);

            gotImages = await gettingImagesTask;
            gotLabels = await gettingLabelsTask;

            Cursor.Current = Cursors.Default;

            totalImages = PrimeNeuralNetwork.GetTotalImages();

            //Since the testing images and labels have been read, we can now begin testing
            Task taskTestingNetwork = new Task(() => { PrimeNeuralNetwork.TestNetwork(); });

            taskTestingNetwork.Start();

            //Generate a testing loading bar screen
            LoadingScreen currLoadingScreen = new LoadingScreen();

            currLoadingScreen.Show(this);

            while (!PrimeNeuralNetwork.FinishedTesting())
            {
                currLoadingScreen.AdjustLoadBar(PrimeNeuralNetwork.GetImagesRead(), totalImages, 0, totalImages, Mode.TESTING);
            }

            await taskTestingNetwork;

            currLoadingScreen.Close();

            DisplayResults();
            EnableActions();
            BtnNext.Enabled = true;
        }