From 434271dc5b9d2cb8d1188c8436977b46c388a20c Mon Sep 17 00:00:00 2001 From: Adam Paszke Date: Thu, 19 Jan 2017 23:11:25 +0100 Subject: [PATCH 1/2] Remove print in MNIST dataset --- torchvision/datasets/mnist.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/torchvision/datasets/mnist.py b/torchvision/datasets/mnist.py index 04506691924..820a41ac654 100644 --- a/torchvision/datasets/mnist.py +++ b/torchvision/datasets/mnist.py @@ -72,7 +72,6 @@ def download(self): import gzip if self._check_exists(): - print('Files already downloaded') return # download files @@ -98,8 +97,8 @@ def download(self): os.unlink(file_path) # process and save as torch files - print('Processing') - + print('Processing...') + training_set = ( read_image_file(os.path.join(self.root, self.raw_folder, 'train-images-idx3-ubyte')), read_label_file(os.path.join(self.root, self.raw_folder, 'train-labels-idx1-ubyte')) From 72cd478ec9f36715ba1a5380787bc62cf8a067b2 Mon Sep 17 00:00:00 2001 From: Adam Paszke Date: Thu, 19 Jan 2017 23:11:32 +0100 Subject: [PATCH 2/2] Minor doc fixes --- torchvision/transforms.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/torchvision/transforms.py b/torchvision/transforms.py index 2be81389c2c..68ce23a1b1a 100644 --- a/torchvision/transforms.py +++ b/torchvision/transforms.py @@ -8,12 +8,16 @@ import types class Compose(object): - """ Composes several transforms together. - For example: - >>> transforms.Compose([ - >>> transforms.CenterCrop(10), - >>> transforms.ToTensor(), - >>> ]) + """Composes several transforms together. + + Args: + transforms (List[Transform]): list of transforms to compose. + + Example: + >>> transforms.Compose([ + >>> transforms.CenterCrop(10), + >>> transforms.ToTensor(), + >>> ]) """ def __init__(self, transforms): self.transforms = transforms @@ -25,8 +29,9 @@ def __call__(self, img): class ToTensor(object): - """ Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range [0, 255] - to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] """ + """Converts a PIL.Image (RGB) or numpy.ndarray (H x W x C) in the range + [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0]. + """ def __call__(self, pic): if isinstance(pic, np.ndarray): # handle numpy array @@ -40,8 +45,9 @@ def __call__(self, pic): img = img.transpose(0, 1).transpose(0, 2).contiguous() return img.float().div(255) + class ToPILImage(object): - """ Converts a torch.*Tensor of range [0, 1] and shape C x H x W + """Converts a torch.*Tensor of range [0, 1] and shape C x H x W or numpy ndarray of dtype=uint8, range[0, 255] and shape H x W x C to a PIL.Image of range [0, 255] """ @@ -56,7 +62,7 @@ def __call__(self, pic): return img class Normalize(object): - """ Given mean: (R, G, B) and std: (R, G, B), + """Given mean: (R, G, B) and std: (R, G, B), will normalize each channel of the torch.*Tensor, i.e. channel = (channel - mean) / std """ @@ -72,7 +78,7 @@ def __call__(self, tensor): class Scale(object): - """ Rescales the input PIL.Image to the given 'size'. + """Rescales the input PIL.Image to the given 'size'. 'size' will be the size of the smaller edge. For example, if height > width, then image will be rescaled to (size * height / width, size) @@ -128,7 +134,7 @@ def __call__(self, img): return ImageOps.expand(img, border=self.padding, fill=self.fill) class Lambda(object): - """Applies a lambda as a transform""" + """Applies a lambda as a transform.""" def __init__(self, lambd): assert type(lambd) is types.LambdaType self.lambd = lambd