8
8
import types
9
9
10
10
class Compose (object ):
11
- """ Composes several transforms together.
12
- For example:
13
- >>> transforms.Compose([
14
- >>> transforms.CenterCrop(10),
15
- >>> transforms.ToTensor(),
16
- >>> ])
11
+ """Composes several transforms together.
12
+
13
+ Args:
14
+ transforms (List[Transform]): list of transforms to compose.
15
+
16
+ Example:
17
+ >>> transforms.Compose([
18
+ >>> transforms.CenterCrop(10),
19
+ >>> transforms.ToTensor(),
20
+ >>> ])
17
21
"""
18
22
def __init__ (self , transforms ):
19
23
self .transforms = transforms
@@ -25,8 +29,9 @@ def __call__(self, img):
25
29
26
30
27
31
class ToTensor (object ):
28
- """ Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range [0, 255]
29
- to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] """
32
+ """Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range
33
+ [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0].
34
+ """
30
35
def __call__ (self , pic ):
31
36
if isinstance (pic , np .ndarray ):
32
37
# handle numpy array
@@ -40,8 +45,9 @@ def __call__(self, pic):
40
45
img = img .transpose (0 , 1 ).transpose (0 , 2 ).contiguous ()
41
46
return img .float ().div (255 )
42
47
48
+
43
49
class ToPILImage (object ):
44
- """ Converts a torch.*Tensor of range [0, 1] and shape C x H x W
50
+ """Converts a torch.*Tensor of range [0, 1] and shape C x H x W
45
51
or numpy ndarray of dtype=uint8, range[0, 255] and shape H x W x C
46
52
to a PIL.Image of range [0, 255]
47
53
"""
@@ -56,7 +62,7 @@ def __call__(self, pic):
56
62
return img
57
63
58
64
class Normalize (object ):
59
- """ Given mean: (R, G, B) and std: (R, G, B),
65
+ """Given mean: (R, G, B) and std: (R, G, B),
60
66
will normalize each channel of the torch.*Tensor, i.e.
61
67
channel = (channel - mean) / std
62
68
"""
@@ -72,7 +78,7 @@ def __call__(self, tensor):
72
78
73
79
74
80
class Scale (object ):
75
- """ Rescales the input PIL.Image to the given 'size'.
81
+ """Rescales the input PIL.Image to the given 'size'.
76
82
'size' will be the size of the smaller edge.
77
83
For example, if height > width, then image will be
78
84
rescaled to (size * height / width, size)
@@ -128,7 +134,7 @@ def __call__(self, img):
128
134
return ImageOps .expand (img , border = self .padding , fill = self .fill )
129
135
130
136
class Lambda (object ):
131
- """Applies a lambda as a transform"""
137
+ """Applies a lambda as a transform. """
132
138
def __init__ (self , lambd ):
133
139
assert type (lambd ) is types .LambdaType
134
140
self .lambd = lambd
0 commit comments