TensorFlow : Docker イメージ (CPU) を利用する2020/07/22 |
|
機械学習ライブラリー, TensorFlow をインストールします。
当例では、TensorFlow 公式の Docker イメージをダウンロードして、コンテナーから TensorFlow を利用します。
Docker イメージは GPU サポート無しの CPU オンリーのイメージを使用します。 |
|
| [1] | |
| [2] | TensorFlow Docker (CPU) の利用例です。 |
|
# TensorFlow 2.0 with Python3 イメージを Pull [cent@dlp ~]$ podman pull tensorflow/tensorflow:2.0.0-py3
podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/tensorflow/tensorflow 2.0.0-py3 90f5cb97b18f 9 months ago 1.09 GB # コンテナー実行 [cent@dlp ~]$ podman run --rm tensorflow/tensorflow:2.0.0-py3 \ python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" 2020-07-22 05:21:27.138093: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801480000 Hz 2020-07-22 05:21:27.138647: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x34ccfe0 executing computations on platform Host. Devices: 2020-07-22 05:21:27.138671: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version tf.Tensor(1074.4442, shape=(), dtype=float32)
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow World!')
tf.print(hello)
podman run --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow:2.0.0-py3 python ./hello_tensorflow.py 2020-07-22 05:23:36.928319: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801480000 Hz 2020-07-22 05:23:36.928717: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4add050 executing computations on platform Host. Devices: 2020-07-22 05:23:36.928738: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version Hello, TensorFlow World! |
| [3] | SELinux を有効にしている場合は、ポリシーの変更が必要です。 |
|
[root@dlp ~]#
vi my-python.te # 以下の内容で新規作成
module my-python 1.0;
require {
type user_home_t;
type container_t;
type user_home_dir_t;
class file { create ioctl open read unlink write };
class dir { add_name remove_name write };
}
#============= container_t ==============
allow container_t user_home_dir_t:dir { add_name remove_name write };
allow container_t user_home_dir_t:file { create ioctl open read unlink write };
allow container_t user_home_t:file { ioctl open read };
checkmodule -m -M -o my-python.mod my-python.te [root@dlp ~]# semodule_package --outfile my-python.pp --module my-python.mod [root@dlp ~]# semodule -i my-python.pp |
| [4] | Jupyter Notebook を含むイメージの利用例です。 |
|
# TensorFlow 2.0 with Python3/Jupyter イメージを Pull [cent@dlp ~]$ podman pull tensorflow/tensorflow:2.0.0-py3-jupyter
podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/tensorflow/tensorflow 2.0.0-py3-jupyter c652a4fc8a4f 9 months ago 1.24 GB docker.io/tensorflow/tensorflow 2.0.0-py3 90f5cb97b18f 9 months ago 1.09 GB # コンテナーをデーモンとして実行 [cent@dlp ~]$ podman run -dt -p 8888:8888 tensorflow/tensorflow:2.0.0-py3-jupyter 1d54bcba3f14eef778a45332b825b6dedd9efb7c8926fde76a5c81cbaed09947[cent@dlp ~]$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1d54bcba3f14 docker.io/tensorflow/tensorflow:2.0.0-py3-jupyter bash -c source /e... 6 seconds ago Up 6 seconds ago 0.0.0.0:8888->8888/tcp vigorous_blackburn # URL 確認 [cent@dlp ~]$ podman exec 1d54bcba3f14 bash -c "jupyter notebook list" Currently running servers: http://0.0.0.0:8888/?token=2b1641a43d5bca23758e6cc1d1979cf3fd4003ba52f8ee4b :: /tf |
| 表示された URL にアクセスすると Jupyter Notebook が利用できます。 |
|
| Sponsored Link |
|
|