2017-03-31 6 views
6

후 얘들 아, MNIST 데이터베이스를 가져올 수 없습니다 등는 아나콘다/jupyter 통해

내가 파이썬/아나콘다/jupyter/NumPy와, 팬더 새로운 해요 .... 그것은 정말 바보 같은 질문이 있다면 그래서 실례하시기 바랍니다. 아나콘다/jupyter를 사용하여 MNIST 데이터베이스를 얻으려고합니다. 하지만 매회 HTTP 오류 500이 발생합니다. 그것은 정말로 서버 문제입니까 (500이 제안하는 것처럼)입니까, 아니면 제가 잘못하고 있습니까? jupyter에서

입력 :

from sklearn.datasets import fetch_mldata 
mnist = fetch_mldata('MNIST original') 

결과 :

--------------------------------------------------------------------------- 
    HTTPError         Traceback (most recent call last) 
    <ipython-input-1-15dc285fb373> in <module>() 
      1 from sklearn.datasets import fetch_mldata 
    ----> 2 mnist = fetch_mldata('MNIST original') 

    e:\ProgramData\Anaconda3\lib\site-packages\sklearn\datasets\mldata.py in fetch_mldata(dataname, target_name, data_name, transpose_data, data_home) 
     140   urlname = MLDATA_BASE_URL % quote(dataname) 
     141   try: 
    --> 142    mldata_url = urlopen(urlname) 
     143   except HTTPError as e: 
     144    if e.code == 404: 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 
     221  else: 
     222   opener = _opener 
    --> 223  return opener.open(url, data, timeout) 
     224 
     225 def install_opener(opener): 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout) 
     530   for processor in self.process_response.get(protocol, []): 
     531    meth = getattr(processor, meth_name) 
    --> 532    response = meth(req, response) 
     533 
     534   return response 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in http_response(self, request, response) 
     640   if not (200 <= code < 300): 
     641    response = self.parent.error(
    --> 642     'http', request, response, code, msg, hdrs) 
     643 
     644   return response 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in error(self, proto, *args) 
     562    http_err = 0 
     563   args = (dict, proto, meth_name) + args 
    --> 564   result = self._call_chain(*args) 
     565   if result: 
     566    return result 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args) 
     502   for handler in handlers: 
     503    func = getattr(handler, meth_name) 
    --> 504    result = func(*args) 
     505    if result is not None: 
     506     return result 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in http_error_302(self, req, fp, code, msg, headers) 
     754   fp.close() 
     755 
    --> 756   return self.parent.open(new, timeout=req.timeout) 
     757 
     758  http_error_301 = http_error_303 = http_error_307 = http_error_302 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout) 
     530   for processor in self.process_response.get(protocol, []): 
     531    meth = getattr(processor, meth_name) 
    --> 532    response = meth(req, response) 
     533 
     534   return response 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in http_response(self, request, response) 
     640   if not (200 <= code < 300): 
     641    response = self.parent.error(
    --> 642     'http', request, response, code, msg, hdrs) 
     643 
     644   return response 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in error(self, proto, *args) 
     568   if http_err: 
     569    args = (dict, 'default', 'http_error_default') + orig_args 
    --> 570    return self._call_chain(*args) 
     571 
     572 # XXX probably also want an abstract factory that knows when it makes 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args) 
     502   for handler in handlers: 
     503    func = getattr(handler, meth_name) 
    --> 504    result = func(*args) 
     505    if result is not None: 
     506     return result 

    e:\ProgramData\Anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs) 
     648 class HTTPDefaultErrorHandler(BaseHandler): 
     649  def http_error_default(self, req, fp, code, msg, hdrs): 
    --> 650   raise HTTPError(req.full_url, code, msg, hdrs, fp) 
     651 
     652 class HTTPRedirectHandler(BaseHandler): 

    HTTPError: HTTP Error 500: INTERNAL SERVER ERROR 
+1

