- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
*Memos:
- explains target_transform and transform & target_transform.
- explains transforms and transform & target_transform & transforms.
There are the differences between transform, target_transform and transforms as shown below. *It's about origin and transform:
*Memos:
- transform is for the function which must have one parameter for transform. *, , , etc also can be used.
- target_transform is for the function which must have one parameter for target(label).
- transforms is for the function which must have two parameters for both transform and target(label). *, , , etc also can be used.
- Both transform and target_transform can be used at the same time.
- transforms cannot be used with transform and/or target_transform at the same time.
- According to my experiments, target_transform and transforms are useless.
from torchvision.datasets import OxfordIIITPet
origin_data = OxfordIIITPet(
root="data"
)
origin_data[0]
# (<PIL.Image.Image image mode=RGB size=394x500>, 0)
origin_data[50]
# (<PIL.Image.Image image mode=RGB size=500x333>, 1)
origin_data[100]
# (<PIL.Image.Image image mode=RGB size=333x500>, 2)
transform:
from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import Resize
tfresize100_50_data = OxfordIIITPet(
root="data",
transform=Resize(size=[100, 50])
)
tfresize100_50_data[0]
# (<PIL.Image.Image image mode=RGB size=50x100>, 0)
tfresize100_50_data[50]
# (<PIL.Image.Image image mode=RGB size=50x100>, 1)
tfresize100_50_data[100]
# (<PIL.Image.Image image mode=RGB size=50x100>, 2)
from torchvision.datasets import OxfordIIITPet
def tf_func(transform):
return transform
tf_func_data = OxfordIIITPet(
root="data",
transform=tf_func
# transform=lambda transform: transform
)
tf_func_data[0]
# (<PIL.Image.Image image mode=RGB size=394x500>, 0)
tf_func_data[50]
# (<PIL.Image.Image image mode=RGB size=500x333>, 1)
tf_func_data[100]
# (<PIL.Image.Image image mode=RGB size=333x500>, 2)
from torchvision.datasets import OxfordIIITPet
def tf_func(transform):
return "Hello"
tf_func_data = OxfordIIITPet(
root="data",
transform=tf_func
# transform=lambda transform: "Hello"
)
tf_func_data[0]
# ('Hello', 0)
tf_func_data[50]
# ('Hello', 1)
tf_func_data[100]
# ('Hello', 2)
from torchvision.datasets import OxfordIIITPet
def tf_func():
return "Hello"
tf_func_data = OxfordIIITPet(
root="data",
transform=tf_func
# transform=lambda: "Hello"
)
tf_func_data[0]
# TypeError: tf_func() takes 0 positional arguments but 1 was given
from torchvision.datasets import OxfordIIITPet
def tf_func(transform, target):
return "Hello"
tf_func_data = OxfordIIITPet(
root="data",
transform=tf_func
# transform=lambda transform, target: "Hello"
)
tf_func_data[0]
# TypeError: tf_func() missing 1 required positional argument: 'target'