Example #1
0
        public static CIFARImageBW FromCIFARImage(CIFARImage orig)
        {
            CIFARImageBW result = new CIFARImageBW(orig.Label, orig.Width, orig.Height);
            for (int i = 0; i < result.PixelData.Length; ++i)
            {
                result.PixelData[i] = (orig.PixelData[i] + orig.PixelData[i + 1024] + orig.PixelData[i + 2048]) / 3.0;
            }

            return result;
        }
Example #2
0
        public static CIFARImageBW FromCIFARImage(CIFARImage orig, int channel)
        {
            if (channel < 0 || channel > 2)
                throw new Exception("Channel != 1, 2, or 3");

            CIFARImageBW result = new CIFARImageBW(orig.Label, orig.Width, orig.Height );
            for (int i = 0; i < result.PixelData.Length; ++i)
            {
                result.PixelData[i] = (orig.PixelData[i + 1024 * channel]);
            }
            return result;
        }
Example #3
0
File: IO.cs Project: KBrus/nton-rbm
        /// <summary>
        /// Zbior uczacy, zbior testowy
        /// </summary>
        public static Tuple<List<CIFARImage>, List<CIFARImage>> Read()
        {
            if (!Directory.Exists(DataFolder))
                throw new IOException("Unable to find DataFolder.");

            Console.WriteLine("Reading files");

            BinaryReader br = null;
            List<CIFARImage> DataTrain = new List<CIFARImage>(), DataTest = new List<CIFARImage>();
            int[] classCountTrain = new int[10], classCountTest = new int[10];

            // train data
            for (int i = 1; i <= 5; ++i)
            {
                br = new BinaryReader(File.OpenRead(DataFolder + @"\data_batch_" + i + ".bin"));
                for (int j = 0; j < 10000; ++j)
                {
                    CIFARImage img = new CIFARImage();
                    img.Label = br.ReadByte();
                    img.PixelData = br.ReadBytes(3072);

                    DataTrain.Add(img);
                    ++classCountTrain[img.Label];
                }
                br.Close();
                Console.WriteLine("Finished reading {0}", i);
            }

            Console.WriteLine("Read training data, [{0}]", string.Join(",", classCountTrain));

            // test data
            br = new BinaryReader(File.OpenRead(DataFolder + @"\test_batch.bin"));
            for (int j = 0; j < 10000; ++j)
            {
                CIFARImage img = new CIFARImage();
                img.Label = br.ReadByte();
                img.PixelData = br.ReadBytes(3072);

                DataTest.Add(img);

                ++classCountTest[img.Label];
            }
            br.Close();
            Console.WriteLine("Read test data,     [{0}]", string.Join(",", classCountTest));

            //Console.WriteLine("Processing");
            //TransformBArrToImage(DataTrain);
            //TransformBArrToImage(DataTest);

            return new Tuple<List<CIFARImage>, List<CIFARImage>>(DataTrain, DataTest);
        }
Example #4
0
File: IO.cs Project: KBrus/nton-rbm
        public static void SavePicture2(CIFARImage image, string path)
        {
            if (image.Image == null)
                throw new Exception("Image not transformed");

            image.Image.Save(path, System.Drawing.Imaging.ImageFormat.Png);
        }
Example #5
0
File: IO.cs Project: KBrus/nton-rbm
        public static void SavePicture(CIFARImage image, string path)
        {
            Bitmap bm = new Bitmap(32, 32);
            var data = image.PixelData;

            for (int x = 0; x < image.Height; ++x)
            {
                for (int y = 0; y < image.Width; ++y)
                {
                    bm.SetPixel(y, x, Color.FromArgb(data[x * 32 + y], data[x * 32 + y + 1024], data[x * 32 + y + 2048]));
                }
            }

            bm.Save(path, System.Drawing.Imaging.ImageFormat.Png);
        }