Skip to content

Commit 75297f4

Browse files
fix(optimization_tutorial): replace deprecated ToTensor with v2 transforms (#3870)
Fixes #3854 ## Description - Replace deprecated `torchvision.transforms.ToTensor()` with `v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])` in `beginner_source/basics/optimization_tutorial.py` - Aligns the tutorial with the supported torchvision v2 transforms API (ToTensor deprecated since torchvision 0.16) ## 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 - [x] 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 @svekars Co-authored-by: sekyondaMeta <127536312+sekyondaMeta@users.noreply.github.com>
1 parent 58d1185 commit 75297f4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

beginner_source/basics/optimization_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
from torch import nn
2929
from torch.utils.data import DataLoader
3030
from torchvision import datasets
31-
from torchvision.transforms import ToTensor
31+
from torchvision.transforms import v2
3232

3333
training_data = datasets.FashionMNIST(
3434
root="data",
3535
train=True,
3636
download=True,
37-
transform=ToTensor()
37+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
3838
)
3939

4040
test_data = datasets.FashionMNIST(
4141
root="data",
4242
train=False,
4343
download=True,
44-
transform=ToTensor()
44+
transform=v2.Compose([v2.ToImage(), v2.ToDtype(torch.float32, scale=True)])
4545
)
4646

4747
train_dataloader = DataLoader(training_data, batch_size=64)

0 commit comments

Comments
 (0)