mnist_dataset {torchvision}R Documentation

MNIST and Derived Datasets

Description

Prepares various MNIST-style image classification datasets and optionally downloads them. Images are thumbnails images of 28 x 28 pixels of grayscale values encoded as integer.

Usage

mnist_dataset(
  root = tempdir(),
  train = TRUE,
  transform = NULL,
  target_transform = NULL,
  download = FALSE
)

kmnist_dataset(
  root = tempdir(),
  train = TRUE,
  transform = NULL,
  target_transform = NULL,
  download = FALSE
)

qmnist_dataset(
  root = tempdir(),
  split = "train",
  transform = NULL,
  target_transform = NULL,
  download = FALSE
)

fashion_mnist_dataset(
  root = tempdir(),
  train = TRUE,
  transform = NULL,
  target_transform = NULL,
  download = FALSE
)

emnist_dataset(
  root = tempdir(),
  split = "balanced",
  transform = NULL,
  target_transform = NULL,
  download = FALSE
)

Arguments

root

Root directory for dataset storage. The dataset will be stored under ⁠root/<dataset-name>⁠. Defaults to tempdir().

train

Logical. If TRUE, use the training set; otherwise, use the test set. Not applicable to all datasets.

transform

Optional. A function that takes an image and returns a transformed version (e.g., normalization, cropping).

target_transform

Optional. A function that transforms the label.

download

Logical. If TRUE, downloads the dataset to ⁠root/⁠. If the dataset is already present, download is skipped.

split

Character. Used in emnist_dataset() and qmnist_dataset() to specify the subset. See individual descriptions for valid values.

Details

Value

A torch dataset object, where each items is a list of x (image) and y (label).

Functions

Supported Splits for emnist_dataset()

Supported Splits for qmnist_dataset()

See Also

Other classification_dataset: caltech_dataset, cifar10_dataset(), eurosat_dataset(), fer_dataset(), fgvc_aircraft_dataset(), flowers102_dataset(), oxfordiiitpet_dataset(), tiny_imagenet_dataset()

Examples

## Not run: 
ds <- mnist_dataset(download = TRUE)
item <- ds[1]
item$x  # image
item$y  # label

qmnist <- qmnist_dataset(split = "train", download = TRUE)
item <- qmnist[1]
item$x
item$y

emnist <- emnist_dataset(split = "balanced", download = TRUE)
item <- emnist[1]
item$x
item$y

kmnist <- kmnist_dataset(download = TRUE)
fmnist <- fashion_mnist_dataset(download = TRUE)

## End(Not run)


[Package torchvision version 0.7.0 Index]