Skip to content

Commit 51bdefb

Browse files
Modernize data tutorial to torchvision v2 API (#3863)
Fixes ##3852 ## Description Replace deprecated ToTensor() with v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)]) in both the training and test FashionMNIST splits, and switch the import to the v2 namespace. ## Checklist <!--- Make sure to add `x` to all items in the following checklist: --> - [x] The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER") - [x] Only one issue is addressed in this pull request - [ ] Labels from the issue that this PR is fixing are added to this pull request - [x] No unnecessary issues are included into this pull request. cc @subramen Co-authored-by: sekyondaMeta <127536312+sekyondaMeta@users.noreply.github.com>
1 parent 75297f4 commit 51bdefb

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

beginner_source/basics/data_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@
4848
import torch
4949
from torch.utils.data import Dataset
5050
from torchvision import datasets
51-
from torchvision.transforms import ToTensor
51+
from torchvision.transforms import v2
5252
import matplotlib.pyplot as plt
5353

5454

5555
training_data = datasets.FashionMNIST(
5656
root="data",
5757
train=True,
5858
download=True,
59-
transform=ToTensor()
59+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
6060
)
6161

6262
test_data = datasets.FashionMNIST(
6363
root="data",
6464
train=False,
6565
download=True,
66-
transform=ToTensor()
66+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
6767
)
6868

6969

0 commit comments

Comments
 (0)