Skip to content

Commit 6f342d3

Browse files
authored
Merge pull request #33 from pytorch/improvements
Minor improvements
2 parents 9896626 + 72cd478 commit 6f342d3

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

torchvision/datasets/mnist.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def download(self):
7272
import gzip
7373

7474
if self._check_exists():
75-
print('Files already downloaded')
7675
return
7776

7877
# download files
@@ -98,8 +97,8 @@ def download(self):
9897
os.unlink(file_path)
9998

10099
# process and save as torch files
101-
print('Processing')
102-
100+
print('Processing...')
101+
103102
training_set = (
104103
read_image_file(os.path.join(self.root, self.raw_folder, 'train-images-idx3-ubyte')),
105104
read_label_file(os.path.join(self.root, self.raw_folder, 'train-labels-idx1-ubyte'))

torchvision/transforms.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
import types
99

1010
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+
>>> ])
1721
"""
1822
def __init__(self, transforms):
1923
self.transforms = transforms
@@ -25,8 +29,9 @@ def __call__(self, img):
2529

2630

2731
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+
"""
3035
def __call__(self, pic):
3136
if isinstance(pic, np.ndarray):
3237
# handle numpy array
@@ -40,8 +45,9 @@ def __call__(self, pic):
4045
img = img.transpose(0, 1).transpose(0, 2).contiguous()
4146
return img.float().div(255)
4247

48+
4349
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
4551
or numpy ndarray of dtype=uint8, range[0, 255] and shape H x W x C
4652
to a PIL.Image of range [0, 255]
4753
"""
@@ -56,7 +62,7 @@ def __call__(self, pic):
5662
return img
5763

5864
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),
6066
will normalize each channel of the torch.*Tensor, i.e.
6167
channel = (channel - mean) / std
6268
"""
@@ -72,7 +78,7 @@ def __call__(self, tensor):
7278

7379

7480
class Scale(object):
75-
""" Rescales the input PIL.Image to the given 'size'.
81+
"""Rescales the input PIL.Image to the given 'size'.
7682
'size' will be the size of the smaller edge.
7783
For example, if height > width, then image will be
7884
rescaled to (size * height / width, size)
@@ -128,7 +134,7 @@ def __call__(self, img):
128134
return ImageOps.expand(img, border=self.padding, fill=self.fill)
129135

130136
class Lambda(object):
131-
"""Applies a lambda as a transform"""
137+
"""Applies a lambda as a transform."""
132138
def __init__(self, lambd):
133139
assert type(lambd) is types.LambdaType
134140
self.lambd = lambd

0 commit comments

Comments
 (0)