주피터 노트북에서 데이터셋을 import하는 중의 오류(밑바닥부터 시작하는 딥러닝)

2024.12.29 17:01 109 Views

밑바닥부터 시작하는 딥러닝 책 1권, 3.6 손글씨 숫자 인식 부분을 주피터 노트북으로 따라하고 있습니다

스크린샷 2024-12-28 오후 11.45.49.png

딥러닝 파일에서 따라 하고 있고 mnist 데이터 셋을 이렇게 저장해서 아래와 같이 실행했습니다.

이런 식으로 입력했고 아래와 같은 오류가 떴습니다.

Downloading train-images-idx3-ubyte.gz ... 
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/var/folders/79/d4_6x4wx1xnfg9kn_7_km__h0000gn/T/ipykernel_8179/3746115192.py in <module>
      3 from mnist import load_mnist
      4 
----> 5 (x_train,t_train),(x_test,t_test) = load_mnist(flatten=True,normalize=False)
      6 
      7 print(x_train.shape)

~/mnist.py in load_mnist(normalize, flatten, one_hot_label)

~/mnist.py in init_mnist()

~/mnist.py in download_mnist()

~/mnist.py in _download(file_name)

~/opt/anaconda3/lib/python3.9/urllib/request.py in urlretrieve(url, filename, reporthook, data)
    237     url_type, path = _splittype(url)
    238 
--> 239     with contextlib.closing(urlopen(url, data)) as fp:
    240         headers = fp.info()
    241 

~/opt/anaconda3/lib/python3.9/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    212     else:
    213         opener = _opener
--> 214     return opener.open(url, data, timeout)
    215 
    216 def install_opener(opener):

~/opt/anaconda3/lib/python3.9/urllib/request.py in open(self, fullurl, data, timeout)
    521         for processor in self.process_response.get(protocol, []):
    522             meth = getattr(processor, meth_name)
--> 523             response = meth(req, response)
    524 
    525         return response

~/opt/anaconda3/lib/python3.9/urllib/request.py in http_response(self, request, response)
    630         # request was successfully received, understood, and accepted.
    631         if not (200 <= code < 300):
--> 632             response = self.parent.error(
    633                 'http', request, response, code, msg, hdrs)
    634 

~/opt/anaconda3/lib/python3.9/urllib/request.py in error(self, proto, *args)
    553             http_err = 0
    554         args = (dict, proto, meth_name) + args
--> 555         result = self._call_chain(*args)
    556         if result:
    557             return result

~/opt/anaconda3/lib/python3.9/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    492         for handler in handlers:
    493             func = getattr(handler, meth_name)
--> 494             result = func(*args)
    495             if result is not None:
    496                 return result

~/opt/anaconda3/lib/python3.9/urllib/request.py in http_error_302(self, req, fp, code, msg, headers)
    745         fp.close()
    746 
--> 747         return self.parent.open(new, timeout=req.timeout)
    748 
    749     http_error_301 = http_error_303 = http_error_307 = http_error_302

~/opt/anaconda3/lib/python3.9/urllib/request.py in open(self, fullurl, data, timeout)
    521         for processor in self.process_response.get(protocol, []):
    522             meth = getattr(processor, meth_name)
--> 523             response = meth(req, response)
    524 
    525         return response

~/opt/anaconda3/lib/python3.9/urllib/request.py in http_response(self, request, response)
    630         # request was successfully received, understood, and accepted.
    631         if not (200 <= code < 300):
--> 632             response = self.parent.error(
    633                 'http', request, response, code, msg, hdrs)
    634 

~/opt/anaconda3/lib/python3.9/urllib/request.py in error(self, proto, *args)
    559         if http_err:
    560             args = (dict, 'default', 'http_error_default') + orig_args
--> 561             return self._call_chain(*args)
    562 
    563 # XXX probably also want an abstract factory that knows when it makes

~/opt/anaconda3/lib/python3.9/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    492         for handler in handlers:
    493             func = getattr(handler, meth_name)
--> 494             result = func(*args)
    495             if result is not None:
    496                 return result

~/opt/anaconda3/lib/python3.9/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    639 class HTTPDefaultErrorHandler(BaseHandler):
    640     def http_error_default(self, req, fp, code, msg, hdrs):
--> 641         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    642 
    643 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden

인터넷을 찾아보면 권한 수락 오류라고 뜨기도 하는데 어떻게 해결해야할 지 모르겠습니다. 도움주시면 감사하겠습니다.

로그인이 필요합니다
0 / 1000
정연사랑
2024.12.30 13:47

안녕하세요.

maryyu 님이 공유해주신 HTTP Error 403: Forbidden 오류는 MNIST 데이터셋 다운로드 과정에서 발생한 문제처럼 보이네요,
어떠한 이유로 님의 로컬 환경이 네트워크 접근 제한되었는지 정확히 알 수는 없으나, 

제가 시도한 방법은  O'Reilly Japan의 Deep Learning from Scratch 깃허브 저장소에서 제공하는 mnist.py 파일을 사용하는 것입니다: 
https://github.com/oreilly-japan/deep-learning-from-scratch/blob/master/dataset/mnist.py

* 위 링크에서 mnist.py 파일을 다운로드
* 작업 중인 주피터 노트북과 같은 디렉토리에 저장
* 코드 실행

이렇게 하면 기존 코드를 수정하지 않고도 정상적으로 MNIST 데이터를 불러올 수 있습니다.

도움이 되셨길 바랍니다!

겔겔
2024.12.30 13:56

http://yann.lecun.com/exdb/mnist
파일 자체는 위 링크에서 다운받을 수 있습니다.
403이 발생하는걸로 봐선 방화벽 문제일 가능성도 있어보입니다.

이전 글
시계열 데이터 관련 공부
Competition -
Likes 4
Views 97
Comments 2
17일 전
현재 글
주피터 노트북에서 데이터셋을 import하는 중의 오류(밑바닥부터 시작하는 딥러닝)
Competition -
Likes 4
Views 109
Comments 2
19일 전
다음 글
AI 공부를 하고 싶은데, 조언을 구합니다.
Competition -
Likes 6
Views 131
Comments 3
21일 전