def load_data(path,files):
import gzip
import numpy as np
paths = [path+ each for each in files ]
with gzip.open(paths[0], 'rb') as lbpath:
train_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)
with gzip.open(paths[1], 'rb') as impath:
train_images = np.frombuffer(impath.read(), np.uint8, offset=16).reshape(len(train_labels),28,28)
with gzip.open(paths[2], 'rb') as lbpath:
test_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)
with gzip.open(paths[3], 'rb') as impath:
test_images = np.frombuffer(impath.read(), np.uint8, offset=16).reshape(len(test_labels), 28, 28)
return (train_labels,train_images), (test_labels,test_images)
path = 'dataset/fashion-mnist/'
files = ['train-labels-idx1-ubyte.gz','train-images-idx3-ubyte.gz', 't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz']
(train_label, train_image), (test_label, test_image) = load_data(path, files)
print(train_image.shape)
https://blog.csdn.net/weixin_39441762/article/details/86026024