torchvision.datasets.
时间: 2023-10-14 17:11:37 浏览: 113
The `torchvision.datasets` module provides a collection of popular datasets like CIFAR-10, CIFAR-100, MNIST, ImageNet and many more. These datasets can be used for training and testing various deep learning models.
The module provides a simple API to download and load these datasets. The datasets are returned as a subclass of `torch.utils.data.Dataset` and can be used with `torch.utils.data.DataLoader` to create a dataloader for training and testing.
Example usage:
```
import torchvision.datasets as datasets
# Download and load the CIFAR-10 dataset
train_dataset = datasets.CIFAR10(root='./data', train=True, download=True, transform=None)
# Create a dataloader for training
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=32, shuffle=True)
```
In this example, we download the CIFAR-10 dataset and create a dataloader for training with a batch size of 32 and shuffling the data. The `transform` parameter can be used to apply transforms to the data, such as resizing, cropping, and normalization.
阅读全文