LoginSignup
1
0

dockerで機械学習(19) with anaconda(19)「Deep Learning Quick Reference」 Mike Bernico著

Last updated at Posted at 2018-10-19

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

(19)「Deep Learning Quick Reference」 Mike Bernico著

cat-5.gif

docker

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

docker pull and run

$ docker pull kaizenjapan/anaconda-mike

$ docker run -it -p 8888:8888 kaizenjapan/anaconda-mike /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# 

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/mbernico/deep_learning_quick_reference

pip

(base) root@f19e2f06eabb:/# 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

##docker ps

$ 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 and push

$ docker commit 19b116a46da8  kaizenjapan/anaconda-mike

$ docker push kaizenjapan/anaconda-mike

参考資料(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

文書履歴(document history)

ver. 0.10 初稿 20181019 昼

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

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

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