Skip to main content

TensorFlow : Install Docker Image (CPU)

 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].  Install Podman, refer to here.

[2]. Install TensorFlow Docker (CPU only).

# 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   9 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])))"

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)


# 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

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]. 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   9 months ago   1.24 GB

docker.io/tensorflow/tensorflow   2.0.0-py3           90f5cb97b18f   9 months ago   1.09 GB


# run container as daemon

[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


# confirm URL

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

Currently running servers:

http://0.0.0.0:8888/?token=2b1641a43d5bca23758e6cc1d1979cf3fd4003ba52f8ee4b :: /tf

Comments

Popular posts from this blog

Unix / Linux - Special Variables

W e will discuss in detail about special variable in Unix. In one of our previous chapters, we understood how to be careful when we use certain nonalphanumeric characters in variable names. This is because those characters are used in the names of special Unix variables. These variables are reserved for specific functions. For example, the  $  character represents the process ID number, or PID, of the current shell − $echo $$ The above command writes the PID of the current shell − 29949 The following table shows a number of special variables that you can use in your shell scripts − Command-Line Arguments The command-line arguments $1, $2, $3, ...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command. Following script uses various special variables related to the command line − #!/bin/sh echo "File Name: $0" echo "First Parameter : $1" echo "Second Parameter :...

LINUX List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the appropriate command. The command name, in this case, is ls and it accepts various parameters. When using the command alone (without arguments): ls the output will be all visible files and folders without additional formatting or information. In order to view more information about the files (such as their permissions, ownership, last modified date, etc) and at the same time to list the files and directories, you would need to supply additional arguments to the command. The most common arguments are as follows: ls –a(Short from –all) Lists all files and folders including hidden (starting with a dot) files and directories. ls –R (Short from –Recursive) Lists recursively (i.e follows subfolders as well) all files and folders under the current directory. ls -l (Short from –long) Lists all files and folders, each on a separate line, and provides additional information about them (permission...

Initial Settings : Vim Settings

 There are many cases to use text editor on CUI terminal, so it's more convenient to install editors with advanced features like Vim. [1]. Install Vim in this example. [root@dlp ~]# dnf -y install vim-enhanced [2]. Set command alias for your own environment. But for users that has UID 201 or higher, Alias is already set by [/etc/profile.d/vim.sh] file that is included in [vim-enhanced] package. [root@dlp ~]# vi ~/.bashrc # add alias to the end alias vi='vim' # apply changes [root@dlp ~]# source ~/.bashrc [3]. Configure Vim for your own environment. (common settings for all users are in [/etc/vimrc]) [root@dlp ~]# vi ~/.vimrc " use extended function of vim (no compatible with vi) set nocompatible " specify encoding set encoding=utf-8 " specify file encoding set fileencodings=utf-8,iso-2022-jp,sjis,euc-jp " specify file formats set fileformats=unix,dos " take backup " if not, specify [ set nobackup ] set backup " specify backup directo...