「ゼロから作るDeep Learning」のサンプルプログラム(MNIST)を動かす

なぜか

半年ほど前(夏の暑いころ)に衝動的に買いました。
誰かが絶賛していた記憶。

ゼロから作るDeep Learning ―Pythonで学ぶディープラーニングの理論と実装
斎藤 康毅
オライリージャパン
売り上げランキング: 308

ずっと放置していたので

大掃除からの現実逃避冬休みの自由研究的に。
雰囲気だけでもつかもうかなと。
さらっとサンプルプログラムを動かしつつ読み始めました。

サンプルプログラムはこちら。
https://github.com/oreilly-japan/deep-learning-from-scratch

3章の「手書き数字認識」まできました

ニューラルネットワークとかの基礎的な解説も終わり。
いよいよ手書き数字認識。

さっそくエラー

とりあえず実行してみたら出たエラー

1
2
3
4
5
C:\work\python>python c:/work/python/deep-learning-from-scratch-master/ch03/neuralnet_mnist.py
Traceback (most recent call last):
File "c:/work/python/deep-learning-from-scratch-master/ch03/neuralnet_mnist.py", line 6, in <module>
from dataset.mnist import load_mnist
ModuleNotFoundError: No module named 'dataset'

こういう、いかにも基本がなってないです系のエラーって。
初心者には厳しいですよね。(注:Python初心者です)

試行錯誤することなく、とりえあえずIssueを確認。

ありました。
https://github.com/oreilly-japan/deep-learning-from-scratch/issues/25

解決していなかった

さらにエラー

1
2
3
4
5
C:\work\python>python c:/work/python/deep-learning-from-scratch-master/ch03/mnist_show.py
Traceback (most recent call last):
File "c:/work/python/deep-learning-from-scratch-master/ch03/mnist_show.py", line 7, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'

これもIssueにあった。
https://github.com/oreilly-japan/deep-learning-from-scratch/issues/26

インストール

1
2
3
4
5
6
C:\work\python>pip3 install pillow
Collecting pillow
Downloading https://files.pythonhosted.org/packages/6c/60/4c0e6702a39eab8d5d4d210f283907cbe387fcffeb873d8eb8c3757a21a9/Pillow-5.3.0-cp36-cp36m-win32.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 3.3MB/s
Installing collected packages: pillow
Successfully installed pillow-5.3.0

できた

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
C:\work\python>python c:/work/python/deep-learning-from-scratch-master/ch03/mnist_show.py
Downloading train-images-idx3-ubyte.gz ...
Done
Downloading train-labels-idx1-ubyte.gz ...
Done
Downloading t10k-images-idx3-ubyte.gz ...
Done
Downloading t10k-labels-idx1-ubyte.gz ...
Done
Converting train-images-idx3-ubyte.gz to NumPy Array ...
Done
Converting train-labels-idx1-ubyte.gz to NumPy Array ...
Done
Converting t10k-images-idx3-ubyte.gz to NumPy Array ...
Done
Converting t10k-labels-idx1-ubyte.gz to NumPy Array ...
Done
Creating pickle file ...
Done!
5
(784,)
(28, 28)

Issueにあげてくれた方、ありがとうございました。

続きは

読み進められるかは不明

続きをやろうとしたら発見した

フォルダを移動して実行しなきゃいけなかったらしい。
https://github.com/oreilly-japan/deep-learning-from-scratch#%E5%AE%9F%E8%A1%8C%E6%96%B9%E6%B3%95

README.md

1
2
3
4
5
$ cd ch01
$ python man.py

$ cd ../ch05
$ python train_nueralnet.py

ちゃんと移動して実行したら、パスとか直さなくて大丈夫でした。
なーんだ。(ありがち)