Skip to content

Commit c4c9042

Browse files
ajaechfacebook-github-bot
authored andcommitted
simplify read_image_file and read_label_file functions (#2476)
Summary: Pull Request resolved: #2476 I simplified the read_image_file and read_label_file functions to make it easier to adapt this code to use it with other file systems that aren't compatible with the simple open command. Reviewed By: fmassa Differential Revision: D22530585 fbshipit-source-id: 0dd20f917c947d1ec1eae23474c251ceea85f427
1 parent df93114 commit c4c9042

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

torchvision/datasets/mnist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,14 @@ def read_sn3_pascalvincent_tensor(path, strict=True):
470470

471471

472472
def read_label_file(path):
473-
with open(path, 'rb') as f:
474-
x = read_sn3_pascalvincent_tensor(f, strict=False)
473+
x = read_sn3_pascalvincent_tensor(path, strict=False)
475474
assert(x.dtype == torch.uint8)
476475
assert(x.ndimension() == 1)
477476
return x.long()
478477

479478

480479
def read_image_file(path):
481-
with open(path, 'rb') as f:
482-
x = read_sn3_pascalvincent_tensor(f, strict=False)
480+
x = read_sn3_pascalvincent_tensor(path, strict=False)
483481
assert(x.dtype == torch.uint8)
484482
assert(x.ndimension() == 3)
485483
return x

0 commit comments

Comments
 (0)