Struct mnist::MnistBuilder

source ·
pub struct MnistBuilder<'a> { /* private fields */ }
Expand description

Struct used for configuring how to load the MNIST data.

  • lbl_format - Specify how to format the label vectors. Options include:
    • Digit (default) - a single number from 0-9 representing the corresponding digit.
    • OneHotVector - a 1x10 one-hot vector of all 0’s except for a 1 at the index of the digit.
      • ex.) 3 -> [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
  • trn_len - the length of the training set (default = 60,000)
  • val_len - the length of the validation set (default = 0)
  • tst_len - the length of the test set (default = 10,000)
  • base_path - the path to the directory in which to look for the MNIST data files. (default = "data/")
  • trn_img_filename - the filename of the training images data file. (default = "train-images-idx3-ubyte")
  • trn_lbl_filename - the filename of the training labels data file. (default = "train-labels-idx1-ubyte")
  • tst_img_filename - the filename of the test images data file. (default = "10k-images-idx3-ubyte")
  • tst_lbl_filename - the filename of the test labels data file. (default = "t10k-labels-idx1-ubyte")

Implementations§

source§

impl<'a> MnistBuilder<'a>

source

pub fn new() -> MnistBuilder<'a>

Create a new MnistBuilder with defaults set.

Examples
let mnist = MnistBuilder::new()
   .finalize();
source

pub fn label_format_digit(&mut self) -> &mut MnistBuilder<'a>

Set the labels format to scalar.

Examples
let mnist = MnistBuilder::new()
    .label_format_digit()
    .finalize();
source

pub fn label_format_one_hot(&mut self) -> &mut MnistBuilder<'a>

Set the labels format to vector.

Examples
let mnist = MnistBuilder::new()
    .label_format_one_hot()
    .finalize();
source

pub fn training_set_length(&mut self, length: u32) -> &mut MnistBuilder<'a>

Set the training set length.

Examples
let mnist = MnistBuilder::new()
    .training_set_length(40_000)
    .finalize();
source

pub fn validation_set_length(&mut self, length: u32) -> &mut MnistBuilder<'a>

Set the validation set length.

Examples
let mnist = MnistBuilder::new()
    .validation_set_length(10_000)
    .finalize();
source

pub fn test_set_length(&mut self, length: u32) -> &mut MnistBuilder<'a>

Set the test set length.

Examples
let mnist = MnistBuilder::new()
    .test_set_length(10_000)
    .finalize();
source

pub fn base_path(&mut self, base_path: &'a str) -> &mut MnistBuilder<'a>

Set the base path to look for the MNIST data files.

Examples
let mnist = MnistBuilder::new()
    .base_path("data_sets/mnist")
    .finalize();
source

pub fn training_images_filename( &mut self, trn_img_filename: &'a str ) -> &mut MnistBuilder<'a>

Set the training images data set filename.

Examples
let mnist = MnistBuilder::new()
    .training_images_filename("training_images")
    .finalize();
source

pub fn training_labels_filename( &mut self, trn_lbl_filename: &'a str ) -> &mut MnistBuilder<'a>

Set the training labels data set filename.

Examples
let mnist = MnistBuilder::new()
    .training_labels_filename("training_labels")
    .finalize();
source

pub fn test_images_filename( &mut self, tst_img_filename: &'a str ) -> &mut MnistBuilder<'a>

Set the test images data set filename.

Examples
let mnist = MnistBuilder::new()
    .test_images_filename("test_images")
    .finalize();
source

pub fn test_labels_filename( &mut self, tst_lbl_filename: &'a str ) -> &mut MnistBuilder<'a>

Set the test labels data set filename.

Examples
let mnist = MnistBuilder::new()
    .test_labels_filename("test_labels")
    .finalize();
source

pub fn download_and_extract(&mut self) -> &mut MnistBuilder<'a>

Download and extract MNIST dataset if not present.

If archives are already present, they will not be downloaded.

If datasets are already present, they will not be extracted.

Note that this requires the ‘download’ feature to be enabled (disabled by default).

Examples
let mnist = MnistBuilder::new()
    .download_and_extract()
    .finalize();
source

pub fn use_fashion_data(&mut self) -> &mut MnistBuilder<'a>

Uses the Fashion MNIST dataset rather than the original

Examples
let mnist = MnistBuilder::new()
    .use_fashion_data()
    .finalize();
source

pub fn base_url(&mut self, base_url: &'a str) -> &mut MnistBuilder<'a>

Download the .gz files from the specified url rather than the standard one

Examples
let mnist = MnistBuilder::new()
    .base_url("<desired_url_here>")
    .download_and_extract()
    .finalize();
source

pub fn finalize(&self) -> Mnist

Get the data according to the specified configuration.

Examples
let mnist = MnistBuilder::new()
    .finalize();
Panics

If trn_len + val_len + tst_len > 70,000.

Trait Implementations§

source§

impl<'a> Debug for MnistBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MnistBuilder<'_>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for MnistBuilder<'a>

§

impl<'a> Send for MnistBuilder<'a>

§

impl<'a> Sync for MnistBuilder<'a>

§

impl<'a> Unpin for MnistBuilder<'a>

§

impl<'a> UnwindSafe for MnistBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.