Пример #1
0
        public void TestArrays()
        {
            string imgfn = "test-c3.png";

            // load Bytearray
            Bytearray ba = new Bytearray(1, 1);

            ImgIo.read_image_gray(ba, imgfn);
            OcrRoutine.Invert(ba);
            //NarrayUtil.Sub((byte)255, image);
            byte[] bytes1 = ba.To1DArray();
            NarrayShow.ShowConsole(ba);
            StdInput linput1 = new StdInput(ba);

            Console.WriteLine();

            // load StdInput
            Bitmap   bitmap  = ImgIo.LoadBitmapFromFile(imgfn);
            StdInput linput2 = StdInput.FromBitmap(bitmap);
            //NarrayShow.ShowConsole(linput2);

            // test convert
            Floatarray fa      = linput2.ToFloatarray();
            StdInput   linput3 = new StdInput(fa);

            Console.WriteLine("Arrays is identical? {0}", Equals(linput1.GetDataBuffer(), linput2.GetDataBuffer()));
            Console.WriteLine("Arrays is identical? {0}", Equals(linput2.GetDataBuffer(), linput3.GetDataBuffer()));
        }
Пример #2
0
        public void TestRowDataset()
        {
            DRandomizer.Default.init_drand(DateTime.Now.Millisecond);

            // load Mnist datasource
            MnistDatasource mds = new MnistDatasource();

            mds.LoadFromFile(mnistFileNamePrefix);

            // convert mnist to RowDataset8
            RowDataset8 ds8 = MnistDatasetConvert.GetRowDataset8(mds, classes);

            // show random sample to console
            Floatarray fa      = new Floatarray();
            int        isample = (int)DRandomizer.Default.drand(ds8.nSamples(), 0);

            ds8.Input(fa, isample);
            Console.WriteLine("Char is '{0}'", (char)ds8.Cls(isample));
            NarrayShow.ShowConsole(fa);

            // compare random float sample and original mnist
            StdInput inp1 = new StdInput(mds.ImagesData[isample], mds.ImgHeight, mds.ImgWidth);
            StdInput inp2 = new StdInput(fa);

            Console.WriteLine("Arrays is identical? {0}", Equals(inp1.GetDataBuffer(), inp2.GetDataBuffer()));

            // save RowDataset8 to file
            Console.WriteLine("Saving {0} samples..", ds8.nSamples());
            ds8.Save(mnistFileNamePrefix + dsExt);

            // load RowDataset8 from file
            RowDataset8 ds = new RowDataset8();

            ds.Load(mnistFileNamePrefix + dsExt);
            Console.WriteLine("Loaded {0} samples", ds.nSamples());
        }