Cannot get MNIST database through Anaconda/jupyter

前端 未结 9 2578
情歌与酒
情歌与酒 2021-02-13 14:20

Hu guys,

I\'m new to python/anaconda/jupyter/numPy, panda, etc.... so please excuse me if it\'s a really stupid question. I\'m trying to obtain MNIST database by using a

9条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 14:55

    Here is an alternative location to download the MNIST dataset (referenced from https://github.com/ageron/handson-ml/blob/master/03_classification.ipynb)

    from six.moves import urllib
    from sklearn.datasets import fetch_mldata
    try:
        mnist = fetch_mldata('MNIST original')
    except urllib.error.HTTPError as ex:
        print("Could not download MNIST data from mldata.org, trying alternative...")
    
        # Alternative method to load MNIST, if mldata.org is down
        from scipy.io import loadmat
        mnist_alternative_url = "https://github.com/amplab/datascience-sp14/raw/master/lab7/mldata/mnist-original.mat"
        mnist_path = "./mnist-original.mat"
        response = urllib.request.urlopen(mnist_alternative_url)
        with open(mnist_path, "wb") as f:
            content = response.read()
            f.write(content)
        mnist_raw = loadmat(mnist_path)
        mnist = {
            "data": mnist_raw["data"].T,
            "target": mnist_raw["label"][0],
            "COL_NAMES": ["label", "data"],
            "DESCR": "mldata.org dataset: mnist-original",
        }
        print("Success!")
    

提交回复
热议问题