forked from keras-team/keras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fashion mnist dataset (keras-team#7809)
* fixed typo * added fashion-mnist dataset * added docs * pep8 * grammer * use offset instead of struct * reshape as in docs
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
from . import cifar10 | ||
from . import cifar100 | ||
from . import boston_housing | ||
from . import fashion_mnist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import gzip | ||
import os | ||
|
||
from ..utils.data_utils import get_file | ||
import numpy as np | ||
|
||
|
||
def load_data(): | ||
"""Loads the Fashion-MNIST dataset. | ||
# Returns | ||
Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`. | ||
""" | ||
dirname = os.path.join('datasets', 'fashion-mnist') | ||
base = 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/' | ||
files = ['train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz', | ||
't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz'] | ||
|
||
paths = [] | ||
for file in files: | ||
paths.append(get_file(file, origin=base + file, cache_subdir=dirname)) | ||
|
||
with gzip.open(paths[0], 'rb') as lbpath: | ||
y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8) | ||
|
||
with gzip.open(paths[1], 'rb') as imgpath: | ||
x_train = np.frombuffer(imgpath.read(), np.uint8, | ||
offset=16).reshape(len(y_train), 28, 28) | ||
|
||
with gzip.open(paths[2], 'rb') as lbpath: | ||
y_test = np.frombuffer(lbpath.read(), np.uint8, offset=8) | ||
|
||
with gzip.open(paths[3], 'rb') as imgpath: | ||
x_test = np.frombuffer(imgpath.read(), np.uint8, | ||
offset=16).reshape(len(y_test), 28, 28) | ||
|
||
return (x_train, y_train), (x_test, y_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters