CentOS Stream 8
Sponsored Link

TensorFlow : Install Docker Image (CPU)2021/04/14

 
Install TensorFlow which is the Machine Learning Library.
On this example, Install TensorFlow official Docker Image without GPU support and run it on Containers.
[1]
[2] Install TensorFlow Docker (CPU only).
# show available images

[cent@dlp ~]$
curl -s https://registry.hub.docker.com/v1/repositories/tensorflow/tensorflow/tags| sed "s/,/\n/g" | grep name

 "name": "latest"}
 "name": "0.10.0"}
 "name": "0.10.0-devel"}
 "name": "0.10.0-devel-gpu"}
 "name": "0.10.0-gpu"}
.....
.....

# pull TensorFlow 2.0 with Python3 image

[cent@dlp ~]$
podman pull tensorflow/tensorflow:2.0.0-py3
[cent@dlp ~]$
podman images

REPOSITORY                       TAG        IMAGE ID      CREATED        SIZE
docker.io/tensorflow/tensorflow  2.0.0-py3  90f5cb97b18f  18 months ago  1.09 GB

# run container

[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])))"

2021-04-13 01:55:05.174282: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801385000 Hz
2021-04-13 01:55:05.174845: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4355000 executing computations on platform Host. Devices:
2021-04-13 01:55:05.174876: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
tf.Tensor(-2229.3335, shape=(), dtype=float32)

# create Hello World test script and run it on container

[cent@dlp ~]$
vi hello_tensorflow.py
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow World!')
tf.print(hello)

[cent@dlp ~]$
podman run --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow:2.0.0-py3 python ./hello_tensorflow.py

2021-04-13 01:56:31.402392: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801385000 Hz
2021-04-13 01:56:31.402898: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4bc0b60 executing computations on platform Host. Devices:
2021-04-13 01:56:31.402920: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
Hello, TensorFlow World!
[3] If SELinux is enabled, change pilicy.
[root@dlp ~]#
vi my-python.te
# create new

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 };

[root@dlp ~]#
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] Install TensorFlow Docker Image with Jupyter Notebook.
# pull TensorFlow 2.0 with Python3/Jupyter image

[cent@dlp ~]$
podman pull tensorflow/tensorflow:2.0.0-py3-jupyter
[cent@dlp ~]$
podman images

REPOSITORY                       TAG                IMAGE ID      CREATED        SIZE
docker.io/tensorflow/tensorflow  2.0.0-py3-jupyter  c652a4fc8a4f  18 months ago  1.24 GB
docker.io/tensorflow/tensorflow  2.0.0-py3          90f5cb97b18f  18 months ago  1.09 GB

# run container as daemon

[cent@dlp ~]$
podman run -dt -p 8888:8888 tensorflow/tensorflow:2.0.0-py3-jupyter

b65573db78f1cda05885422418103271bc0eda57a85e119cb44e2d443dd0ef53

[cent@dlp ~]$
podman ps

CONTAINER ID  IMAGE                                              COMMAND               CREATED        STATUS            PORTS                   NAMES
b65573db78f1  docker.io/tensorflow/tensorflow:2.0.0-py3-jupyter  bash -c source /e...  6 seconds ago  Up 7 seconds ago  0.0.0.0:8888->8888/tcp  gallant_fermat

# confirm URL

[cent@dlp ~]$
podman exec b65573db78f1 bash -c "jupyter notebook list"

Currently running servers:
http://0.0.0.0:8888/?token=6396247ca174e621ec0aab5fb230953d4bfaf0c4a219f6f6 :: /tf
  Accessto the URL above, then it's possible to use Jupyter Notebook.
Matched Content