https://github.com/fillassuncao/denser-models
Revision 7a5e8c0dcf94a6caa46505c9ab63e163f51870ca authored by Filipe Assunção on 01 June 2018, 09:01:29 UTC, committed by Filipe Assunção on 01 June 2018, 09:01:29 UTC
1 parent cddaee3
Tip revision: 7a5e8c0dcf94a6caa46505c9ab63e163f51870ca authored by Filipe Assunção on 01 June 2018, 09:01:29 UTC
update readme
update readme
Tip revision: 7a5e8c0
fashion_mnist.py
import sys
if sys.version_info >= (3,0):
import urllib.request
else:
import urllib
import gzip
import idx2numpy
def load_data():
"""Loads the Fashion MNIST dataset.
# Arguments
path: path where to cache the dataset locally
(relative to ~/.keras/datasets).
# Returns
Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.
"""
if sys.version_info >= (3,0):
path_x_train = urllib.request.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz', 'train-images-idx3-ubyte.gz')
path_y_train = urllib.request.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz', 'train-labels-idx1-ubyte.gz')
path_x_test = urllib.request.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz', 't10k-images-idx3-ubyte.gz')
path_y_test = urllib.request.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz', 't10k-labels-idx1-ubyte.gz')
else:
path_x_train = urllib.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz', 'train-images-idx3-ubyte.gz')
path_y_train = urllib.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz', 'train-labels-idx1-ubyte.gz')
path_x_test = urllib.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz', 't10k-images-idx3-ubyte.gz')
path_y_test = urllib.urlretrieve('http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz', 't10k-labels-idx1-ubyte.gz')
with gzip.open('train-images-idx3-ubyte.gz', 'rb') as f:
x_train = idx2numpy.convert_from_string(f.read())
with gzip.open('train-labels-idx1-ubyte.gz', 'rb') as f:
y_train = idx2numpy.convert_from_string(f.read())
with gzip.open('t10k-images-idx3-ubyte.gz', 'rb') as f:
x_test = idx2numpy.convert_from_string(f.read())
with gzip.open('t10k-labels-idx1-ubyte.gz', 'rb') as f:
y_test = idx2numpy.convert_from_string(f.read())
return (x_train, y_train), (x_test, y_test)
Computing file changes ...