LoginSignup
1
0

dockerで機械学習(18) with anaconda(18)「Deep Learning with Keras」 Antonio Gulli, Sujit Pal著

Last updated at Posted at 2018-10-19

1.すぐに利用したい方へ(as soon as)

ごめんなさい。
現在、作業中です。下の方に示すエラーがでていて、悪戦苦闘中です。

「Deep Learning with Keras」 Antonio Gulli, Sujit Pal著

cat-4.gif
http://shop.oreilly.com/product/0636920163886.do

docker

dockerを導入し、Windows, Macではdockerを起動しておいてください。
Windowsでは、BiosでIntel Virtualizationをenableにしないとdockerが起動しない場合があります。
また、セキュリティの警告などが出ることがあります。

docker pull and run

$ docker pull kaizenjapan/anaconda-antonio

$ docker run -it -p 8888:8888 kaizenjapan/anaconda-antonio /bin/bash

以下のshell sessionでは
(base) root@f19e2f06eabb:/#は入力促進記号(comman prompt)です。実際には数字の部分が違うかもしれません。この行の#の右側を入力してください。
それ以外の行は出力です。出力にエラー、違いがあれば、コメント欄などでご連絡くださると幸いです。
それぞれの章のフォルダに移動します。

dockerの中と、dockerを起動したOSのシェルとが表示が似ている場合には、どちらで捜査しているか間違えることがあります。dockerの入力促進記号(comman prompt)に気をつけてください。

ファイル共有または複写

dockerとdockerを起動したOSでは、ファイル共有をするか、ファイル複写するかして、生成したファイルをブラウザ等表示させてください。参考文献欄にやり方のURLを記載しています。

複写の場合は、dockerを起動したOS側コマンドを実行しました。お使いのdockerの番号で置き換えてください。複写したファイルをブラウザで表示し内容確認しました。

(base) root@ed6304aaed64:/# ls
bin  boot  deep-learning-with-keras-ja	dev  etc  home	kerasBook  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var
(base) root@ed6304aaed64:/# cd kerasBook/
(base) root@ed6304aaed64:/kerasBook# ls
Keras_Adversarial  cifar10_architecture.json  keras_Azure.py			     keras_LeNet.py	keras_MINST_V6.py		 model.png
MNIST_data	   cifar10_weights.h5	      keras_CIFAR10_V1.py		     keras_MINST.py	keras_MINST_V7.py		 model_MLP_toy_classification.png
READ.ME		   data			      keras_CIFAR10_V2.py		     keras_MINST_V1.py	keras_MINST_V8.py		 old
README.md	   dog.jpg		      keras_CIFAR10_simple.py		     keras_MINST_V2.py	keras_MINST_V9.py		 preview
cat-standing.jpg   gulli.jpg		      keras_EvaluateCIFAR10.py		     keras_MINST_V3.py	keras_VGG16.py			 steam-locomotive.jpg
cat.jpg		   imageAugument.py	      keras_FaceDetection.py		     keras_MINST_V4.py	keras_VGG16_prebuilt.py		 tensorflow.simple.test.py
cat2.jpg	   imageAugumentMNIST.py      keras_InceptionNetTransferLearning.py  keras_MINST_V5.py	keras_VGG16_prebuilt_predict.py  theano.simple.test.py
(base) root@ed6304aaed64:/kerasBook# python imageAugument.py
/opt/conda/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
170500096/170498071 [==============================] - 61s 0us/step
Augmenting training set images...


imageAugumentMNIST.py

(base) root@ed6304aaed64:/kerasBook# python imageAugumentMNIST.py 
/opt/conda/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Augmenting training set images...
/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image.py:1437: UserWarning: NumpyArrayIterator is set to use the data format convention "channels_last" (channels on axis 3), i.e. expected either 1, 3, or 4 channels on axis 3. However, it was passed an array with shape (1, 1, 28, 28) (28 channels).
  str(self.x.shape[channels_axis]) + ' channels).')
