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

            // バイト配列を分解する
            FileStream     stream = new FileStream(path, FileMode.Open);
            BinaryReaderBE reader = new BinaryReaderBE(stream);

            MNistImageLoader loader = new MNistImageLoader();

            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);
        }
Esempio n. 2
0
        public static MNistLabelLoader Load(string path)
        {
            if (File.Exists(path) == false)
            {
                return(null);
            }
            FileStream       stream = new FileStream(path, FileMode.Open);
            BinaryReaderBE   reader = new BinaryReaderBE(stream);
            MNistLabelLoader loader = new MNistLabelLoader();

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