mnist_read 1.0.1

Reads generic data and label files in the MNIST file format.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 2 items with examples
  • Size
  • Source code size: 5.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.14 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • JonathanWoollett-Light/mnist_read
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JonathanWoollett-Light

MNIST Read

Crates.io lib.rs.io docs

Reads generic data and label files in the MNIST file format for Rust.

As simple as that.

// Raw format
let train_labels: Vec<u8> = mnist_read::read_labels("train-labels.idx1-ubyte");
let train_data: Vec<u8> = mnist_read::read_data("train-images.idx3-ubyte");

// Ndarray (Maths lib)
let usize_labels:Vec<usize> = train__labels.into_iter().map(|l|l as usize).collect();
let mut array_labels:ndarray::Array2<usize> = ndarray::Array::from_shape_vec((10000, 1), usize_labels).expect("Bad labels");

let f32_data:Vec<f32> = train_data.into_iter().map(|d|d as f32 / 255f32).collect();
let mut array_data:ndarray::Array2<f32> = ndarray::Array::from_shape_vec((10000, 28*28), f32_data).expect("Bad data");

// Cogent (Neural network library)
let mut net = cogent::NeuralNetwork::new(784,&[
    cogent::Layer::Dense(1000, cogent::Activation::ReLU),
    cogent::Layer::Dropout(0.2),
    cogent::Layer::Dense(500, cogent::Activation::ReLU),
    cogent::Layer::Dropout(0.2),
    cogent::Layer::Dense(10, cogent::Activation::Softmax)
])
net.train(&mut array_data, &mut array_labels).go()