MNIST
A crate for parsing the MNIST and Fashion MNIST data set into vectors to be
used by Rust programs.
Example
extern crate mnist;
extern crate rulinalg;
use mnist::{Mnist, MnistBuilder};
use rulinalg::matrix::{BaseMatrix, BaseMatrixMut, Matrix};
fn main() {
let (trn_size, rows, cols) = (50_000, 28, 28);
let Mnist { trn_img, trn_lbl, .. } = MnistBuilder::new()
.label_format_digit()
.training_set_length(trn_size)
.validation_set_length(10_000)
.test_set_length(10_000)
.finalize();
let first_label = trn_lbl[0];
println!("The first digit is a {}.", first_label);
let trn_img = Matrix::new((trn_size * rows) as usize, cols as usize, trn_img);
let row_indexes = (0..27).collect::<Vec<_>>();
let first_image = trn_img.select_rows(&row_indexes);
println!("The image looks like... \n{}", first_image);
let trn_img: Matrix<f32> = trn_img.try_into().unwrap() / 255.0;
let first_image = trn_img.select_rows(&row_indexes)
.apply(&|p| (p * 10.0).round() / 10.0);
println!("The image looks like... \n{}", first_image);
}
Fashion MNIST
The Fasion MNIST dataset offers a similarly-formatted
drop-in replacement dataset for the original MNIST set, but typically poses a more difficult classification challenge that handwritten numbers.
An example of downloading this dataset may be found by running:
$ cargo run --features download --example fashion_mnist
This example uses the minifb library to display the parsed images,
and may require the installation of certain dependencies. On an Ubuntu-like system, this may be done via:
$ sudo apt install libxkbcommon-dev libwayland-cursor0 libwayland-dev