Traceback (most recent call last):
  File "imageAugumentMNIST.py", line 34, in <module>
    save_to_dir='preview', save_prefix='mnist', save_format='jpeg'):
  File "/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image.py", line 1331, in __next__
    return self.next(*args, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image.py", line 1498, in next
    return self._get_batches_of_transformed_samples(index_array)
  File "/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image.py", line 1469, in _get_batches_of_transformed_samples
    img = array_to_img(batch_x[i], self.data_format, scale=True)
  File "/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image.py", line 399, in array_to_img
    raise ValueError('Unsupported channel number: ', x.shape[2])
ValueError: ('Unsupported channel number: ', 28)
(base) root@ed6304aaed64:/kerasBook# 

READ.ME

(base) root@ed6304aaed64:/kerasBook# cat READ.ME
1. keras_MLP_toy_classification.py is a toy example with two layers, train, test, validation, categorical_cross_entropy, accuracy
  - you can test different synthetic datasets
  - epoch
  - change size of the net
  - show the plotted net
  - show the dataset
  - change the batch size
  - different optimizers

2. keras_reuter_MLP is a real example similar to the above one 

3. keras_Iris is a real example similar to the above one

4. keras_MINST is a real example similar to the above one
   - change the size of the net 128, 512 , 2048

 5. keras_XOR learn the XOR function 

 6. keras_CreditDefaulDetection.py is a credit defaul detection net
   - increase Dropout
   - however this net is not decreasing the loss, tried:
      -- expand the layers
      -- normalization
      -- increase dropout

 7. CIFAR10 is a classification into 10 categories
    - training is separated from evaluation

 8. CIFAR100 -- TBD

keras_MLP_toy_classification.pyは、oldというフォルダの中に入っている。

現在、どうやって動かすか、悪戦苦闘中。

2. dockerを自力で構築する方へ

ここから下は、上記のpullしていただいたdockerをどういう方針で、どういう手順で作ったかを記録します。
上記のdockerを利用する上での参考資料です。本の続きを実行する上では必要ありません。
自力でdocker/anacondaを構築する場合の手順になります。
dockerfileを作る方法ではありません。ごめんなさい。

docker

ubuntu, debianなどのLinuxを、linux, windows, mac osから共通に利用できる仕組み。
利用するOSの設定を変更せずに利用できるのがよい。
同じ仕様で、大量の人が利用することができる。
ソフトウェアの開発元が公式に対応しているものと、利用者が便利に仕立てたものの両方が利用可能である。今回は、公式に配布しているものを、自分で仕立てて、他の人にも利用できるようにする。

#python

DeepLearningの実習をPhthonで行って来た。
pythonを使う理由は、多くの機械学習の仕組みがpythonで利用できることと、Rなどの統計解析の仕組みもpythonから容易に利用できることがある。

anaconda

pythonには、2と3という版の違いと、配布方法の違いなどがある。
Anacondaでpython3をこの1年半利用してきた。
Anacondaを利用した理由は、統計解析のライブラリと、JupyterNotebookが初めから入っているからである。

docker公式配布

ubuntu, debianなどのOSの公式配布,gcc, anacondaなどの言語の公式配布などがある。
これらを利用し、docker-hubに登録することにより、公式配布の質の確認と、変更権を含む幅広い情報の共有ができる。dockerが公式配布するものではなく、それぞれのソフト提供者の公式配布という意味。

docker pull

docker公式配布の利用は、URLからpullすることで実現する。

docker Anaconda

anacondaが公式配布しているものを利用。

$  docker pull kaizenjapan/anaconda-keras
Using default tag: latest
latest: Pulling from continuumio/anaconda3
Digest: sha256:e07b9ca98ac1eeb1179dbf0e0bbcebd87701f8654878d6d8ce164d71746964d1
Status: Image is up to date for continuumio/anaconda3:latest
OgawaKiyoshi-no-MacBook-Pro:docker-toppers ogawakiyoshi$ docker run -it continuumio/anaconda3 /bin/bash

実際にはkeras, tensorflow を利用していた他のpushをpull

apt

(base) root@d8857ae56e69:/# apt update; apt -y upgrade

(base) root@d8857ae56e69:/# apt install -y procps vim  apt-utils sudo

ソース git

(base) root@f19e2f06eabb:/# git clone  https://github.com/agulli/kerasBook

pip

(base) root@f19e2f06eabb:/deep-learning-from-scratch-2/ch01# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 2.0MB/s 
distributed 1.21.8 requires msgpack, which is not installed.
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0
(base) root@da73a1cf3e64:/Deep-Learning-Essentials/Chapter02/chapter-2/codeblock# pip install mxnet
Collecting mxnet
  Downloading https://files.pythonhosted.org/packages/71/64/49c5125befd5e0f0e17f115d55cb78080adacbead9d19f253afd0157656a/mxnet-1.3.0.post0-py2.py3-none-manylinux1_x86_64.whl (27.7MB)
    100% |████████████████████████████████| 27.8MB 1.8MB/s 
Collecting requests<2.19.0,>=2.18.4 (from mxnet)
  Downloading https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 5.0MB/s 
Collecting graphviz<0.9.0,>=0.8.1 (from mxnet)
  Downloading https://files.pythonhosted.org/packages/53/39/4ab213673844e0c004bed8a0781a0721a3f6bb23eb8854ee75c236428892/graphviz-0.8.4-py2.py3-none-any.whl
Collecting numpy<1.15.0,>=1.8.2 (from mxnet)
  Downloading https://files.pythonhosted.org/packages/18/84/49b7f268741119328aeee0802aafb9bc2e164b36fc312daf83af95dae646/numpy-1.14.6-cp37-cp37m-manylinux1_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 5.2MB/s 
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests<2.19.0,>=2.18.4->mxnet) (2018.8.24)
Collecting urllib3<1.23,>=1.21.1 (from requests<2.19.0,>=2.18.4->mxnet)
  Downloading https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 10.7MB/s 
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests<2.19.0,>=2.18.4->mxnet) (3.0.4)
Collecting idna<2.7,>=2.5 (from requests<2.19.0,>=2.18.4->mxnet)
  Using cached https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl
