コード例 #1
0
        public MainForm()
        {
            InitializeComponent();
            // Список камер получаем
            videoDevicesList = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            foreach (FilterInfo videoDevice in videoDevicesList)
            {
                cmbVideoSource.Items.Add(videoDevice.Name);
            }

            if (cmbVideoSource.Items.Count > 0)
            {
                cmbVideoSource.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("А нет у вас камеры!", "Ошибочка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            controller = new Controller(new FormUpdateDelegate(UpdateFormFields));
            //            updateTmr = new System.Threading.Timer(Tick, evnt, 500, 100);

            samplesSet = controller.processor.CreateSamplesSet();
            Console.WriteLine("SAMPLE SET CREATED");
            neuralNetwork.TrainOnDataSet(samplesSet, 20, 50);
        }
コード例 #2
0
        public SamplesSet CreateSamplesSet()
        {
            var result = new SamplesSet();

            ProcessClassSamples(result, Directory.GetFiles(@"..\..\Images\play"), FigureType.PLAY);
            ProcessClassSamples(result, Directory.GetFiles(@"..\..\Images\stop"), FigureType.STOP);
            ProcessClassSamples(result, Directory.GetFiles(@"..\..\Images\pause"), FigureType.PAUSE);
            ProcessClassSamples(result, Directory.GetFiles(@"..\..\Images\forward"), FigureType.FORWARD);
            ProcessClassSamples(result, Directory.GetFiles(@"..\..\Images\backward"), FigureType.BACKWARD);

            return(result);
        }
コード例 #3
0
        public override double TestOnDataSet(SamplesSet testSet)
        {
            double correct = 0.0;

            foreach (Sample sample in testSet)
            {
                Run(sample);
                sample.output = getOutput();
                sample.processOutput();
                if (sample.Correct())
                {
                    correct += 1;
                }
            }

            return(correct / testSet.Count);
        }
コード例 #4
0
        private void ProcessClassSamples(SamplesSet samplesSet, string[] fileNames, FigureType type)
        {
            foreach (var fileName in fileNames)
            {
//                var image = getProcessedImage(new Bitmap(fileName));
//                var newPath = fileName.Split('\\');
//                newPath[newPath.Length - 1] = "processed_" + newPath.Last();
//                image.Save(String.Join("\\", newPath));

                var image  = new Bitmap(fileName);
                var inputs = new double[1000];
                for (int i = 0; i < 500; i++)
                {
                    inputs[i]       = CountBlackPixels(GetBitmapColumn(image, i));
                    inputs[i + 500] = CountBlackPixels(GetBitmapRow(image, i));
                }
                samplesSet.AddSample(new Sample(inputs, 5, type));
                Console.WriteLine($"Add sample {fileName}");
            }
        }
コード例 #5
0
        public override double TrainOnDataSet(SamplesSet samplesSet, int epochs_count, double acceptable_erorr,
                                              bool parallel = true)
        {
            Random rnd           = new Random();
            var    randomSamples = samplesSet.samples.OrderBy(x => rnd.Next());
            var    stopWatch     = new Stopwatch();

            stopWatch.Restart();
            var guessLevel = 0.0;

            for (int i = 1; i <= epochs_count; i++)
            {
                foreach (var sample in randomSamples)
                {
                    if (Train((Sample)sample) == 0)
                    {
                        guessLevel += 1;
                    }
                }
                guessLevel /= samplesSet.samples.Count;

                // updateDelegate((double)i / epochs_count, guessLevel, stopWatch.Elapsed);
                if (1.0 - guessLevel < acceptable_erorr)
                {
                    break;
                }
            }

            Console.WriteLine($"Time elapsed: {stopWatch.Elapsed}");

            stopWatch.Stop();
            // updateDelegate(1.0, guessLevel, stopWatch.Elapsed);


            return(guessLevel);
        }
コード例 #6
0
 public abstract double TestOnDataSet(SamplesSet testSet);
コード例 #7
0
 public abstract double TrainOnDataSet(SamplesSet samplesSet, int epochs_count, double acceptable_erorr,
                                       bool parallel = true);