環境
Mac OS Sierra
本の解説は Windows のようなので、適宜読み替える
Chapter2
python 環境の準備
python 3.6.0 を使うようなので、
$ brew install pyenv
.zshrc に下記を追記。
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init -)"
$ brew install pyenv-virtualenv
.zshrc に下記を追記。
eval "$(pyenv virtualenv-init -)"
$ pyenv install 3.6.0
$ pyenv local 3.6.0
$ pyenv rehash
これはやってもやらんでも。
$ pyenv virtualenv 3.6.0 TensorFlow
$ pyenv rehash
TensorFlow 環境の準備
TensorFlow インストール。本書は 1.5.0。pip3 にしておいた。
$ pip3 install --upgrade tensorflow==1.5.0
...
Successfully installed absl-py-0.2.2 bleach-1.5.0 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.5 protobuf-3.5.2.post1 setuptools-39.2.0 six-1.11.0 tensorflow-1.5.0 tensorflow-tensorboard-1.5.1 werkzeug-0.14.1 wheel-0.31.1
なお、pip 古かったらしいけど、一旦放置。
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
動作確認。
$ python
Python 3.6.0 (default, Jun 5 2018, 09:00:55)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.5.0'
>>>
Jupyter Notebook インストール。
$ pip3 install jupyter
...
Successfully installed MarkupSafe-1.0 Send2Trash-1.5.0 appnope-0.1.0 backcall-0.1.0 decorator-4.3.0 entrypoints-0.2.3 ipykernel-4.8.2 ipython-6.4.0 ipython-genutils-0.2.0 ipywidgets-7.2.1 jedi-0.12.0 jinja2-2.10 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.2.3 jupyter-console-5.2.0 jupyter-core-4.4.0 mistune-0.8.3 nbconvert-5.3.1 nbformat-4.4.0 notebook-5.5.0 pandocfilters-1.4.2 parso-0.2.1 pexpect-4.6.0 pickleshare-0.7.4 prompt-toolkit-1.0.15 ptyprocess-0.5.2 pygments-2.2.0 python-dateutil-2.7.3 pyzmq-17.0.0 qtconsole-4.3.1 simplegeneric-0.8.1 terminado-0.8.1 testpath-0.3.1 tornado-5.0.2 traitlets-4.3.2 wcwidth-0.1.7 widgetsnbextension-3.2.1
動作確認。
$ jupyter notebook
サンプルで利用しているライブラリ群も同様にインストール。特に version 指定はしなかった。(ので、微妙に本書とは version 違う)
$ pip3 install h5py
...
Successfully installed h5py-2.8.0
$ pip3 install matplotlib
...
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.2 pyparsing-2.2.0 pytz-2018.4
OpenCV は…だめだった。
$ pip3 install opencv
Collecting opencv
Could not find a version that satisfies the requirement opencv (from versions: )
No matching distribution found for opencv
非公式らしいけど、こっちで。
$ pip3 install opencv-python
...
Successfully installed opencv-python-3.4.1.15
$ pip3 install pillow
...
Successfully installed pillow-5.1.0
$ pip3 install pandas
...
Successfully installed pandas-0.23.0
$ pip3 install scipy
...
Successfully installed scipy-1.1.0
Chapter3
The optional feed_dict argument allows the caller to override the value of tensors in the graph.
tensorboard でエラー。
$ tensorboard --logdir=logs
...
locale.Error: unsupported locale setting
stack trace 的に、下記で失敗している様子。
locale.setlocale(locale.LC_ALL, '')
見た感じ、設定されてそうだけどなー。pyenv とか使ってる影響?
$ locale
LANG="en_US.utf8"
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL="C"
よくわからないけど、locale 指定してあげたら動いた。
$ export LC_ALL=C
$ pip3 install keras
...
Successfully installed keras-2.2.0 keras-applications-1.0.2 keras-preprocessing-1.0.1 pyyaml-3.12
セルの添字がバラバラで気になるときは、Kernel > Restart
すれば OK。
Chapter4
-
活性化関数
-
ステップ関数
-
シグモイド関数
-
全結合層
-
全ての入力が全てのニューロンと結合している層。
-
Dense
-
出力次元 64 って数字はどう決めたのだろう?
-
validation_split
-
https://www.tensorflow.org/versions/r1.4/api_docs/python/tf/keras/models/Sequential
-
これで指定された量のデータが検証用データとして用いられるご様子
validation_split: float (0. < x < 1). Fraction of the data to use as held-out validation data.
- acc
- 分類精度
- 基本的には高くなっていく
- val_acc は検証用データに対する分類精度
- loss
- 損失関数
- 基本的には低くなっていく
- val_loss は検証用データに対する損失関数
Chapter5
略語多い…
- MLP
-
- Multi Layer Perceptron
- CNN
- Convolutional Neural Network
- よく聞くやつ、畳み込みニューラルネットワーク
- 畳み込み層
- カーネル=フィルタ
- 画像の特徴量を抽出
- 入力データのサイズが大きくなっても、結果的にカーネルのサイズになる
- プーリング層
- 画像を縮小するような層だと思ってれば OK
- ドロップアウト層
- 敢えてデータを落として学習させることで頑健性を高める
- 頑健性
- がんけんせい
- robustness
- 全結合層では、2次元のテンソルしか入力に受け取ることが出来ないので、Flatten レイヤーを追加して、多次元のテンソルを 2 次元のテンソルに展開する
- TensorBoard を確認する方法おさらい
$ tensorboard --logdir=logs
Chapter6
-
VGG16 のモデルのサマリを見ると、入力層のサイズが 224×224、出力層のサイズが 1000 になっている。これは、224×224 の1枚の入力画像に対して、1000 クラスそれぞれの分類確率を出力することを示している。
-
1000 クラスに含まれていない画像の分類を行いたい場合は、転移学習を行う。
-
転移学習=学習モデルを利用して、別のタスクに適用すること。
-
Dense って何だっけ…。
-
6.3.7 以降で使う utils は、サンプルプログラムに含まれている。パスが通っていないでエラーになる場合、こうすれば動作する。
-
もちろん パスに追加しても OK。
import sys
sys.path.append('samples/chap6')
Chapter7
(随時更新)