Beispiel #1
0
        /// <summary>
        /// Выполнить распознавание.
        /// </summary>
        private static void DoRecognizeWork()
        {
            Console.BackgroundColor = ConsoleColor.Green;
            Console.ForegroundColor = ConsoleColor.Black;

            Console.WriteLine(ConsoleMessageConstants.RECOGNIZE_RESULT_MESSAGE);

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;

            Console.WriteLine(ConsoleMessageConstants.LOAD_PATH_MESSAGE);

            var path          = GetPathToWeightFiles();
            var weightLodUtil = new WeightLoadUtil(path);

            weightLodUtil.Load();

            var data       = weightLodUtil.GetData();
            var coreToLoad = weightLodUtil.GetNewCore();

            FilterCoreModel.UpdateCore(coreToLoad);

            var breakFlag        = false;
            var isFirstIteration = true;

            do
            {
                if (isFirstIteration)
                {
                    RecognizeImage(data);
                    isFirstIteration = false;
                }

                Console.WriteLine(ConsoleMessageConstants.RECOGNIZE_ANOTHER_MESSAGE);
                var dialogResult = Console.ReadLine();

                if (DialogConstants.NoResults.Contains(dialogResult))
                {
                    breakFlag = true;
                }

                if (DialogConstants.YesResults.Contains(dialogResult))
                {
                    RecognizeImage(data);
                }
            } while (!breakFlag);

            Console.WriteLine(ConsoleMessageConstants.PRESS_ANY_KEY_MESSAGE);
            Console.ReadKey();

            Console.WriteLine(ConsoleMessageConstants.EXIT_MESSAGE);
            System.Threading.Thread.Sleep(500);
            Environment.Exit(0);
        }
Beispiel #2
0
        /// <summary>
        /// Выполнить обучение.
        /// </summary>
        private static void DoLearnWork()
        {
            Console.BackgroundColor = ConsoleColor.Green;
            Console.ForegroundColor = ConsoleColor.Black;

            Console.WriteLine(ConsoleMessageConstants.LEARN_RESULT_MESSAGE);

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;

            var pathToFiles     = GetPathToFiles();
            var pathToResources = PathHelper.GetResourcesPath();

            if (string.IsNullOrEmpty(pathToFiles))
            {
                pathToFiles = pathToResources;
            }

            var images = Directory.GetFiles(pathToFiles).ToList();

            var converter            = new ImageConverterUtil(images);
            var listOfPicturesMatrix = converter.ConvertImagesToMatrix();

            var iterationsCount = listOfPicturesMatrix.Count;

            var configuration = new Configuration
            {
                Alpha                  = 3.1,
                Epsilon                = 3.1,
                EpochCount             = 3,
                IdealResult            = 1,
                IterationsInEpochCount = iterationsCount
            };

            var layers     = new List <Layer>();
            var filterCore = FilterCoreModel.Initialize();

            LayersInitialize(listOfPicturesMatrix, layers, filterCore,
                             out Dictionary <string, double> inputLayerWeights,
                             out List <NeuronModel> convolutionalLayerNeurons,
                             out List <NeuronModel> hiddenLayerNeurons,
                             out NeuronModel outputNeuron);

            var learningUtil = new LearningUtil(layers, configuration, listOfPicturesMatrix);

            learningUtil.StartToLearn();
        }
Beispiel #3
0
        /// <summary>
        /// Обновить ядро фильтра.
        /// </summary>
        /// <param name="gradients">Матрица градиентов.</param>
        private void UpdateCore(double[,] gradients)
        {
            var updatedCore = new double[MatrixConstants.FILTER_MATRIX_SIZE,
                                         MatrixConstants.FILTER_MATRIX_SIZE];

            for (var xIndex = 0; xIndex < MatrixConstants.FILTER_MATRIX_SIZE; ++xIndex)
            {
                for (var yIndex = 0; yIndex < MatrixConstants.FILTER_MATRIX_SIZE; ++yIndex)
                {
                    updatedCore[xIndex, yIndex] = _configuration.Epsilon *
                                                  gradients[xIndex, yIndex] + _configuration.Alpha *
                                                  FilterCoreModel.LastCoreValue[xIndex, yIndex];
                }
            }

            FilterCoreModel.UpdateCore(updatedCore);
        }