Commit 58d1185
Modernize transforms tutorial to torchvision v2 API (#3861)
Fixes #3853
## Description
files changed - `beginner_source/basics/transforms_tutorial.py`
1. Replaced deprecated `torchvision.transforms.ToTensor` (deprecated
since torchvision 0.16) with the v2 pipeline `v2.Compose([v2.ToImage(),
v2.ToDtype(torch.float32, scale=True)])`.
2. Switched the legacy v1 `transforms` namespace import to `from
torchvision.transforms import v2`.
3. Replaced the low-level `torch.zeros(...).scatter_(...)` one-hot
pattern with `torch.nn.functional.one_hot(torch.tensor(y),
num_classes=10).float()`, wrapped in `v2.Lambda`.
4. Updated the section heading and explanatory prose so they describe
`v2.ToImage()` + `v2.ToDtype()` and `F.one_hot` instead of `ToTensor`
and `scatter_`.
## 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 08435cc commit 58d1185
1 file changed
Lines changed: 22 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
38 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | | - | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | | - | |
61 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
70 | | - | |
| 75 | + | |
| 76 | + | |
0 commit comments