Download the data from Yann's website, unless it's already here.
(filename, work_directory)
| 9 | from six.moves import xrange # pylint: disable=redefined-builtin |
| 10 | SOURCE_URL = 'http://yann.lecun.com/exdb/mnist/' |
| 11 | def maybe_download(filename, work_directory): |
| 12 | """Download the data from Yann's website, unless it's already here.""" |
| 13 | if not os.path.exists(work_directory): |
| 14 | os.mkdir(work_directory) |
| 15 | filepath = os.path.join(work_directory, filename) |
| 16 | if not os.path.exists(filepath): |
| 17 | filepath, _ = urllib.request.urlretrieve(SOURCE_URL + filename, filepath) |
| 18 | statinfo = os.stat(filepath) |
| 19 | print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.') |
| 20 | return filepath |
| 21 | def _read32(bytestream): |
| 22 | dt = numpy.dtype(numpy.uint32).newbyteorder('>') |
| 23 | return numpy.frombuffer(bytestream.read(4), dtype=dt) |