Esempio n. 1
0
        /// <summary>
        /// MNIST のラベルファイルをロードする.
        /// 失敗した時は null を返す.
        /// </summary>
        /// <param name="path">ラベルファイルのパス.</param>
        /// <returns></returns>
        public static MnistLabelLoader Load(string path)
        {
            // ファイルが存在しない
            if (File.Exists(path) == false)
            {
                return(null);
            }

            MnistLabelLoader loader = new MnistLabelLoader();

            using (FileStream inStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (GZipStream decompStream = new GZipStream(inStream, CompressionMode.Decompress))
                {
                    // バイト配列を分解する
                    BinaryReaderBE reader = new BinaryReaderBE(decompStream);

                    loader.magicNumber   = reader.ReadInt32();
                    loader.numberOfItems = reader.ReadInt32();
                    loader.labelList     = reader.ReadBytes(loader.numberOfItems);

                    reader.Close();
                }

            return(loader);
        }
Esempio n. 2
0
        ///<summary>
        ///Load MNIST data.
        ///If it fails, it returns null.
        ///</summary>
        ///<param name = "path"> Image data path. </param>
        ///<returns> </returns>
        public static MnistImageLoader Load(string path)
        {
            //File does not exist
            if (File.Exists(path) == false)
            {
                return(null);
            }

            MnistImageLoader loader = new MnistImageLoader();

            //Decompose byte array
            using (FileStream inStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (GZipStream decompStream = new GZipStream(inStream, CompressionMode.Decompress))
                {
                    BinaryReaderBE reader = new BinaryReaderBE(decompStream);

                    loader.magicNumber     = reader.ReadInt32();
                    loader.numberOfImages  = reader.ReadInt32();
                    loader.numberOfRows    = reader.ReadInt32();
                    loader.numberOfColumns = reader.ReadInt32();

                    int pixelCount = loader.numberOfRows * loader.numberOfColumns;
                    for (int i = 0; i < loader.numberOfImages; i++)
                    {
                        byte[] pixels = reader.ReadBytes(pixelCount);
                        loader.bitmapList.Add(pixels);
                    }

                    reader.Close();
                }

            return(loader);
        }