Exemple #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DigitImage currImage = trainImages[0];
            Bitmap     bitMap    = MakeBitmap(currImage, 6);

            foto.Source = bitMap.ToBitmapImage();
        }
Exemple #2
0
        public static DigitImage[] LoadData(string pixelFile, string labelFile, int numImages)
        {
            DigitImage[] result = new DigitImage[numImages];
            byte[][]     pixels = new byte[28][];
            for (int i = 0; i < pixels.Length; ++i)
            {
                pixels[i] = new byte[28];
            }
            FileStream   ifsPixels = new FileStream(pixelFile, FileMode.Open);
            FileStream   ifsLabels = new FileStream(labelFile, FileMode.Open);
            BinaryReader brImages  = new BinaryReader(ifsPixels);
            BinaryReader brLabels  = new BinaryReader(ifsLabels);
            int          magic1    = brImages.ReadInt32(); // stored as big endian

            magic1 = ReverseBytes(magic1);                 // convert to Intel format
            int imageCount = brImages.ReadInt32();

            imageCount = ReverseBytes(imageCount);
            int numRows = brImages.ReadInt32();

            numRows = ReverseBytes(numRows);
            int numCols = brImages.ReadInt32();

            numCols = ReverseBytes(numCols);
            int magic2 = brLabels.ReadInt32();

            magic2 = ReverseBytes(magic2);
            int numLabels = brLabels.ReadInt32();

            numLabels = ReverseBytes(numLabels);
            for (int di = 0; di < numImages; ++di)
            {
                for (int i = 0; i < 28; ++i) // get 28x28 pixel values
                {
                    for (int j = 0; j < 28; ++j)
                    {
                        byte b = brImages.ReadByte();
                        pixels[i][j] = b;
                    }
                }
                byte       lbl    = brLabels.ReadByte(); // get the label
                DigitImage dImage = new DigitImage(28, 28, pixels, lbl);
                result[di] = dImage;
            } // Each image
            ifsPixels.Close(); brImages.Close();
            ifsLabels.Close(); brLabels.Close();
            return(result);
        }
Exemple #3
0
        public static Bitmap MakeBitmap(DigitImage dImage, int mag)
        {
            int      width  = dImage.width * mag;
            int      height = dImage.height * mag;
            Bitmap   result = new Bitmap(width, height);
            Graphics gr     = Graphics.FromImage(result);

            for (int i = 0; i < dImage.height; ++i)
            {
                for (int j = 0; j < dImage.width; ++j)
                {
                    int pixelColor          = 255 - dImage.pixels[i][j]; // black digits
                    System.Drawing.Color c  = System.Drawing.Color.FromArgb(pixelColor, pixelColor, pixelColor);
                    SolidBrush           sb = new SolidBrush(c);
                    gr.FillRectangle(sb, j * mag, i * mag, mag, mag);
                }
            }
            return(result);
        }
Exemple #4
0
        public async Task <bool> Lern()
        {
            await Task.Factory.StartNew(async() =>
            {
                await GenerateRandomWeight();
                await GenerateBias();
                await LoadTreningData(trainImages);


                //for every image
                for (int c = 0; c < 60000; c++)
                {
                    DigitImage currImage = trainImages[c];
                    Bitmap bitMap        = MakeBitmap(currImage, 6);
                    foto.Dispatcher.Invoke(new UpdateImageCallback(this.UpdateImage), bitMap);
                    await CountHLOutput(c);
                    await CountOLOutput(c);


                    await ErrorTotals(c);

                    await ErrorHiddenOuT(c);
                    await ErrorHiddenIn(c);
                }

                await LoadTreningData(testImages);
                for (int t = 0; t < 10000; t++)
                {
                    DigitImage currImage = testImages[t];
                    Bitmap bitMap        = MakeBitmap(currImage, 6);
                    TestFoto.Dispatcher.Invoke(new UpdateImageCallback(this.UpdateTestImage), bitMap);
                    await CountHLOutput(t);
                    await CountOLOutput(t);
                    await CheckResult(t);
                }
            });

            return(true);
        }