Crate mnist_reader

Source
Expand description

§MNIST data reader

This module provides a reader for the MNIST dataset. It downloads the dataset from GitHub if it is not already present in the specified directory. It also provides methods to load the data into memory.

You can easily download and use the MNIST data as shown below.

use mnist_reader::{MnistReader, print_image};
fn main() {
   // read MNIST data
    let mut mnist = MnistReader::new("mnist-data");
   // download MNIST data
    mnist.load().unwrap();
    // print the size of the data
    println!("Train data size: {}", mnist.train_data.len());
    println!("Test data size: {}", mnist.test_data.len());
    println!("Train labels size: {}", mnist.train_labels.len());
    println!("Test labels size: {}", mnist.test_labels.len());
    // print the first image
    let train_data: Vec<Vec<f32>> = mnist.train_data;
    println!("images[0]={:?}", train_data[0]);
    print_image(&train_data[0]);
    // print the first label
    let train_labels: Vec<u8> = mnist.train_labels;
    println!("labels[0]={:?}", train_labels[0]);
}

Structs§

MnistReader
MNIST data reader This struct is used to read MNIST data from the given directory. It downloads the data files if they are not already present in the directory. It also provides methods to load the data into memory.

Functions§

print_image
print MNIST image data
read_gzip
read from gzip file to memory
ungzip
ungzip a file