Installing collected packages: urllib3, idna, requests, graphviz, numpy, mxnet
  Found existing installation: urllib3 1.23
    Uninstalling urllib3-1.23:
      Successfully uninstalled urllib3-1.23
  Found existing installation: idna 2.7
    Uninstalling idna-2.7:
      Successfully uninstalled idna-2.7
  Found existing installation: requests 2.19.1
    Uninstalling requests-2.19.1:
      Successfully uninstalled requests-2.19.1
  Found existing installation: numpy 1.15.1
    Uninstalling numpy-1.15.1:
      Successfully uninstalled numpy-1.15.1
Successfully installed graphviz-0.8.4 idna-2.6 mxnet-1.3.0.post0 numpy-1.14.6 requests-2.18.4 urllib3-1.22

そして

$ docker docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                              NAMES
19b116a46da8        kaizenjapan/anaconda-keras   "/usr/bin/tini -- /b…"   About an hour ago   Up About an hour    6006/tcp, 0.0.0.0:8888->8888/tcp   competent_bohr


$ docker commit 19b116a46da8  kaizenjapan/anaconda-antonio

$ $ docker push kaizenjapan/anaconda-antonio
The push refers to repository [docker.io/kaizenjapan/anaconda-francois]
fd7357fb271d: Pushed 
95456260f6d1: Mounted from kaizenjapan/anaconda3-wei 
6410333f34cf: Mounted from kaizenjapan/anaconda3-wei 
cf342e34eca3: Mounted from kaizenjapan/anaconda3-wei 
cea95006e36a: Mounted from kaizenjapan/anaconda3-wei 
0f3a12fef684: Mounted from kaizenjapan/anaconda3-wei 
latest: digest: sha256:ff05b76bc3472a706cd10a810237f5f653ca04c43f347f37729b3572dc17f042 size: 1591

参考資料(reference)

dockerで機械学習(python:anaconda)「直感Deep Learning」Antonio Gulli、Sujit Pal 第1章,第2章
https://qiita.com/kaizen_nagoya/items/483ae708c71c88419c32

OpenCVをPythonで動かそうとしてlibGL.soが無いって言われたけど解決した。
https://qiita.com/toshitanian/items/5da24c0c0bd473d514c8

サーバサイドにおけるmatplotlibによる作図Tips
https://qiita.com/TomokIshii/items/3a26ee4453f535a69e9e

Dockerでホストとコンテナ間でのファイルコピー
https://qiita.com/gologo13/items/7e4e404af80377b48fd5

Docker for Mac でファイル共有を利用する
https://qiita.com/seijimomoto/items/1992d68de8baa7e29bb5

「名古屋のIoTは名古屋のOSで」Dockerをどっかーらどうやって使えばいいんでしょう。TOPPERS/FMP on RaspberryPi with Macintosh編 5つの関門
https://qiita.com/kaizen_nagoya/items/9c46c6da8ceb64d2d7af

64bitCPUへの道 and/or 64歳の決意
https://qiita.com/kaizen_nagoya/items/cfb5ffa24ded23ab3f60

ゼロから作るDeepLearning2自然言語処理編 読書会の進め方(例)
https://qiita.com/kaizen_nagoya/items/025eb3f701b36209302e

Ubuntu 16.04 LTS で NVIDIA Docker を使ってみる
https://blog.amedama.jp/entry/2017/04/03/235901

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

C++ Support(0) 
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding Rules(0) C Secure , MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

Autosar Guidelines C++14 example code compile list(1-169)
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76

Error一覧(C/C++, python, bash...) Error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2

言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4

プログラムちょい替え(0)一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

官公庁・学校・公的団体(NPOを含む)システムの課題、官(0)
https://qiita.com/kaizen_nagoya/items/04ee6eaf7ec13d3af4c3

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

LaTeX(0) 一覧 
https://qiita.com/kaizen_nagoya/items/e3f7dafacab58c499792

自動制御、制御工学一覧(0)
https://qiita.com/kaizen_nagoya/items/7767a4e19a6ae1479e6b

Rust(0) 一覧 
https://qiita.com/kaizen_nagoya/items/5e8bb080ba6ca0281927

小川清最終講義、最終講義(再)計画, Ethernet(100) 英語(100) 安全(100)
https://qiita.com/kaizen_nagoya/items/e2df642e3951e35e6a53

文書履歴(document history)

ver. 0.10 初稿 20181019 昼
ver. 0.11 READ.ME追記 20181019 夕
ver. 0.12 ありがとう追記 20230413

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0