Ejemplo n.º 1
0
        private void ImagePatternRecognization(int index)
        {
            List <Mutex> mutexs = new List <Mutex>(2);

            for (int i = 0; i < 2; i++)
            {
                var mutex = new Mutex();
                mutexs.Add(mutex);
            }

            var NNTessing = new NNTestPatterns(_NN, _Mnistdatabase, _Preference, _bDatabaseReady, null, null, this, mutexs);
            var thread    = new Thread(() => NNTessing.PatternRecognizingThread(index));

            thread.Start();
        }
Ejemplo n.º 2
0
        private void buttonMnistTest_Click(object sender, EventArgs e)
        {
            if ((_bTestingThreadRuning == false) && (_bTrainingThreadRuning == false))
            {
                var  mutexs           = new List <Mutex>(2);
                int  theadsNum        = (int)numericUpDownThreads.Value;
                var  nnTesting        = (NNTestPatterns)null;;
                var  nnNetwork        = new NeuralNetwork();
                bool bDatabaseforTest = false;
                //create neural network
                try
                {
                    CreateNNNetWork(nnNetwork);
                    //initialize weight parameters to the network
                    if (_mnistWeightsFile != "")
                    {
                        _MainMutex.WaitOne();
                        var fsIn = new FileStream(_mnistWeightsFile, FileMode.Open);
                        var arIn = new Archive(fsIn, ArchiveOp.load);
                        nnNetwork.Serialize(arIn);
                        fsIn.Close();
                        _MainMutex.ReleaseMutex();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                //
                if (radioButtonTestingdatabase.Checked)
                {
                    if (_bTestingDataReady)
                    {
                        nnTesting        = new NNTestPatterns(nnNetwork, _MinstTestingDatabase, _Preference, _bTestingDataReady, _EventTestingStopThread, _EventTestingThreadStopped, this, mutexs);
                        bDatabaseforTest = _bTestingDataReady;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (_bTrainingDataReady)
                    {
                        nnTesting        = new NNTestPatterns(nnNetwork, _MnistTrainingDatabase, _Preference, _bTrainingDataReady, _EventTestingStopThread, _EventTestingThreadStopped, this, mutexs);
                        bDatabaseforTest = _bTrainingDataReady;
                    }
                    else
                    {
                        return;
                    }
                }
                if (bDatabaseforTest)
                {
                    //
                    listBox2.Items.Clear();
                    for (int i = 0; i < 2; i++)
                    {
                        var mutex = new Mutex();
                        mutexs.Add(mutex);
                    }
                    _EventTestingStopThread.Reset();
                    _EventTestingThreadStopped.Reset();
                    _testing_threads = new List <Thread>(2);

                    try
                    {
                        for (int i = 0; i < theadsNum; i++)
                        {
                            var thread = new Thread(delegate()
                            {
                                nnTesting.PatternsTestingThread((int)numericUpDownNumberofTestPattern.Value);
                            });
                            _testing_threads.Add(thread);
                            thread.Start();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }
                    _bTestingThreadRuning = true;
                    radioButtonTestingdatabase.Enabled  = false;
                    radioButtonTrainingdatabase.Enabled = false;
                    buttonMnistTest.Enabled             = false;
                }
            }
        }