You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I downloaded the dataset from a source and placing it in an arbitrary path.
And I found some people having trouble in loading the dataset from a local path using tensorflow 2.0.
The API tf.keras.datasets.fashion_mnist.load_data() seems not support loading data locally.
I write a new function that may help to solve this issue. I hope that this function could help somebody in need.
I don`t know whether the issue is big enough for a pull request. So I open an issue here and post my code here. Hope that I won't cause any inconvenience.
The code of new function:
importosimportnumpyasnpimportgzipdefload_data_fromlocalpath(input_path):
"""Loads the Fashion-MNIST dataset. Modified by Henry Huang in 2020/12/24. We assume that the input_path should in a correct path address format. We also assume that potential users put all the four files in the path. Load local data from path ‘input_path’. Returns: Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`. """files= [
'train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz',
't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz'
]
paths= []
forfnameinfiles:
paths.append(os.path.join(input_path, fname)) # The location of the dataset.withgzip.open(paths[0], 'rb') aslbpath:
y_train=np.frombuffer(lbpath.read(), np.uint8, offset=8)
withgzip.open(paths[1], 'rb') asimgpath:
x_train=np.frombuffer(
imgpath.read(), np.uint8, offset=16).reshape(len(y_train), 28, 28)
withgzip.open(paths[2], 'rb') aslbpath:
y_test=np.frombuffer(lbpath.read(), np.uint8, offset=8)
withgzip.open(paths[3], 'rb') asimgpath:
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)
I downloaded the dataset from a source and placing it in an arbitrary path.
And I found some people having trouble in loading the dataset from a local path using tensorflow 2.0.
The API tf.keras.datasets.fashion_mnist.load_data() seems not support loading data locally.
I write a new function that may help to solve this issue. I hope that this function could help somebody in need.
I don`t know whether the issue is big enough for a pull request. So I open an issue here and post my code here. Hope that I won't cause any inconvenience.
The code of new function:
When calling this function:
The text was updated successfully, but these errors were encountered: