Skip to content

Mnist

MNISTDataModule #

Bases: ImageClassificationDataModule

.. figure:: https://miro.medium.com/max/744/1*AO2rIhzRYzFVQlFLx9DM9A.png :width: 400 :alt: MNIST

Specs
  • 10 classes (1 per digit)
  • Each image is (1 x 28 x 28)

Standard MNIST, train, val, test splits and transforms

Transforms::

mnist_transforms = transform_lib.Compose([
    transform_lib.ToTensor()
])

Example::

from pl_bolts.datamodules import MNISTDataModule

dm = MNISTDataModule('.')
model = LitModel()

Trainer().fit(model, datamodule=dm)

__init__ #

__init__(
    data_dir: str | None = None,
    val_split: int | float = 0.2,
    num_workers: int | None = 0,
    normalize: bool = False,
    batch_size: int = 32,
    seed: int = 42,
    shuffle: bool = True,
    pin_memory: bool = True,
    drop_last: bool = False,
    *args: Any,
    **kwargs: Any
) -> None

Parameters:

Name Type Description Default
data_dir str | None

Where to save/load the data

None
val_split int | float

Percent (float) or number (int) of samples to use for the validation split

0.2
num_workers int | None

How many workers to use for loading data

0
normalize bool

If true applies image normalize

False
batch_size int

How many samples per batch to load

32
seed int

Random seed to be used for train/val/test splits

42
shuffle bool

If true shuffles the train data every epoch

True
pin_memory bool

If true, the data loader will copy Tensors into CUDA pinned memory before returning them

True
drop_last bool

If true drops the last incomplete batch

False