오류 메시지는 내부 서버 오류를 의미하는 HTTP 오류 500을 반환합니다. 따라서 대부분의 경우 서버에 오류가 있습니다. 나중에 다시 시도하겠습니다. ulr mldata.org를 확인하면 현재 사용할 수 없다는 것을 알 수 있습니다. – pafede2

답변

2

나는 또한 당신과 같은 오류가 발생합니다. 이 서버가 필요없는 몇 가지 가능한 솔루션을 소개합니다. 당신이 tensorflow가 설치되어있는 경우

, 당신은 다음과 같은 방법으로 MNIST 데이터를 얻을 수 있습니다 :

예를 len(m.train.images)에 대한 다음
import tensorflow.examples.tutorials.mnist.input_data as input_data 
m=input_data.read_data_sets("MNIST") 

는 55000.

당신이 tensorflow이없는 경우, 당신은이를 얻을 수 있습니다 here 지침을 사용하여 데이터 집합. https://github.com/Lasagne/Lasagne/blob/master/examples/mnist.py

그것은 얀 LeCun의 웹 사이트 (http://yann.lecun.com/exdb/mnist/)에서 데이터 집합을 다운로드 :

0

여기 (https://github.com/ageron/handson-ml/blob/master/03_classification.ipynb에서 참조)를 MNIST 데이터 세트 좋은 해결책이 여기

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!") 
0

을 다운로드 할 수있는 대체 위치입니다.

import os 
from urllib import urlretrieve 

def download(filename, source='http://yann.lecun.com/exdb/mnist/'): 
    print("Downloading %s" % filename) 
    urlretrieve(source + filename, filename) 

# We then define functions for loading MNIST images and labels. 
# For convenience, they also download the requested files if needed. 
import gzip 

def load_mnist_images(filename): 
    if not os.path.exists(filename): 
     download(filename) 
    # Read the inputs in Yann LeCun's binary format. 
    with gzip.open(filename, 'rb') as f: 
     data = np.frombuffer(f.read(), np.uint8, offset=16) 
    # The inputs are vectors now, we reshape them to monochrome 2D images, 
    # following the shape convention: (examples, channels, rows, columns) 
    data = data.reshape(-1, 1, 28, 28) 
    # The inputs come as bytes, we convert them to float32 in range [0,1]. 
    # (Actually to range [0, 255/256], for compatibility to the version 
    # provided at http://deeplearning.net/data/mnist/mnist.pkl.gz.) 
    return data/np.float32(256) 

def load_mnist_labels(filename): 
    if not os.path.exists(filename): 
     download(filename) 
    # Read the labels in Yann LeCun's binary format. 
    with gzip.open(filename, 'rb') as f: 
     data = np.frombuffer(f.read(), np.uint8, offset=8) 
    # The labels are vectors of integers now, that's exactly what we want. 
    return data 


X_train = load_mnist_images('train-images-idx3-ubyte.gz') 
y_train = load_mnist_labels('train-labels-idx1-ubyte.gz') 
X_test = load_mnist_images('t10k-images-idx3-ubyte.gz') 
y_test = load_mnist_labels('t10k-labels-idx1-ubyte.gz') 
2

나는 또한 동일한 오류가있어서 방화벽을 꺼야했습니다. Macbook에서 시스템 환경 설정> 보안 & 개인 정보> 방화벽> 방화벽 끄기로 이동하십시오.

2
from sklearn.datasets import fetch_mldata 
try: 
    mnist = fetch_mldata('MNIST original') 
except Exception as ex:   
    from six.moves import urllib 
    from scipy.io import loadmat 
    import os 

    mnist_path = os.path.join(".", "datasets", "mnist-original.mat") 

    # download dataset from github. 
    mnist_alternative_url = "https://github.com/amplab/datascience-sp14/raw/master/lab7/mldata/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("Done!") 
+0

이 답변은 모두 코드입니다. 설명을 추가하고 정보를 증폭하십시오. –

관련 문제