项目作者: davidMcneil

项目描述 :
MNIST data set parser https://crates.io/crates/mnist
高级语言: Rust
项目地址: git://github.com/davidMcneil/mnist.git
创建时间: 2017-01-16T13:28:35Z
项目社区:https://github.com/davidMcneil/mnist

开源协议:

下载


MNIST

A crate for parsing the MNIST and Fashion MNIST data set into vectors to be
used by Rust programs.

Example

  1. use mnist::*;
  2. use ndarray::prelude::*;
  3. fn main() {
  4. // Deconstruct the returned Mnist struct.
  5. let Mnist {
  6. trn_img,
  7. trn_lbl,
  8. tst_img,
  9. tst_lbl,
  10. ..
  11. } = MnistBuilder::new()
  12. .label_format_digit()
  13. .training_set_length(50_000)
  14. .validation_set_length(10_000)
  15. .test_set_length(10_000)
  16. .finalize();
  17. let image_num = 0;
  18. // Can use an Array2 or Array3 here (Array3 for visualization)
  19. let train_data = Array3::from_shape_vec((50_000, 28, 28), trn_img)
  20. .expect("Error converting images to Array3 struct")
  21. .map(|x| *x as f32 / 256.0);
  22. println!("{:#.1?}\n",train_data.slice(s![image_num, .., ..]));
  23. // Convert the returned Mnist struct to Array2 format
  24. let train_labels: Array2<f32> = Array2::from_shape_vec((50_000, 1), trn_lbl)
  25. .expect("Error converting training labels to Array2 struct")
  26. .map(|x| *x as f32);
  27. println!("The first digit is a {:?}",train_labels.slice(s![image_num, ..]) );
  28. let _test_data = Array3::from_shape_vec((10_000, 28, 28), tst_img)
  29. .expect("Error converting images to Array3 struct")
  30. .map(|x| *x as f32 / 256.);
  31. let _test_labels: Array2<f32> = Array2::from_shape_vec((10_000, 1), tst_lbl)
  32. .expect("Error converting testing labels to Array2 struct")
  33. .map(|x| *x as f32);
  34. }

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:

  1. $ cargo run --features download --example fashion_mnist