Description
The Training with PyTorch tutorial uses deprecated torchvision transforms, Python 2-style super(), and old string formatting throughout.
Changes needed
Deprecated APIs
transforms.ToTensor() → v2.ToImage() + v2.ToDtype(torch.float32, scale=True): ToTensor() is deprecated since torchvision 0.18 and lives in torchvision.transforms._deprecated.py. Update Compose and Normalize to v2 namespace as well.
Outdated patterns
- Python 2-style
super(GarmentClassifier, self).__init__() → super().__init__()
.format() → f-strings (9 instances):
'Training set has {} instances'.format(...)
'Validation set has {} instances'.format(...)
'Total loss for this batch: {}'.format(...)
' batch {} loss: {}'.format(...)
'runs/fashion_trainer_{}'.format(timestamp)
'EPOCH {}:'.format(...)
'LOSS train {} valid {}'.format(...)
'model_{}_{}'.format(...)
Files
cc @subramen
Description
The Training with PyTorch tutorial uses deprecated torchvision transforms, Python 2-style
super(), and old string formatting throughout.Changes needed
Deprecated APIs
transforms.ToTensor()→v2.ToImage() + v2.ToDtype(torch.float32, scale=True):ToTensor()is deprecated since torchvision 0.18 and lives intorchvision.transforms._deprecated.py. UpdateComposeandNormalizeto v2 namespace as well.Outdated patterns
super(GarmentClassifier, self).__init__()→super().__init__().format()→ f-strings (9 instances):'Training set has {} instances'.format(...)'Validation set has {} instances'.format(...)'Total loss for this batch: {}'.format(...)' batch {} loss: {}'.format(...)'runs/fashion_trainer_{}'.format(timestamp)'EPOCH {}:'.format(...)'LOSS train {} valid {}'.format(...)'model_{}_{}'.format(...)Files
beginner_source/introyt/trainingyt.pycc @subramen