public static MnistLabels Read(string path) { Stream stream = File.OpenRead(path); if (path.EndsWith(".gz")) { stream = new GZipInputStream(stream); } using (var reader = new BinaryReader(stream)) { var magic = reader.ReadInt32BigEndian(); if (magic != 0x801) { throw new InvalidOperationException(); } var count = reader.ReadInt32BigEndian(); var result = new MnistLabels() { Count = count, Labels = new NDArray <byte>(new Shape(count)) }; for (var i = 0; i < count; i++) { result.Labels[i] = reader.ReadByte(); } return(result); } }
public static MnistDataset Read(string path) { return(new MnistDataset() { TrainingLabels = MnistLabels.Read(Path.Combine(path, "train-labels-idx1-ubyte.gz")), TrainingImages = MnistImages.Read(Path.Combine(path, "train-images-idx3-ubyte.gz")), TestLabels = MnistLabels.Read(Path.Combine(path, "t10k-labels-idx1-ubyte.gz")), TestImages = MnistImages.Read(Path.Combine(path, "t10k-images-idx3-ubyte.gz")), }); }