快捷方式

MNIST

class torchvision.datasets.MNIST(root: Union[str, Path], train: bool = True, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False)[源代码]

MNIST 数据集。

参数:
  • root (str or pathlib.Path) – 数据集的根目录,其中包含 MNIST/raw/train-images-idx3-ubyteMNIST/raw/t10k-images-idx3-ubyte

  • train (bool, optional) – 如果为 True,则从 train-images-idx3-ubyte 创建数据集,否则从 t10k-images-idx3-ubyte 创建。

  • transform (callable, optional) – 一个函数/转换,它接收一个 PIL 图像并返回一个转换后的版本。例如,transforms.RandomCrop

  • target_transform (callable, optional) – 一个函数/转换,它接收目标并对其进行转换。

  • download (bool, optional) – 如果为 True,则从互联网下载数据集并将其放入根目录。如果数据集已下载,则不会再次下载。

特殊成员:

__getitem__(index: int) Tuple[Any, Any][源代码]
参数:

index (int) – 索引

返回:

(图像, 目标),其中目标是目标类别的索引。

返回类型:

元组

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并解答您的疑问

查看资源