Commit 4a36e31b authored by Asim Shankar's avatar Asim Shankar
Browse files

[mnist]: Incorporate comments in PR

parent 120526af
...@@ -21,6 +21,7 @@ import os ...@@ -21,6 +21,7 @@ import os
import shutil import shutil
import gzip import gzip
import numpy as np import numpy as np
from six.moves import urllib
import tensorflow as tf import tensorflow as tf
...@@ -56,7 +57,7 @@ def check_labels_file_header(filename): ...@@ -56,7 +57,7 @@ def check_labels_file_header(filename):
f.name)) f.name))
def maybe_download(directory, filename): def download(directory, filename):
"""Download (and unzip) a file from the MNIST dataset, if it doesn't already exist.""" """Download (and unzip) a file from the MNIST dataset, if it doesn't already exist."""
if not tf.gfile.Exists(directory): if not tf.gfile.Exists(directory):
tf.gfile.MakeDirs(directory) tf.gfile.MakeDirs(directory)
...@@ -65,19 +66,18 @@ def maybe_download(directory, filename): ...@@ -65,19 +66,18 @@ def maybe_download(directory, filename):
return filepath return filepath
# CVDF mirror of http://yann.lecun.com/exdb/mnist/ # CVDF mirror of http://yann.lecun.com/exdb/mnist/
url = 'https://storage.googleapis.com/cvdf-datasets/mnist/' + filename + '.gz' url = 'https://storage.googleapis.com/cvdf-datasets/mnist/' + filename + '.gz'
zipped_filename = filename + '.gz' zipped_filepath = filepath + '.gz'
zipped_filepath = os.path.join(directory, zipped_filename) print('Downloading %s to %s' % (url, zipped_filepath))
tf.contrib.learn.datasets.base.maybe_download(zipped_filename, directory, url) urllib.request.urlretrieve(url, zipped_filepath)
with gzip.open(os.path.join(zipped_filepath), 'rb') as f_in, open( with gzip.open(zipped_filepath, 'rb') as f_in, open(filepath, 'wb') as f_out:
filepath, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)
os.remove(zipped_filepath) os.remove(zipped_filepath)
return filepath return filepath
def dataset(directory, images_file, labels_file): def dataset(directory, images_file, labels_file):
images_file = maybe_download(directory, images_file) images_file = download(directory, images_file)
labels_file = maybe_download(directory, labels_file) labels_file = download(directory, labels_file)
check_image_file_header(images_file) check_image_file_header(images_file)
check_labels_file_header(labels_file) check_labels_file_header(labels_file)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment