oreilly-japan / deep-learning-from-scratch

『ゼロから作る Deep Learning』(O'Reilly Japan, 2016)
MIT License
3.95k stars 3.31k forks source link

解決方法:MNISTデータがHTTP Error 403: Forbiddenで読み込めない #81

Open matsuda-tkm opened 2 months ago

matsuda-tkm commented 2 months ago

実行環境

  • OS:macOS Sonoma 14.4.1
  • Python:3.12.3
  • パッケージ管理:Poetry (version 1.8.2)
  • 入っているライブラリ(poetry showの結果)
    • contourpy 1.2.1
    • cycler 0.12.1
    • fonttools 4.51.0
    • kiwisolver 1.4.5
    • matplotlib 3.8.4
    • numpy 1.26.4
    • packaging 24.0
    • pillow 10.3.0
    • pyparsing 3.1.2
    • python-dateutil 2.9.0.post0
    • six 1.16.0

問題の事象

ch03/neuralnet_mnist.pyを実行したところ、以下のようにurllib.error.HTTPError: HTTP Error 403: Forbiddenというエラーが発生し、MNISTデータをダウンロードできない。 また、ブラウザからダウンロード先のリンクへアクセスしても403 Forbiddenとなっている。

Downloading train-images-idx3-ubyte.gz ... 
Traceback (most recent call last):
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/neuralnet_mnist.py", line 35, in <module>
    x, t = get_data()
           ^^^^^^^^^^
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/neuralnet_mnist.py", line 11, in get_data
    (x_train, t_train), (x_test, t_test) = load_mnist(normalize=True, flatten=True, one_hot_label=False)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/../dataset/mnist.py", line 111, in load_mnist
    init_mnist()
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/../dataset/mnist.py", line 80, in init_mnist
    download_mnist()
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/../dataset/mnist.py", line 47, in download_mnist
    _download(v)
  File "/Users/takumi/github/deep-learning-from-scratch/ch03/../dataset/mnist.py", line 40, in _download
    response = urllib.request.urlopen(request).read()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

解決方法

解決にあたって参考にしたもの

@koki0702 お手数おかけしますが修正お願いいたします。

koki0702 commented 2 months ago

本家URLが403になっていたので、ミラーサイトに変更しました。 (PyTorchのコードを参考にしました)

https://github.com/oreilly-japan/deep-learning-from-scratch/commit/497a4ac8859dce7a3b4819edf695364afe73fcda