Keras导入Mnist数据集出错解决方案

Mnist数据集导入出错

在进行Mnist手写识别的项目中,出现了Mnist数据集下载出错的问题,报出以下错误:

Exception: URL fetch failure on https://s3.amazonaws.com/img-datasets/mnist.npz: None -- [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

解决方案如下:

在浏览器输入网址https://s3.amazonaws.com/img-datasets/mnist.npz,下载minst.npz数据集,保存到某个文件夹下,在这里,我保存到了"F:\Anaconda"下,然后进入minst.load_data(),将代码改成如下:

def load_data():
    """Loads the 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)`.
        """
    path='F://Anaconda//mnist.npz'
    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)

即可将mnist数据集导入成功,并能够成功运行。

运行过程如上图所示。

猜你喜欢

转载自blog.csdn.net/qq_37587850/article/details/83574615
今日推荐