From 2d558a107a2e3ae3a689998000c63f52e83d3cc4 Mon Sep 17 00:00:00 2001 From: Aaron Jaech Date: Wed, 15 Jul 2020 08:55:06 -0700 Subject: [PATCH] simplify read_image_file and read_label_file functions Summary: 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. Differential Revision: D22530585 fbshipit-source-id: 0e19b344b37a70fb8cee39b701d041f65cb9516b --- torchvision/datasets/mnist.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/torchvision/datasets/mnist.py b/torchvision/datasets/mnist.py index 3b9db53a9ff..357b1c6312d 100644 --- a/torchvision/datasets/mnist.py +++ b/torchvision/datasets/mnist.py @@ -470,16 +470,14 @@ def read_sn3_pascalvincent_tensor(path, strict=True): def read_label_file(path): - with open(path, 'rb') as f: - x = read_sn3_pascalvincent_tensor(f, strict=False) + x = read_sn3_pascalvincent_tensor(path, strict=False) assert(x.dtype == torch.uint8) assert(x.ndimension() == 1) return x.long() def read_image_file(path): - with open(path, 'rb') as f: - x = read_sn3_pascalvincent_tensor(f, strict=False) + x = read_sn3_pascalvincent_tensor(path, strict=False) assert(x.dtype == torch.uint8) assert(x.ndimension() == 3) return x