Difference between transform & target_transform in pytorch?
Context:
Every TorchVision Dataset includes two arguments: transform and target_transform to modify the samples and labels respectively.
If you look at the source code, particularly the __getitem__
method for any of the torchvision Dataset classes, e.g., torchvision.datasets.DatasetFolder, you can see that transform and target_transform are used to modify / augment / transform the image and the target respectively.
Examples where this might be useful include object detection and semantic segmentation, where if you apply a translation / rotation / shear / scale / crop on the source image, you would also want corresponding transforms on the bounding boxes / segmentation masks.
As an additional example, you can take a look at this official tutorial where target_transform
is used to convert integer class labels to one-hot format for image classification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With