TensorFlow : Docker イメージ (CPU) を利用する2022/09/08 |
機械学習ライブラリー TensorFlow をインストールします。
当例では、TensorFlow 公式の Docker イメージをダウンロードして、コンテナーから TensorFlow を利用します。
Docker イメージは GPU サポート無しの CPU オンリーのイメージを使用します。 |
|
[1] | |
[2] | TensorFlow Docker (CPU) の利用例です。 |
root@dlp:~#
root@dlp:~# docker pull tensorflow/tensorflow:latest
docker images REPOSITORY TAG IMAGE ID CREATED SIZE tensorflow/tensorflow latest 976c17ec6daa 34 hours ago 1.46GB # コンテナー実行 root@dlp:~# docker run --rm tensorflow/tensorflow:latest \ python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" 2022-09-08 05:46:54.777140: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-09-08 05:46:57.014887: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. tf.Tensor(-654.6173, shape=(), dtype=float32) import tensorflow as tf hello = tf.constant('Hello, TensorFlow World!') tf.print(hello) docker run --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow:latest python3 ./hello_tensorflow.py 2022-09-08 05:48:16.886674: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-09-08 05:48:18.236757: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. Hello, TensorFlow World! |
[3] | Jupyter Notebook を含むイメージの利用例です。 |
root@dlp:~#
root@dlp:~# docker pull tensorflow/tensorflow:latest-jupyter
docker images REPOSITORY TAG IMAGE ID CREATED SIZE tensorflow/tensorflow latest-jupyter c94342dbd1e8 34 hours ago 1.68GB tensorflow/tensorflow latest 976c17ec6daa 34 hours ago 1.46GB # コンテナーをデーモンとして実行 root@dlp:~# docker run -dt -p 8888:8888 tensorflow/tensorflow:latest-jupyter a2c4cd0c12f8d36b24e54edc257099cba7581c1ed6d14864595879e6e47f49b6root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a2c4cd0c12f8 tensorflow/tensorflow:latest-jupyter "bash -c 'source /et…" 8 seconds ago Up 7 seconds 0.0.0.0:8888->8888/tcp, :::8888->8888/tcp unruffled_fermat # URL 確認 root@dlp:~# docker exec a2c4cd0c12f8 bash -c "jupyter notebook list" Currently running servers: http://0.0.0.0:8888/?token=d3a7a2bd19e9bf986ff54b7280812d5de75c93d06e4898ce :: /tf |
表示された URL にアクセスすると Jupyter Notebook が利用できます。 |
Sponsored Link |