本地加载mnist数据集的方法:
在学习keras的过程中需要联网下载mnist,而总是在下载一半时出现连接错误
报错:ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
解决方法:
step1:下载mnist数据集到本地
百度网盘链接:https://pan.baidu.com/s/1mZo8weNMGfpW7L4EHWNymg
step2:上代码加载
def load_mnist():
path = r'C:\Users\Administrator\Desktop\study\mnist.npz' #放置mnist.py的目录。注意斜杠
f = np.load(path)
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
f.close()
return (x_train, y_train), (x_test, y_test)
(train_image,train_label),(test_image,test_label) = load_mnist()
大功告成!
本地测试: