def _maybe_download():
  """Downloads the MNIST dataset if it is not there already."""
  data_url = 'http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz'
  filename = data_url.split('/')[-1]
  filepath = os.path.join(_get_data_dir(), filename)
  if not os.path.exists(filepath):

    def _progress(count, block_size, total_size):
      print('\r>> Downloading %s %.1f%%' %
            (filename, float(count * block_size) / float(total_size) * 100.0))

    filepath, _ = urllib.urlretrieve(data_url, filepath, _progress)
    statinfo = os.stat(filepath)
    print('Successfully downloaded %s %d bytes.' % (filename, statinfo.st_size))
  else:
    print('Data already present on disk.')
  return filepath
Downloads the MNIST dataset if it is not there already.
trax/tf_numpy/examples/mnist/dataset.py