1. 程式人生 > >Mnist資料集匯入出錯解決方案

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資料集匯入成功,並能夠成功執行。

執行過程如上圖所示。