Пример #1
0
        public void ExportFontData(List <FontData> fontDatas, List <ImageDecorator> decorators)
        {
            LabelConfig labelConfig = null;

            if (_twoLetters.Equals("1"))
            {
                labelConfig = new TwoLetterConfig();
            }
            else
            {
                labelConfig = new SingleLetterConfig(BigString);
            }

            foreach (var fontdata in fontDatas)
            {
                var imagePath = Path.Combine(dir.ToString(), fontdata.FontName);
                Directory.CreateDirectory(imagePath);
                labelConfig.LabelDatas.ForEach(ld =>
                {
                    SaveOneImage(ld.Label, ld.LabelAsFolderName, fontdata, imagePath, decorators);
                });
            }
        }
Пример #2
0
        //normallly we run command 2 then command 1, when byte file for image and label are generated
        //move those files to ML solution
        static void Main(string[] args)
        {
            //for each character, we have around 10000 images, either synthesized ones or dummy copies.
            //our ML solution does not randomize the order of the images, therefore it is vital that we shuffle them
            //already in this project
            Console.WriteLine("generate a byte file containing all image byte data by pointing to an image source - 1");

            //we are not sure if the synthesize works, but it is supported. if synthesize is not used, in order to gain enough
            //training examples, we are going to make copies of original ones. The images are organized by font name, not by
            //character identity, we are going to resize them into 28*28 and reorganize them into folder by character identity,
            //then for each image, either we synthesize it or or we make some copies of it (if we are using windows font for testing, 14 fonts, 1000 copies are enougth)
            Console.WriteLine("synthesize images / make copies of original ones - 2");

            //the ML pipleline takes image and label byte files generated by us as input
            //in order to make sure our own byte files are in correct format, we unpack the original
            //"..\\..\\Data\\train-labels-idx1-ubyte", "..\\..\\Data\\train-images-idx3-ubyte" files into
            //normal image files. When we view the actual images, we can be sure about the processing
            //generating the byte files for image/label

            Console.WriteLine("unpack mnist byte files into images - 3");
            LabelConfig labelConfig = null;

            if (_twoLetters.Equals("1"))
            {
                labelConfig = new TwoLetterConfig();
            }
            else
            {
                var allSingleChars = ConfigurationManager.AppSettings["GeneratedChars"];
                labelConfig = new SingleLetterConfig(allSingleChars);
            }

            var command = Console.ReadLine();

            if (command.Equals("1"))
            {
                ByteFileGenerator.GenerateByteFile(_fontDataDirDest, size, labelConfig);
            }
            else if (command.Equals("2"))
            {
                Console.WriteLine("we are going to normalize the data and put them into folder with char name, do you want to spawn 5 synthesized images per image? (false/true)");
                var shouldSynthesize = Convert.ToBoolean(Console.ReadLine());


                Console.WriteLine("generate more copies of original image? type of number, if 1 no copy is saved, if larger than 1 then N-1 more copies will be saved");
                var copy = Convert.ToInt32(Console.ReadLine());



                //the images feed into ML solution has black background
                Console.WriteLine("should make background black? (true/false)");
                var colorInvert = Convert.ToBoolean(Console.ReadLine());

                //create dirs for the chars or two letters
                labelConfig.LabelDatas.ForEach(ld => { DirGenerator.CreateDir(ld.Label, _fontDataDirDest); });

                Directory.CreateDirectory(_fontDataDir);
                Directory.CreateDirectory(_fontDataDirDest);
                ImageGenerator.GenerateImages(_fontDataDir,
                                              _fontDataDirDest,
                                              shouldSynthesize,
                                              synthesizeCount,
                                              copy,
                                              colorInvert,
                                              size);
            }
            else if (command.Equals("3"))
            {
                Console.WriteLine("read byte data from MNIST files, then output new byte files?");
                bool resaveByteFile = Convert.ToBoolean(Console.ReadLine());
                Console.WriteLine("save images to hard disk?");
                bool saveImages   = Convert.ToBoolean(Console.ReadLine());
                bool orderbylabel = false;
                if (resaveByteFile)
                {
                    Console.WriteLine("order by label?");
                    orderbylabel = Convert.ToBoolean(Console.ReadLine());
                }

                MNISTUnpack.UnpackByteFileToImages("..\\..\\Data\\train-labels-idx1-ubyte",
                                                   "..\\..\\Data\\train-images-idx3-ubyte",
                                                   _mnistDir,
                                                   resaveByteFile,
                                                   saveImages,
                                                   orderbylabel);
            }
        }