Skip to content

Commit 3ed4831

Browse files
authored
Merge pull request #21 from pytorch/float
Fixes for inconsistency between / in Python 2 and 3
2 parents 5c39840 + 0786bae commit 3ed4831

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

torchvision/transforms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __call__(self, pic):
4141
return img.float().div(255)
4242

4343
class ToPILImage(object):
44-
""" Converts a torch.*Tensor of range [0, 1] and shape C x H x W
44+
""" Converts a torch.*Tensor of range [0, 1] and shape C x H x W
4545
or numpy ndarray of dtype=uint8, range[0, 255] and shape H x W x C
4646
to a PIL.Image of range [0, 255]
4747
"""
@@ -111,8 +111,8 @@ def __init__(self, size):
111111
def __call__(self, img):
112112
w, h = img.size
113113
th, tw = self.size
114-
x1 = int(round((w - tw) / 2))
115-
y1 = int(round((h - th) / 2))
114+
x1 = int(round((w - tw) / 2.))
115+
y1 = int(round((h - th) / 2.))
116116
return img.crop((x1, y1, x1 + tw, y1 + th))
117117

118118

@@ -187,7 +187,7 @@ def __call__(self, img):
187187
for attempt in range(10):
188188
area = img.size[0] * img.size[1]
189189
target_area = random.uniform(0.08, 1.0) * area
190-
aspect_ratio = random.uniform(3 / 4, 4 / 3)
190+
aspect_ratio = random.uniform(3. / 4, 4. / 3)
191191

192192
w = int(round(math.sqrt(target_area * aspect_ratio)))
193193
h = int(round(math.sqrt(target_area / aspect_ratio)))

0 commit comments

Comments
 (0)